web2py

Cleaning up web2py my controllers

爷,独闯天下 提交于 2019-12-05 05:54:26
My controllers are getting a bit cluttered in my web2py app, and I would like to move functions to another place. I was initially thinking of moving them to modules, but I access the db sometimes, and have other parameters set in db.py (me for user id, now for the date, etc.). Is there a clean way to move these functions to a new file while still having access to the variables I need? I'm not opposed to something like from db import me, now You controller actions (i.e., the actions that appear in URLs) have to be functions defined in a controller file (i.e., you cannot move them to a module).

Asynchronous background processes with web2py

半城伤御伤魂 提交于 2019-12-05 04:29:30
I need to to handle a large (time and memory-consuming) process asynchronously in a web2py application called inside a controller method. My specific use case is to call a process via stdlib.subprocess and wait for it to exit without blocking the web server, but I am open to alternative methods. Hands-on examples would be a plus. 3rd party library recommendations are welcome. CRON scheduling is not required/wanted. Assuming you'll need to start multiple, possibly simultaneous, instances of the background task, the solution is a task queue. I've heard good things about Celery and RabbitMQ, if

Multi-Column Unique Constraint with web2py

房东的猫 提交于 2019-12-05 02:21:11
It is possible to mark a particular column as unique=true. What is the most correct way to handle multi-column unique constraints in web2py? For example, say I have an exchange rate table. It could have columns from-currency, to-currency and the exchange rate. It would not make sense to have two rows with the same from and to currencies. What would be the most elegant or correct way to make the from/to combination unique? Assuming the data will be entered via a form, you could use a form validator, like this: db.define_table('rates', Field('from_currency'), Field('to_currency')) db.rates.to

Web2Py - Upload a file and read the content as Zip file

妖精的绣舞 提交于 2019-12-04 21:54:08
I am trying to upload a zip file from Web2Py form and then read the contents: form = FORM(TABLE( TR(TD('Upload File:', INPUT(_type='file', _name='myfile', id='myfile', requires=IS_NOT_EMPTY()))), TR(TD(INPUT(_type='submit',_value='Submit'))) )) if form.accepts(request.vars): data=StringIO.StringIO(request.vars.myfile) import zipfile zfile=zipfile.Zipfile(data) For some reason this code does work and complains of file not being a zip file although the uploaded file is a zip file. I am new to Web2Py . How can the data be represented as zip-file? web2py form field uploads already are cgi

How to change '_class' of Web2py autocomplete widget

血红的双手。 提交于 2019-12-04 21:53:47
I loop through a form object to change all the classes: form = crud.create(db.messages, next = URL('index')) parts = ['title', 'body', 'subject'] # corresponding fields classes = 'form-control col-md-12' # my classes for p in parts: form.custom.widget[p]['_class'] = '%s %s' % (classes, form.custom.widget[p]['_type']) This is working - but: subject is an autocomplete widget: db.messages.subject.widget = SQLFORM.widgets.autocomplete(...) and here _class is not changed (or altered afterwards again?) How can this be fixed? Thanks! The autocomplete widget is a TAG object that contains two

Web2py: Pass a variable from view to controller

别等时光非礼了梦想. 提交于 2019-12-04 19:02:08
How can I pass a JavaScript variable from the view to Python in controller? I don't want to use request.vars or request.args , because that would allow to user to give arbitrary parameters for the action by typing it into the address bar. Example view: <button onclick='myFunction();'>Execute</button> <script> function myFunction();{ var value = calculateValue(); //pass value to my_action window.location = 'my_action'; } </script> Example controller: def index(): return dict() def my_action(): #retrieve passed variable #handle the variable #... redirect(URL('index')) You could make an Ajax call

defining sub-domain based on a function in routes.py of Web2Py

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 17:46:25
I have this page: http://mysite.org/myapp/pages/blog?name=user9 and I need to have this: user9.mysite.org What should i write in my routes.py? Ok, so i think misinterpreted this a little. You need user9.mysite.org to be served from the web2py app. One way, if you have your site hosted at mysite.org, is to pass all requests (regardless of subdomain) to the web2py application (you'll need an A record like *.mysite.org with your DNS provider: http://kb.mediatemple.net/questions/791/DNS+Explained#/A_Record ) Then, you can use routes Something like: routes_in = ( ('http://(?P<user>.*).mysite.org/(

web2py - how to inject html

萝らか妹 提交于 2019-12-04 14:59:43
i used rows.xml() to generate html output. i want to know how to add html codes to this generated html page e.g: "add logo, link css file,.. etc" rows=db(db.member.membership_id==request.args[0]).select(db.member.membership_id ,db.member.first_name,db.member.middle_name ,db.member.last_name) return rows.xml() There are many HTML helpers you can use, for example: html_code = A('<click>', rows.xml(), _href='http://mylink') html_code = B('Results:', rows.xml(), _class='results', _id=1) html_page = HTML(BODY(B('Results:', rows.xml(), _class='results', _id=1))) and so on. You can even create a

Anyone out there using web2py? [closed]

你。 提交于 2019-12-04 07:23:59
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . Is anyone out there* using web2py? Specifically: In production? With what database? With Google Application Engine? by "out there" I mean at stackoverflow. 回答1: You are welcome to ask the same question on the google group. You will find more than 500 users there and some of

how to pass value from view to controller in web2py

谁说胖子不能爱 提交于 2019-12-04 06:37:05
问题 I want to insert the value of lang to mysql table. How to pass the value of lang to controller view <script type="text/javascript"> function test(it) { var lang=it.value; } </script> <form> <p>language <select id="select" onchange="test(this)"> <option value ="0">c</option> <option value ="1">cc</option> <option value="2">pas</option> <option value="3">java</option> <option value ="4">rb</option> </select> </p> </form> conteoller def problem(lang): { } Thanks! 回答1: web2py doesn't work quite