[web2py] Re: SQLFORM deletable=True -- buggy behavior
Are you using the entire web2py_ajax.js file from the cookbook? If so, much of it is out of date and should not be used. Note, in the current web2py, the name of the file has actually been changed to web2py.js, and a number of changes were made, including resolving that redundant event handler bug. You should use the current web2py.js, and try to copy the special Ajax file upload code only from the cookbook (I think it is limited to the web2py_trap_form() function). Anthony On Thursday, March 22, 2012 1:52:00 AM UTC-4, Anthony wrote: It's the code straight out of the new web2py cookbook. I'm not sure ... will I be violating copyright if I post it here? Hmm... The code in this book is released under the BSD license, unless otherwise specified, and is available online on a dedicated GitHub repository listed below.
Re: [web2py] Re: DAL or SQL?
On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said: for every period, duration is calculated as: duration = db.periods.end_time.seconds() - db.periods.start_time.seconds() now, get a list of all durations... result = db(db.periods.id0).select(db.periods.id, duration) This does not work: every 'duration' is None: duration = db.t_periods.f_period_end.seconds() - db.t_periods.f_period_start.seconds() result = db(db.t_periods.id0).select(db.t_periods.id, duration) result[0] Row {'t_periods': Row {'update_record': function lambda at 0x923479c, 't_periods_archive': gluon.dal.Set object at 0x923924c, 0x923479c'id': 40, 'delete_record': function lambda at 0x9234764}, 0x923479c'_extra': Row 0x923479c{(web2py_extract('second',t_periods.f_period_end) - 0x923479cweb2py_extract('second',t_periods.f_period_start)): None}} All rows give the same result (None). I can see that what I need to be doing is calculating the end time in seconds and subtracting the start time in seconds, but I can't see how to do that via the DAL. Back to my original question: is the only way to do this to use hand-crafted SQL? -- You can have everything in life you want if you help enough other people get what they want - Zig Ziglar. Who did you help today?
[web2py] trouble with auth.settings.login_next
I'm setting auth.settings.login_next but it's not taking. In gluon/ tools.py there's a snippet of code beginning at line 1642: ### use session for federated login if self.next: session._auth_next = self.next elif session._auth_next: self.next = session._auth_next ### pass if next is DEFAULT: next = self.next or self.settings.login_next What's happening is that session._auth_next is already set by the time execution reaches that point, so self.next is getting set to some non- null value, which is then getting used. How to prevent session._auth_next getting set? Obviously, I can set it in a model, but if I do that, then what purpose does auth.settings.login_next serve?
[web2py] Re: creating relationship between two tables
I've seen both, and I think that the second doesn't make a foreign key constraint, it just creates an int field... not sure though. I come from a SQL background, so I could write the queries myself and have stored procedures, but I'm trying it the web2py way, as I think eventually, this may be put on a linux system. That whole DRY principle is important. Anyway, I only mention it because I think that having a foreign key constraint is good practice, since you can tell from the structure of the database how the tables are related. On Wednesday, March 21, 2012 11:22:45 AM UTC-7, pbreit wrote: I think it needs to be 'reference db.customers' Are these equivalent? Is there a preferred usage? db.define_table('dog', Field('owner', 'reference db.owner')) db.define_table('dog', Field('owner', db.owner))
Re: [web2py] Re: DAL or SQL?
Perhaps you could add the seconds as a virtual lazy field. On Wednesday, March 21, 2012 11:25:41 PM UTC-7, backseat wrote: On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said: for every period, duration is calculated as: duration = db.periods.end_time.seconds() - db.periods.start_time.seconds() now, get a list of all durations... result = db(db.periods.id0).select(db.periods.id, duration) This does not work: every 'duration' is None: duration = db.t_periods.f_period_end.seconds() - db.t_periods.f_period_start.seconds() result = db(db.t_periods.id0).select(db.t_periods.id, duration) result[0] Row {'t_periods': Row {'update_record': function lambda at 0x923479c, 't_periods_archive': gluon.dal.Set object at 0x923924c, 0x923479c'id': 40, 'delete_record': function lambda at 0x9234764}, 0x923479c'_extra': Row 0x923479c{(web2py_extract('second',t_periods.f_period_end) - 0x923479cweb2py_extract('second',t_periods.f_period_start)): None}} All rows give the same result (None). I can see that what I need to be doing is calculating the end time in seconds and subtracting the start time in seconds, but I can't see how to do that via the DAL. Back to my original question: is the only way to do this to use hand-crafted SQL? -- You can have everything in life you want if you help enough other people get what they want - Zig Ziglar. Who did you help today?
[web2py] Re: open web2py it self when deployed
yes, deployed it's not a good idea, but for a development server, it can work. On Tuesday, March 20, 2012 9:02:07 PM UTC-7, Anthony wrote: On Tuesday, March 20, 2012 7:23:15 PM UTC-4, Derek wrote: Comment out these two lines... #elif (remote_addr not in hosts) and (remote_addr != 127.0.0.1): #raise HTTP(200, T('appadmin is disabled because insecure channel')) That will work, but not a good move from a security perspective.
[web2py] Re: SQLFORM deletable=True -- buggy behavior
No, I'm only using the web2py_trap_form out of the cookbook. The rest of the web2py_ajax.js file is the same. I'll check out the latest web2py.js later today. On Mar 22, 2:12 pm, Anthony abasta...@gmail.com wrote: Are you using the entire web2py_ajax.js file from the cookbook? If so, much of it is out of date and should not be used. Note, in the current web2py, the name of the file has actually been changed to web2py.js, and a number of changes were made, including resolving that redundant event handler bug. You should use the current web2py.js, and try to copy the special Ajax file upload code only from the cookbook (I think it is limited to the web2py_trap_form() function). Anthony On Thursday, March 22, 2012 1:52:00 AM UTC-4, Anthony wrote: It's the code straight out of the new web2py cookbook. I'm not sure ... will I be violating copyright if I post it here? Hmm... The code in this book is released under the BSD license, unless otherwise specified, and is available online on a dedicated GitHub repository listed below.
Re: [web2py] Re: DAL or SQL?
We shall come to an agreement when you explain plainly what is your real model... it seems that your start and end columns are time and not datetime... Time fields don't have a seconds() method, only datetime!
[web2py] auth.login() from inside a component in a dialog
I'm trying to do the modal login thing. I'm LOADing the auth login form into a div, which is id'd as a dialog for jquery ui. Should be a snap, right? Wrong. It's not working at all. First, I ran into the problem I describe in another thread, which is that I'm forced to do this: session._auth_next = auth.settings.login_next = URL(c='user', f='login') because otherwise, session._auth_next will drive me to the default index. The other problem I have is that I can't figure out how to get the flow of the form submission to recognize response.js and execute the ajax call after login is completed. I've tried putting response.js into a function in my 0_db.py file, like this: def myonaccept(form): response.js = ... auth.settings.login_onaccept = [myonaccept] but that doesn't seem to do anything. I've also tried changing the login function to something like this: def login(): auth.settings.captcha = None login_form = auth.login() if login_form.accepts(request): response.flash = 'yo dude' response.js = util.clean_str( 'ajax(%s,[],:eval);' % URL(c='user', f='cb_after_login')) return dict(login_form=login_form) But that also doesn't work. I get tied up with a nasty ticket: ... if login_form.accepts(request): File N:\web2py\gluon\sqlhtml.py, line 1267, in accepts self.vars.id = self.table.insert(**fields) File N:\web2py\gluon\dal.py, line 5597, in insert return self._db._adapter.insert(self,self._listify(fields)) File N:\web2py\gluon\dal.py, line 914, in insert raise e IntegrityError: duplicate key value violates unique constraint auth_user_email_key Any help or working examples would be appreciated. On, and I have multiple forms going on the page, so that might be an issue, too.
[web2py] Re: [video] websockets com web2py e tornado
Sorry, this is in Portuguese and should go only to Brazilian groups... On Thu, Mar 22, 2012 at 5:10 AM, Bruno Rocha rochacbr...@gmail.com wrote: *Curso De Python .com.br * websockets com tornado, web2py, Python, jQueryhttp://vimeo.com/38972256, [image: websockets com tornado, web2py, Python, jQuery]http://vimeo.com/38972256 *websockets com tornado, web2py, Python, jQuery* http://vimeo.com/38972256 Envio de mensagens Server--Client utilziando websockets (comet) com tornado e web2py. http://www.cursodepython.com.br; *Mais videos como este disponíveis em:* http://www.cursodepython.com.br/videos [image: Inline image 1] http://www.cursodepython.com.br/videos -- Bruno Rocha [http://rochacbruno.com.br] -- Bruno Rocha [http://rochacbruno.com.br]
Re: [web2py] Re: DAL or SQL?
Perhaps you could add the seconds as a virtual lazy field. That sounds worth investigating, thanks. We shall come to an agreement when you explain plainly what is your real model... it seems that your start and end columns are time and not datetime... Time fields don't have a seconds() method, only datetime! In my original posting, I said: the periods table has id, date, start_time, end_time (and other fields). I suppose I assumed that the presence of a 'date' field implied that the *_time fields were indeed of type time, but I'm sorry if that wasn't clear. For clarity: db.define_table('t_periods', Field('f_date', type='date', label=T('Date')), Field('f_period_start', type='time', label=T('Period Start')), Field('f_period_end', type='time', label=T('Period End')), ... -- You can have everything in life you want if you help enough other people get what they want - Zig Ziglar. Who did you help today?
Re: [web2py] Re: DAL or SQL?
In my original posting, I said: the periods table has id, date, start_time, end_time (and other fields). I suppose I assumed that the presence of a 'date' field implied that the *_time fields were indeed of type time, but I'm sorry if that wasn't clear. my point was: my model implied datetime, your's not, don't blame web2py if my method don't work applied to your model. so, there is an hiccup to your model: time fields don't represent a point in time, it has no sense trying to subtract them e.g. a record that has start time 09:00:00 and an end time of 10:00:00 means that it has passed one hour, one hour and one day or one hour and two days(and so on)? Anyway, if you do durations = db.periods.end_time - db.periods.start_time it works. but sqlite actually returns the difference in hours, and seems to round that as an integer.
[web2py] Re: Package max file size
They are tar gzipped files. I do not know if there is a limit. If there is a very large. On Wednesday, 21 March 2012 09:20:12 UTC-5, Marco Tulio wrote: Hi, Packages are a really cool feature. They allow you to backup your application (including all the tables, views, controllers, and also static files, uploads etc). I made an application that has some static maps (png images), and also made a few pdf files available for download. What happens is that my application itself is really small. But the static files (pdf) and the images that I made available (when I created an upload field) make the size of the package created really large (about 80Mb). And now when I try to backup my app, web2py fails on creating the package. Although it doesn't say it, I do believe it's about the size of the package itself. So, first question is : is there a limit for the size of the package? If so, how we deal with applications that'll need to use lots of images? Thanks in advanced. -- []'s Marco Tulio
[web2py] Re: Online book is down (producing internal error)
Seems to work now.
[web2py] Re: Environment variable LD_LIBRARY_PATH
try: import os os.environ['LD_LIBRARY_PATH'] = '' On Wednesday, 21 March 2012 14:10:57 UTC-5, surfnet3 wrote: How can I set the environment variable LD_LIBRARY_PATH for web2py?
[web2py] Re: The python brochure
I know about it but I did not see it. I believe it is framework agnostic. Yet we should look at it. We should make our own brochures perhaps. On Thursday, 22 March 2012 04:24:23 UTC-5, mcm wrote: Hello Massimo, http://brochure.getpython.info/ do you know anything about it? should web2py care about it?
Re: [web2py] Re: [video] websockets com web2py e tornado
I disaggree. I´m portuguese and Bruno is perfect explaining websockets in web2py! Add english subtitles!!! 2012/3/22 Bruno Rocha rochacbr...@gmail.com Sorry, this is in Portuguese and should go only to Brazilian groups... On Thu, Mar 22, 2012 at 5:10 AM, Bruno Rocha rochacbr...@gmail.comwrote: *Curso De Python .com.br * websockets com tornado, web2py, Python, jQueryhttp://vimeo.com/38972256, [image: websockets com tornado, web2py, Python, jQuery]http://vimeo.com/38972256 *websockets com tornado, web2py, Python, jQuery* http://vimeo.com/38972256 Envio de mensagens Server--Client utilziando websockets (comet) com tornado e web2py. http://www.cursodepython.com.br; *Mais videos como este disponíveis em:* http://www.cursodepython.com.br/videos [image: Inline image 1] http://www.cursodepython.com.br/videos -- Bruno Rocha [http://rochacbruno.com.br] -- Bruno Rocha [http://rochacbruno.com.br]
[web2py] using janrain and normal registration
Dear ALL , i want to use janrain and normal registration at the same time so i did this : from gluon.contrib.login_methods.rpx_account import RPXAccount url = http://localhost:8000/%s/default/user/login; % request.application from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm other_form = RPXAccount(request, api_key='xx', domain='xx', url=url) auth.settings.login_form = ExtendedLoginForm(request,auth, other_form) but when i open user/login i keep getting this error :: TRACEBACK Traceback (most recent call last): File C:\web2py\gluon\restricted.py, line 204, in restricted exec ccode in environment File C:/web2py/applications/i3zif/controllers/default.py, line 218, in module File C:\web2py\gluon\globals.py, line 172, in lambda self._caller = lambda f: f() File C:/web2py/applications/i3zif/controllers/default.py, line 153, in user return dict(form=auth()) File C:\web2py\gluon\tools.py, line 1141, in __call__ return getattr(self,args[0])() File C:\web2py\gluon\tools.py, line 1766, in login return cas.login_form() File C:\web2py\gluon\contrib\login_methods\extended_login_form.py, line 89, in login_form request = self.auth.environment.request AttributeError: 'NoneType' object has no attribute 'request' ERROR SNAPSHOT type 'exceptions.AttributeError'('NoneType' object has no attribute 'request') how can i fix this ??
[web2py] Re: Online book is down (producing internal error)
Yes, the problem was brief.
Re: [web2py] Re: [video] websockets com web2py e tornado
+1 On Thursday, 22 March 2012 05:23:17 UTC-5, Ramos wrote: I disaggree. I´m portuguese and Bruno is perfect explaining websockets in web2py! Add english subtitles!!! Sorry, this is in Portuguese and should go only to Brazilian groups... On Thu, Mar 22, 2012 at 5:10 AM, Bruno Rocha rochacbr...@gmail.comwrote: *Curso De Python .com.br * websockets com tornado, web2py, Python, jQueryhttp://vimeo.com/38972256, [image: websockets com tornado, web2py, Python, jQuery]http://vimeo.com/38972256 *websockets com tornado, web2py, Python, jQuery* http://vimeo.com/38972256 Envio de mensagens Server--Client utilziando websockets (comet) com tornado e web2py. http://www.cursodepython.com.br; *Mais videos como este disponíveis em:* http://www.cursodepython.com.br/videos [image: Inline image 1] http://www.cursodepython.com.br/videos -- Bruno Rocha [http://rochacbruno.com.br] -- Bruno Rocha [http://rochacbruno.com.br]
[web2py] Re: using janrain and normal registration
auth.settings.login_form = ExtendedLoginForm(request,auth, other_form) Looks like the book is not up-to-date -- if you're using the current web2py, I think the above should be: auth.settings.login_form = ExtendedLoginForm(auth, other_form) Anthony
[web2py] Re: auth.login() from inside a component in a dialog
First, I ran into the problem I describe in another thread, which is that I'm forced to do this: session._auth_next = auth.settings.login_next = URL(c='user', f='login') because otherwise, session._auth_next will drive me to the default index. I believe auth.settings.login_next only has an effect when there is no session._auth_next (i.e., when the user goes directly to the login URL rather than getting there via an internal link or redirect). The idea is that when the user gets to the login via a redirect (i.e., trying to access a URL that requires login) or an internal link, they should be redirected back to their original page right after login. auth.settings.login_next is only intended as a default post-login redirect for other cases (I guess primarily if the user simply goes directly to the login URL itself). The other problem I have is that I can't figure out how to get the flow of the form submission to recognize response.js and execute the ajax call after login is completed. I've tried putting response.js into a function in my 0_db.py file, like this: def myonaccept(form): response.js = ... auth.settings.login_onaccept = [myonaccept] The problem is that the auth.login() action does a redirect after running the onaccept callback, so I think your response.js is getting lost. You can probably solve both this problem and the session._auth_next redirect problem by having your onaccept callback itself do a redirect (to an action that then sets response.js) or even raise its own HTTP() response directly. def login(): auth.settings.captcha = None login_form = auth.login() if login_form.accepts(request): response.flash = 'yo dude' response.js = util.clean_str( 'ajax(%s,[],:eval);' % URL(c='user', f='cb_after_login')) That won't work because auth.login() does its own form.accepts(), and in the case of a successful login, it does a redirect, which will prevent the rest of your code from executing. Anthony
[web2py] Re: creating relationship between two tables
I think it needs to be 'reference db.customers' 'reference customers' is the correct syntax (it assumes the customers table is in the same db, so no need to include db.). Anthony
[web2py] zip xls file and return it in response
Hello, Am generating xls file using the following code: response.headers['Content-Type'] = gluon.contenttype.contenttype('.xls') response.headers['Content-disposition'] = 'attachment; filename=file.xls' today = str(datetime.today()) wbk.save(temp1+today+.xls) f = open(temp1+today+.xls, 'r') out= f.read() f.close() return out How can zip file.xls and return it ?? could you please any Advices ??
[web2py] Re: using janrain and normal registration
It works but now when anyone registers with janrain his data is messing so i used this code but its not redirecting : auth.settings.extra_fields['auth_user']= [ Field('Country'), Field('City'), Field('gender',requires=IS_IN_SET(genders,zero=None)), Field('complete_registration',default=False,update=True,writable=False, readable=False)] if auth.user and not auth.user.complete_registration: if not (request.controller,request.function) == ('default','user'): redirect(URL('default','user/profile'))
[web2py] Re: creating relationship between two tables
I've seen both, and I think that the second doesn't make a foreign key constraint, it just creates an int field... not sure though. Field('customer', 'reference customers') and Field('customer', db.customers) are equivalent (behind the scenes, when you do type=db.customers, it is converted to type='reference customers'), and both create a foreign key constraint. Note, your error is not about the constraint but seems to indicate that customers is an invalid table. I'm not sure why, though -- the model definition looks OK. Have you tried it on SQLite? Anthony
Re: [web2py] Re: Package max file size
Could it be a limitation on the max file size on apache then? I saw something similar on Nginx (had to manually add on the config file a configuration with the maximum file size). Thanks for the atention, Marco Tulio 2012/3/22 Massimo Di Pierro massimo.dipie...@gmail.com They are tar gzipped files. I do not know if there is a limit. If there is a very large. On Wednesday, 21 March 2012 09:20:12 UTC-5, Marco Tulio wrote: Hi, Packages are a really cool feature. They allow you to backup your application (including all the tables, views, controllers, and also static files, uploads etc). I made an application that has some static maps (png images), and also made a few pdf files available for download. What happens is that my application itself is really small. But the static files (pdf) and the images that I made available (when I created an upload field) make the size of the package created really large (about 80Mb). And now when I try to backup my app, web2py fails on creating the package. Although it doesn't say it, I do believe it's about the size of the package itself. So, first question is : is there a limit for the size of the package? If so, how we deal with applications that'll need to use lots of images? Thanks in advanced. -- []'s Marco Tulio -- []'s Marco Tulio
[web2py] Re: auth.login() from inside a component in a dialog
Hi Anthony, again, many thanks for your valuable contributions to this group. I believe auth.settings.login_next only has an effect when there is no session._auth_next (i.e., when the user goes directly to the login URL rather than getting there via an internal link or redirect). Your logic is sound, but I'm afraid this is not the case. I am directly going to myapp/login and then getting redirected via session._auth_next to default/index. The other problem I have is that I can't figure out how to get the flow of the form submission to recognize response.js and execute the ajax call after login is completed. I've tried putting response.js into a function in my 0_db.py file, like this: def myonaccept(form): response.js = ... auth.settings.login_onaccept = [myonaccept] The problem is that the auth.login() action does a redirect after running the onaccept callback, so I think your response.js is getting lost. You can probably solve both this problem and the session._auth_next redirect problem by having your onaccept callback itself do a redirect (to an action that then sets response.js) or even raise its own HTTP() response directly. def login(): auth.settings.captcha = None login_form = auth.login() if login_form.accepts(request): response.flash = 'yo dude' response.js = util.clean_str( 'ajax(%s,[],:eval);' % URL(c='user', f='cb_after_login')) That won't work because auth.login() does its own form.accepts(), and in the case of a successful login, it does a redirect, which will prevent the rest of your code from executing. Anthony I thought this is what the auth.settings.login_onaccept = [myonaccept] was supposed to do (see my example stated earlier). That was my first attempt as it seemed the most logical. Am I doing something wrong there? The second attempt, which is the if login_form.accepts(...) was an act of desperation :-o
[web2py] Re: using janrain and normal registration
if auth.user and not auth.user.complete_registration: if not (request.controller,request.function) == ('default','user'): redirect(URL('default','user/profile')) Are you getting an error, or is it just not redirecting at all? In either case, change the URL call to URL('default', 'user', args='profile'). Anthony
[web2py] Re: using janrain and normal registration
its not redirecting at all and i changed the URL to URL('default', 'user', args='profile') but still nothing is happening ,, what to do ??!
[web2py] Re: auth.login() from inside a component in a dialog
I believe auth.settings.login_next only has an effect when there is no session._auth_next (i.e., when the user goes directly to the login URL rather than getting there via an internal link or redirect). Your logic is sound, but I'm afraid this is not the case. I am directly going to myapp/login and then getting redirected via session._auth_next to default/index. Puzzling. Could be a bug. I thought this is what the auth.settings.login_onaccept = [myonaccept] was supposed to do (see my example stated earlier). That was my first attempt as it seemed the most logical. Am I doing something wrong there? auth.settings.login_onaccept gets called after a successful login, but it's not the very last thing that happens in auth.login() -- after the callback, auth.login() still proceeds to do its usual redirect. The redirect starts a whole new request, so if you set response.js before the redirect, it will get lost. Here's why -- when you set response.js, it adds the JS code to a special web2py-component-command header. However, because of the redirect, that header will arrive at the browser as part of a 303 redirect response. When the browser receives a redirect response, it immediately issues the redirect request without further processing the XHR object, so the client-side web2py JS code never gets to process the web2py-component-command header. Instead, you have to set response.js *after* the redirect, or simply prevent the redirect altogether (hence my suggestion to have your callback raise an HTTP() response). Anthony
[web2py] Re: auth.login() from inside a component in a dialog
When the browser receives a redirect response, it immediately issues the redirect request without further processing the XHR object, so the client-side web2py JS code never gets to process the web2py-component-command header. Note, this is not a web2py issue -- this is how XHR works.
[web2py] Re: SQLFORM deletable=True -- buggy behavior
No, I'm only using the web2py_trap_form out of the cookbook. The rest of the web2py_ajax.js file is the same. If the name of the file is web2py_ajax.js, it's probably old -- it was changed to web2py.js quite a while ago. Anthony
[web2py] Systems Management Web App for Ubuntu
Hi Everyone! I would like to ask some guidance regarding anyone who may be interested in developing web-based python app for systems management in Ubuntu. The web-app acts as centralized interface to manage cloud based or physical Ubuntu servers in one location. I'd like it to be developed using web2py framework. The system has features found in Ubuntu's proprietary systems management tool like Landscape --(http://www.canonical.com/enterprise-services/ubuntu-advantage/landscape/systems-management) a remote management tool for Ubuntu servers and desktops. The project combines some essential features of Webmin (webmin.com) and Landscape. System Requirements: * web2py based web app * manages Ubuntu desktop or servers thru a single interface * require registration of clients (desktop or servers) to be managed by the system * install, remove, upgrade packages, update history * Manage users (create, remove, change password) * View system info (cpu, ram, io) * email notification such as status of services, package updates * support common basic configurations * ability to explore filesystem * reboot, shutdown remote servers * log viewer (/var/log) Thank you for your help and guidance. -- Eduardo B.
[web2py] Re: Systems Management Web App for Ubuntu
Does this share any functionality with: http://cloudsilverlining.org/ Cheers On Mar 22, 8:43 am, Eduardo Bergavera j...@dnsc.edu.ph wrote: Hi Everyone! I would like to ask some guidance regarding anyone who may be interested in developing web-based python app for systems management in Ubuntu. The web-app acts as centralized interface to manage cloud based or physical Ubuntu servers in one location. I'd like it to be developed using web2py framework. The system has features found in Ubuntu's proprietary systems management tool like Landscape --(http://www.canonical.com/enterprise-services/ubuntu-advantage/landsca...) a remote management tool for Ubuntu servers and desktops. The project combines some essential features of Webmin (webmin.com) and Landscape. System Requirements: * web2py based web app * manages Ubuntu desktop or servers thru a single interface * require registration of clients (desktop or servers) to be managed by the system * install, remove, upgrade packages, update history * Manage users (create, remove, change password) * View system info (cpu, ram, io) * email notification such as status of services, package updates * support common basic configurations * ability to explore filesystem * reboot, shutdown remote servers * log viewer (/var/log) Thank you for your help and guidance. -- Eduardo B.
[web2py] Re: auth.login() from inside a component in a dialog
I think this actually is a bug. I haven't looked at it more, but I changed my default controller/function to home/index When I login (regular login except for the following lines in my model) it returns me to default/index (my old controller still exists there until I finished refactoring the code). def get_last_opened(form): if auth.has_membership(auth.user.last_opened): session.table_token = auth.user.last_opened else: redirect(URL('error','index')) auth.settings.login_onaccept = get_last_opened If I have more time next week and the issue is not solved, I'll take a better look at it. On Thursday, March 22, 2012 3:33:30 PM UTC+2, Anthony wrote: I believe auth.settings.login_next only has an effect when there is no session._auth_next (i.e., when the user goes directly to the login URL rather than getting there via an internal link or redirect). Your logic is sound, but I'm afraid this is not the case. I am directly going to myapp/login and then getting redirected via session._auth_next to default/index. Puzzling. Could be a bug. I thought this is what the auth.settings.login_onaccept = [myonaccept] was supposed to do (see my example stated earlier). That was my first attempt as it seemed the most logical. Am I doing something wrong there? auth.settings.login_onaccept gets called after a successful login, but it's not the very last thing that happens in auth.login() -- after the callback, auth.login() still proceeds to do its usual redirect. The redirect starts a whole new request, so if you set response.js before the redirect, it will get lost. Here's why -- when you set response.js, it adds the JS code to a special web2py-component-command header. However, because of the redirect, that header will arrive at the browser as part of a 303 redirect response. When the browser receives a redirect response, it immediately issues the redirect request without further processing the XHR object, so the client-side web2py JS code never gets to process the web2py-component-command header. Instead, you have to set response.js *after* the redirect, or simply prevent the redirect altogether (hence my suggestion to have your callback raise an HTTP() response). Anthony
[web2py] Modify T() function
Hi, I am working on a translation enhancement project on sahana-eden[1]. sahana-eden uses the translation feature of web2py. Is it possible to have a modified T() function so that the developer can leave a comment for the translator, for example T(This is a SAMPLE, keep SAMPLE as it is) where the second argument is the comment. Or is there any other mechanism in web2py to accomplish this task. Further the language file in /applications/application name/languages/.py should be in the format source string: target string: comment I may be able to modify my local web2py so that this is accomplished. Rather I would like to see this upstream as for 1) sahana-eden is deployed with web2py framework so it needs it's core functions build into it (patching is not so nice) 2) there will be many other projects existing or about to deploy on web2py which will be benefited with this method. The whole idea is that the translator has more information that will ultimately help to end in a better translation. I'm willing to contribute in code if the developers want me to. [1] eden.sahanafoundation.org Thank you
[web2py] How to upload tables with images ?
Greetings, I'm starting with web2py and it seems to be the right tool I need for my project. My point is to upload a zip file to update or fill in a database (several tables) including pictures. This will be a feature of my application and (auth) users will be allowed to use this feature. Here are the steps: - show a form with a file-type field (done) - get the 20MB+ compressed file (zip or other) somewhere * - uncompress it (or access the files on the fly, I'll see) - get the CSV, check them and update the corresponding tables ... - ... transforming the image path field contents to a web2py upload-type field * - get the pictures and put them to the upload directory with a web2py generated name * - display ok or error on success/failure The * steps are the ones for which I need your help. I will manage the other ones (uncompress, check...). Code snippets: db.define_table('t_product', Field('f_reference', type='string', notnull=True), Field('f_photo', type='upload'), Field('f_description_multi', type='string'), [...] Compressed file contents: - product.csv - others.csv - images/product 0001.jpg - images/product 0002.jpg - images/others 0005.jpg [...] the csv contents: 023693240,file:///p/a/t/h/images/product%21.jpg,bla bla bla,[...] Till there, I've tried to get the uploaded file, but did not manage to find it if it is not stored into an upload field, and I don't need that. Yhank you for any help. Le Mogwaï
[web2py] Re: Modify T() function
I am working on a translation enhancement project on sahana-eden[1]. sahana-eden uses the translation feature of web2py. Is it possible to have a modified T() function so that the developer can leave a comment for the translator, for example T(This is a SAMPLE, keep SAMPLE as it is) where the second argument is the comment. Or is there any other mechanism in web2py to accomplish this task. Further the language file in /applications/application name/languages/.py should be in the format source string: target string: comment Right now, the language files are simply treated as Python dictionaries, so this structure would require a major change. Instead, maybe you can just write a special helper that takes a string and a comment, adds the comment to the string, passes the combined string/comment to T(), and then removes the comment from the value returned by T() upon serialization. So, in your language file, before translation you'd end up with something like: source string [[comment: my comment]]: source string [[comment: my comment]] When retrieving a translation, your helper would then look for [[comment: .*]]$ at the end of the retrieved value and remove it if it is there. Anthony
[web2py] Re: How to upload tables with images ?
Upon submission of the form, you should find the file itself in request.vars.f_photo.file (and the filename in request.vars.f_photo.filename). Anthony On Thursday, March 22, 2012 9:11:10 AM UTC-4, LeMogwaï wrote: Greetings, I'm starting with web2py and it seems to be the right tool I need for my project. My point is to upload a zip file to update or fill in a database (several tables) including pictures. This will be a feature of my application and (auth) users will be allowed to use this feature. Here are the steps: - show a form with a file-type field (done) - get the 20MB+ compressed file (zip or other) somewhere * - uncompress it (or access the files on the fly, I'll see) - get the CSV, check them and update the corresponding tables ... - ... transforming the image path field contents to a web2py upload-type field * - get the pictures and put them to the upload directory with a web2py generated name * - display ok or error on success/failure The * steps are the ones for which I need your help. I will manage the other ones (uncompress, check...). Code snippets: db.define_table('t_product', Field('f_reference', type='string', notnull=True), Field('f_photo', type='upload'), Field('f_description_multi', type='string'), [...] Compressed file contents: - product.csv - others.csv - images/product 0001.jpg - images/product 0002.jpg - images/others 0005.jpg [...] the csv contents: 023693240,file:///p/a/t/h/images/product%21.jpg,bla bla bla,[...] Till there, I've tried to get the uploaded file, but did not manage to find it if it is not stored into an upload field, and I don't need that. Yhank you for any help. Le Mogwaï
[web2py] Re: How to get pound sign in url or work around it?
I might have missed something. Are you trying to move the viewport to the element with the id after the hash? If so, would you be able to use: document.location.hash = tabs=2; Does that work? On Wednesday, March 21, 2012 5:39:08 PM UTC-4, Cliff wrote: Thanks, Jonathan. I appreciate the hint. For anyone interested, there are a few more things you have to do. If you just add anchor='tabs-2' to URL(), it renders /bla/edit/ 5#tabs-2. Not an invalid request, but it doesn't get you to the anchor, either. So do something like URL(bla, args=[request.args(0), ''], anchor='tabs-2'). That renders bla/edit/5//#tabs-2. Note the two slashes. This works but only one time, even if you create an observer by using live(). A call to location.reload() fixes that problem. Here is the complete function. It is kind of slow. $('#clickme').live('click', function(){ alert('hi'); // make sure we are firing on click window.location.href = {{=URL('edit', anchor='tabs-2',args=[str(request.args(0))])}}; location.reload; }); On Mar 21, 4:04 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 21, 2012, at 12:49 PM, Cliff wrote: Here is a snippet of javascript code: window.location.href = {{=URL('edit', args=[request.args(0), '#tabs-2'])}}; Notice the '#' in the args list. URL persists in rendering the '#' as %23, which causes Web2py to throw an 'Invalid Request' page. I have tried using XML to preserve the pound sign, but to no avail. How can I work around this? Try adding the argument anchor='tabs-2' to URL().
[web2py] SQLForm.grid : how to change the way column are rendered
Hello, I just discovered SQLForm.grid ! Waow, geat job !! I'd like to customize some columns in the generated table. Example use case : - Use the pretty date formatting instead of displaying the raw date (yesterday, etc ...) - Use an icon instead of a status flag. Is it possible ? How to do it ? Thanks Seb
Re: [web2py] Re: [video] websockets com web2py e tornado
Thank you Bruno! Richard On Thu, Mar 22, 2012 at 8:25 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: +1 On Thursday, 22 March 2012 05:23:17 UTC-5, Ramos wrote: I disaggree. I´m portuguese and Bruno is perfect explaining websockets in web2py! Add english subtitles!!! Sorry, this is in Portuguese and should go only to Brazilian groups... On Thu, Mar 22, 2012 at 5:10 AM, Bruno Rocha rochacbr...@gmail.comwrote: *Curso De Python .com.br * websockets com tornado, web2py, Python, jQueryhttp://vimeo.com/38972256, [image: websockets com tornado, web2py, Python, jQuery]http://vimeo.com/38972256 *websockets com tornado, web2py, Python, jQuery* http://vimeo.com/38972256 Envio de mensagens Server--Client utilziando websockets (comet) com tornado e web2py. http://www.cursodepython.com.**brhttp://www.cursodepython.com.br *Mais videos como este disponíveis em:* http://www.cursodepython.com.**br/videoshttp://www.cursodepython.com.br/videos [image: Inline image 1] http://www.cursodepython.com.br/videos -- Bruno Rocha [http://rochacbruno.com.br] -- Bruno Rocha [http://rochacbruno.com.br]
[web2py] Re: Book translation
Count on me to translate the book to Spanish! -- Miguel On Tuesday, December 27, 2011 6:03:31 PM UTC+2, Mirek Zvolský wrote: I want start translation of the book 4th edition (czech language). Can I read somewhere hints, how to do it? Idea: Can we have menu item in web2py.com/book (Translations?) with such hints?
[web2py] Re: How do I group the list by value and make it table in HTML?
You can simply loop over a sorted list (first by the state, then by name): city_list = [('Huntsville', 'AL'), ('Decatur', 'AL'), ('Anchorage', 'NV'), ('Nome', 'AK'),('Selma', 'AL'), ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')] sorted_list = sorted(city_list, key=lambda x: (x[1],[0])) last = None for city, state in sorted_list: if state != last: print(state) last = state print(city)
[web2py] Re: Modify T() function
Just a simpler idea : as the language file is a python dictionary, why not put the comment in a python comment? source string: target string, #comment Cedric On 22 mar, 15:53, Anthony abasta...@gmail.com wrote: I am working on a translation enhancement project on sahana-eden[1]. sahana-eden uses the translation feature of web2py. Is it possible to have a modified T() function so that the developer can leave a comment for the translator, for example T(This is a SAMPLE, keep SAMPLE as it is) where the second argument is the comment. Or is there any other mechanism in web2py to accomplish this task. Further the language file in /applications/application name/languages/.py should be in the format source string: target string: comment Right now, the language files are simply treated as Python dictionaries, so this structure would require a major change. Instead, maybe you can just write a special helper that takes a string and a comment, adds the comment to the string, passes the combined string/comment to T(), and then removes the comment from the value returned by T() upon serialization. So, in your language file, before translation you'd end up with something like: source string [[comment: my comment]]: source string [[comment: my comment]] When retrieving a translation, your helper would then look for [[comment: .*]]$ at the end of the retrieved value and remove it if it is there. Anthony
[web2py] Re: SQLForm.grid : how to change the way column are rendered
You can use a format string to define the data representation, read this: http://web2py.com/books/default/chapter/29/6#Record-representation To get the icons, instead of a format string, pass a function that generates the required HTML code.
Re: [web2py] Re: Conditional Fields
Ok, if I am understanding correctly you want a complex validation. I mean validating a field base on the input of an other field. Default web2py validator are applying only to one field at a time. It is possible to do what you ask for, but it will require that you implement your own validator. You can have a look into gluon/validators.py to figure out where to start. I use to modify some of the web2py validator in the pass to make sure that only one FK is provided for a table where to kind of relation was used cause by a bad design. Check validators.py and if you still want to make complex validation I could help a little bit. Richard On Wed, Mar 21, 2012 at 4:30 PM, Rakesh Singh rak...@verifaction.co.zawrote: Hi Richard, My tables are pretty large (30-60 columns each), so let me use another test table. Let's say we have a table called survey. If the user selects Male in the Sex field, Favourite Car and Favourite Sport must not be empty. Favourite Perfume and Favourite Soapie can be empty. If the user selects Female then the opposite applies. I was initially trying to hide the fields, and only unhide the appropriate ones bases on the user input. But it is not necessary. I don't mind displaying all fields, as long as they are validated based on user input. I initially tried SQLFORM.grid and smartgrid, but what I want to achieve does not seem possible. I thought of splitting the input form into multiple forms, but due to the number of conditions, it won't be feasible to the user. Thank you for any advice/suggestions. Regards, Rakesh #-- TABLE DEFINITION db.define_table('survey', Field('fname', 'string', length=25, required=True, requires=[IS_NOT_EMPTY(), IS_UPPER()], label='First Name'), Field('sname', 'string', length=80, required=True, requires=[IS_NOT_EMPTY(), IS_UPPER()], label='Surname'), Field('sex', 'string', length=1, required=True, requires=[IS_NOT_EMPTY(), IS_UPPER(), IS_IN_SET(['F', 'M'])], label='Sex'), Field('fav_perfume', 'string', length=20, required=False, requires=IS_UPPER(), label='Favourite Perfume'), Field('fav_soapie', 'string', length=20, required=False, requires=IS_UPPER(), label='Favourite Soapie'), Field('fav_car', 'string', length=20, required=False, requires=IS_UPPER(), label='Favourite Car'), Field('fav_sport', 'string', length=20, required=False, requires=IS_UPPER(), label='Favourite Sport') ) On Mar 20, 11:46 am, Richard Vézina ml.richard.vez...@gmail.com wrote: We will need more code to help you... Regards Richard On Tue, Mar 20, 2012 at 10:15 AM, Rakesh Singh rak...@verifaction.co.za wrote: Hi All, Apologies if this has been covered before but I cannot seem to find the appropriate solution in the archives or in the web2py book. I am using SQLFORM.grid to generate an interface into my table. Some of my fields in the table are only required based on other inputs. As a simple example, if the user is an individual, the Identity Number field must be completed. But if it is a business, the Company Registration Number field must be completed. I read the Conditional Field section in the book, but I cannot seem to get it to work on my form. Also, my table name and columns have quite a few underscores, so I'm not sure if this is affecting the jQuery syntax. eg. NCS_SARS_DECLARANT is the table, RECORD_TYPE is the column If I understand correctly, I should have : jQuery('#NCS_SARS_DECLARANT_RECORD_TYPE__row').hide() ? What is the suggested way in achieving this? Many thanks. Regards, Rakesh Running Web2py Version 1.99.7
[web2py] Re: SQLForm.grid : how to change the way column are rendered
Thanks for your quick answer. I figure it out just right now, here is my. It's working as expected !! def formatFlag(value): if value == 1: icon = 'msg_received' elif value ==0: icon = 'msg_sent' return IMG(_src=URL('static', 'images/%s.png' % icon), _alt='icon') db.message.flags.represent = lambda value,row: formatFlag(value) On Mar 22, 5:28 pm, Wikus van de Merwe dupakrop...@googlemail.com wrote: You can use a format string to define the data representation, read this:http://web2py.com/books/default/chapter/29/6#Record-representation To get the icons, instead of a format string, pass a function that generates the required HTML code.
[web2py] Re: Conditional Fields
There are two separated things here. One is presentation of required attributes only, the other is validation of the from. The first one could be solved with the conditional field approach described in the book. If you are not sure what are the ids for generated form elements, simply view the generated HTML code in your browser. To implement the validation you need to use your own function in the controller: def validate_survey(form): if M == form.vars.sex: if not form.vars.fav_car: form.errors.fav_car = favorite car is required if not form.vars.fav_sport: form.errors.fav_sport = favorite sport is required elif F == form.vars.sex: if not form.vars.fav_soapie: form.errors.fav_soapie = favorite soap opera is required if not form.vars.fav_perfume: form.errors.fav_perfume = favorite perfume is required And the use it with the grid: grid = SQLFORM.grid(db.survey, onvalidation=validate_survey)
[web2py] Re: Modify T() function
Just a simpler idea : as the language file is a python dictionary, why not put the comment in a python comment? source string: target string, #comment It sounds like he wants to be able to specify the comment in the application code where T() is called -- e.g., T('my string', comment='my comment'). If that's not a requirement, a Python comment in the file might be fine (though I assume it would not be visible when editing the language file in the admin interface). Anthony
[web2py] Re: creating relationship between two tables
Well, it is trying to create the contacts table before it creates the customers table. That's the problem. I don't know if that's an issue in the DAL or if I just need to re-arrange the statements in my db.py - they are correctly ordered in the db.py - it seems that it wants to create the association before it actually creates the associated table. Not sure how I would test that in SQLite. Is that installed and running already? On Thursday, March 22, 2012 6:11:46 AM UTC-7, Anthony wrote: I've seen both, and I think that the second doesn't make a foreign key constraint, it just creates an int field... not sure though. Field('customer', 'reference customers') and Field('customer', db.customers) are equivalent (behind the scenes, when you do type=db.customers, it is converted to type='reference customers'), and both create a foreign key constraint. Note, your error is not about the constraint but seems to indicate that customers is an invalid table. I'm not sure why, though -- the model definition looks OK. Have you tried it on SQLite? Anthony On Thursday, March 22, 2012 6:11:46 AM UTC-7, Anthony wrote: I've seen both, and I think that the second doesn't make a foreign key constraint, it just creates an int field... not sure though. Field('customer', 'reference customers') and Field('customer', db.customers) are equivalent (behind the scenes, when you do type=db.customers, it is converted to type='reference customers'), and both create a foreign key constraint. Note, your error is not about the constraint but seems to indicate that customers is an invalid table. I'm not sure why, though -- the model definition looks OK. Have you tried it on SQLite? Anthony
[web2py] SQLForm text and newlines
I am prefilling a field in an SQLForm, but there are other fields that the user will fill out. The text I am prefilling I would like to display, but not allow the user to edit it. I am setting the writable to false, but the problem is the text I am filling with has multiple lines all separated by newlines(\n). I need to keep the newlines because this data will eventually be pulled out of the database, put into a file, and then loaded on some hardware, so replacing the '\n' with br isn't really an option. The problem is by setting writable to false, it converts the text just to normal html text which doesn't understand newlines. I would like to either put the data into a textarea, but I will need to disable it so the user can't modify it, or figure out a way to replace the newlines with br but only on the html page, and make sure newlines are entered in the database. Any help is greatly appreciated.Thanks!
[web2py] Re: creating relationship between two tables
Well, it is trying to create the contacts table before it creates the customers table. That's the problem. I don't know if that's an issue in the DAL or if I just need to re-arrange the statements in my db.py - they are correctly ordered in the db.py - it seems that it wants to create the association before it actually creates the associated table. Not sure how I would test that in SQLite. Is that installed and running already? Yes, SQLite is included with Python, so no need to install. You don't even have to create the SQLite db manually -- it will be created automatically by web2py. I only suggested that to confirm the issue is specific to MSSQL. Anthony
[web2py] Re: zip xls file and return it in response
http://docs.python.org/library/zipfile.html It's part of the python standard library. On Thursday, March 22, 2012 6:03:41 AM UTC-7, Neveen Adel wrote: Hello, Am generating xls file using the following code: response.headers['Content-Type'] = gluon.contenttype.contenttype('.xls') response.headers['Content-disposition'] = 'attachment; filename=file.xls' today = str(datetime.today()) wbk.save(temp1+today+.xls) f = open(temp1+today+.xls, 'r') out= f.read() f.close() return out How can zip file.xls and return it ?? could you please any Advices ??
[web2py] Re: auth.login() from inside a component in a dialog
mini rant to others considering this type of thing Why waste so much time and energy overcomplicating something that works perfectly out-of-the-box? 99% of projects do not benefit from a modal login. Modal log-ins can actually be worse since they don't always work everywhere and they don't always have a unique URL where you can send people. Sure Twitter does it, but look who doesn't: Facebook, Apple, Google, Ebay, etc. /mini rant
[web2py] cross-domain auth
Hi, I'm wondering if it's possible to have cross-domain auth in web2py (different domains pointing to the same web2py app and sharing the same cookie)?. I believe this is not possible because cookies (web2py's session cookie) can not be shared across domains, correct?. Or is there some kind of trick I can do to accomplish this?. Thanks! Carlos
[web2py] Re: How to upload tables with images ?
Thank you Anthony, you helped me for the first step. I found the SQLFORM.factory concept and together with your info, I've been able to get my file and start to process it. Now, here is how my action looks like: @auth.requires_login() def dbimport(): result = Please, upload a packed database form = SQLFORM.factory(Field('packed_db', 'upload', label=T('Packed database to load'), uploadfolder='uploads')) if form.process().accepted: response.flash = 'Machin chargé' result = packed_db_process(request.vars.packed_db.file) elif form.errors: response.flash = 'Pwët error' return dict(form=form, result=result) Note that the file does not appear in the uploads folder! That's the reason why I first was disappointed. But the file is still in memory! Now that I'm able to process my file (with the zipfile module) I'm able to extract the csv and the pictures from it, but I need a function to encode the names from product 0001.jpg to t_product.f_photo.xx..jpg and store them into the uploads directory. Ho, ho ! I think I just found a way there: http://web2py.com/books/default/chapter/29/6#Manual-uploads I'll keep you in touch if I get stuck again. Thank you! Le Mogwaï Le jeudi 22 mars 2012 16:00:25 UTC+1, Anthony a écrit : Upon submission of the form, you should find the file itself in request.vars.f_photo.file (and the filename in request.vars.f_photo.filename). Anthony
[web2py] Re: efficient DB queries
This is not the best way. It will run a separate query for each board id. On GAE you want to do as much as you can in a single query. So the best way is to construct a list of GAE keys and get all entities together. Unfortunately, AFAIK, there is no support for GAE batch queries in DAL. You can, however, try to refer to the GAE datastore directly. from google.appengine.ext import db as gdb articles = db().select(db.articles.ALL) keys = [gdb.Key.from_path(boards, a.board_id) for a in articles] boards = gdb.get(keys) But I'm afraid this is not an elegant solution as it probably won't work without a gdb.Model defined for the board entity, and that would go against DRY [1]. Anyway, if you want to do it, see the GAE docs [2] for details on model definition. Depending on how often are you going to perform this query a better solution might be redesigning your database. Forget about 3NF and add the board attributes to each article entity so that you can fetch everything together in a single query. [1] https://en.wikipedia.org/wiki/Don%27t_repeat_yourself [2] http://code.google.com/appengine/docs/python/datastore/entities.html
[web2py] Re: How to upload tables with images ?
Looks like you're on the right track. On Thursday, March 22, 2012 2:19:16 PM UTC-4, LeMogwaï wrote: Thank you Anthony, you helped me for the first step. I found the SQLFORM.factory concept and together with your info, I've been able to get my file and start to process it. Now, here is how my action looks like: @auth.requires_login() def dbimport(): result = Please, upload a packed database form = SQLFORM.factory(Field('packed_db', 'upload', label=T('Packed database to load'), uploadfolder='uploads')) if form.process().accepted: response.flash = 'Machin chargé' result = packed_db_process(request.vars.packed_db.file) elif form.errors: response.flash = 'Pwët error' return dict(form=form, result=result) Note that the file does not appear in the uploads folder! That's the reason why I first was disappointed. But the file is still in memory! Now that I'm able to process my file (with the zipfile module) I'm able to extract the csv and the pictures from it, but I need a function to encode the names from product 0001.jpg to t_product.f_photo.xx..jpg and store them into the uploads directory. Ho, ho ! I think I just found a way there: http://web2py.com/books/default/chapter/29/6#Manual-uploadshttp://web2py.com/books/default/chapter/29/6#Manual-uploads I'll keep you in touch if I get stuck again. Thank you! Le Mogwaï Le jeudi 22 mars 2012 16:00:25 UTC+1, Anthony a écrit : Upon submission of the form, you should find the file itself in request.vars.f_photo.file (and the filename in request.vars.f_photo.filename). Anthony
[web2py] Re: cross-domain auth
Have you looked into using CAS (http://web2py.com/books/default/chapter/29/9#Central-Authentication-Service)? On Thursday, March 22, 2012 2:16:42 PM UTC-4, Carlos wrote: Hi, I'm wondering if it's possible to have cross-domain auth in web2py (different domains pointing to the same web2py app and sharing the same cookie)?. I believe this is not possible because cookies (web2py's session cookie) can not be shared across domains, correct?. Or is there some kind of trick I can do to accomplish this?. Thanks! Carlos
[web2py] Re: SQLForm text and newlines
Something like: db.mytable.myfield.default = 'some\ntext\nwith\nline\nbreaks' db.mytable.myfield.represent = lambda v, r: XML(v.replace('\n', 'br /')) db.mytable.myfield.writable = False With writable=False, no value will actually be submitted with the form -- the default value will simply be inserted with the new record. However, the represent function will be used to display the read-only value on the form. Note, you can also specify the above three attributes directly in the initial field definition: db.define_table('mytable', Field('myfield', default=..., represent=..., writable=False)) Note, in the represent function, it is necessary to wrap the value in XML() so the br / doesn't get escaped when serialized in the response body. Anthony On Thursday, March 22, 2012 1:52:25 PM UTC-4, Brian F wrote: I am prefilling a field in an SQLForm, but there are other fields that the user will fill out. The text I am prefilling I would like to display, but not allow the user to edit it. I am setting the writable to false, but the problem is the text I am filling with has multiple lines all separated by newlines(\n). I need to keep the newlines because this data will eventually be pulled out of the database, put into a file, and then loaded on some hardware, so replacing the '\n' with br isn't really an option. The problem is by setting writable to false, it converts the text just to normal html text which doesn't understand newlines. I would like to either put the data into a textarea, but I will need to disable it so the user can't modify it, or figure out a way to replace the newlines with br but only on the html page, and make sure newlines are entered in the database. Any help is greatly appreciated.Thanks!
[web2py] Re: creating relationship between two tables
Yes, it works on sqlite, it doesn't seem to enforce the reference, it asked me to manually type the reference, and when i put in something invalid, it put it as a zero instead of giving me an error in the form. According to the web2py documentation, this should be the default: reference tableIS_IN_DB(db,table.field,format) But it's not doing any checks at all apparently. And sqlite doesn't enforce referential integrity anyway. On Thursday, March 22, 2012 10:53:43 AM UTC-7, Anthony wrote: Well, it is trying to create the contacts table before it creates the customers table. That's the problem. I don't know if that's an issue in the DAL or if I just need to re-arrange the statements in my db.py - they are correctly ordered in the db.py - it seems that it wants to create the association before it actually creates the associated table. Not sure how I would test that in SQLite. Is that installed and running already? Yes, SQLite is included with Python, so no need to install. You don't even have to create the SQLite db manually -- it will be created automatically by web2py. I only suggested that to confirm the issue is specific to MSSQL. Anthony
[web2py] Re: How to upload tables with images ?
Ah, that's what I love about web2py and python - things like this are not too difficult to accomplish, especially since a lot of it is built into the standard libraries. , On Thursday, March 22, 2012 11:19:16 AM UTC-7, LeMogwaï wrote: Thank you Anthony, you helped me for the first step. I found the SQLFORM.factory concept and together with your info, I've been able to get my file and start to process it. Now, here is how my action looks like: @auth.requires_login() def dbimport(): result = Please, upload a packed database form = SQLFORM.factory(Field('packed_db', 'upload', label=T('Packed database to load'), uploadfolder='uploads')) if form.process().accepted: response.flash = 'Machin chargé' result = packed_db_process(request.vars.packed_db.file) elif form.errors: response.flash = 'Pwët error' return dict(form=form, result=result) Note that the file does not appear in the uploads folder! That's the reason why I first was disappointed. But the file is still in memory! Now that I'm able to process my file (with the zipfile module) I'm able to extract the csv and the pictures from it, but I need a function to encode the names from product 0001.jpg to t_product.f_photo.xx..jpg and store them into the uploads directory. Ho, ho ! I think I just found a way there: http://web2py.com/books/default/chapter/29/6#Manual-uploadshttp://web2py.com/books/default/chapter/29/6#Manual-uploads I'll keep you in touch if I get stuck again. Thank you! Le Mogwaï Le jeudi 22 mars 2012 16:00:25 UTC+1, Anthony a écrit : Upon submission of the form, you should find the file itself in request.vars.f_photo.file (and the filename in request.vars.f_photo.filename). Anthony
[web2py] Re: SQLForm text and newlines
That worked perfectly. Thanks! On Thursday, March 22, 2012 3:06:37 PM UTC-4, Anthony wrote: Something like: db.mytable.myfield.default = 'some\ntext\nwith\nline\nbreaks' db.mytable.myfield.represent = lambda v, r: XML(v.replace('\n', 'br /')) db.mytable.myfield.writable = False With writable=False, no value will actually be submitted with the form -- the default value will simply be inserted with the new record. However, the represent function will be used to display the read-only value on the form. Note, you can also specify the above three attributes directly in the initial field definition: db.define_table('mytable', Field('myfield', default=..., represent=..., writable=False)) Note, in the represent function, it is necessary to wrap the value in XML() so the br / doesn't get escaped when serialized in the response body. Anthony On Thursday, March 22, 2012 1:52:25 PM UTC-4, Brian F wrote: I am prefilling a field in an SQLForm, but there are other fields that the user will fill out. The text I am prefilling I would like to display, but not allow the user to edit it. I am setting the writable to false, but the problem is the text I am filling with has multiple lines all separated by newlines(\n). I need to keep the newlines because this data will eventually be pulled out of the database, put into a file, and then loaded on some hardware, so replacing the '\n' with br isn't really an option. The problem is by setting writable to false, it converts the text just to normal html text which doesn't understand newlines. I would like to either put the data into a textarea, but I will need to disable it so the user can't modify it, or figure out a way to replace the newlines with br but only on the html page, and make sure newlines are entered in the database. Any help is greatly appreciated.Thanks!
[web2py] Re: creating relationship between two tables
Yes, it works on sqlite, it doesn't seem to enforce the reference, it asked me to manually type the reference, and when i put in something invalid, it put it as a zero instead of giving me an error in the form. According to the web2py documentation, this should be the default: reference tableIS_IN_DB(db,table.field,format) But it's not doing any checks at all apparently. I guess the book should be more clear -- the above default validator is only added if the referenced table includes a _format attribute. So, if you do: db.define_table('customers', Field('name', 'string',length=50), Field('sapID', 'string', length=10), Field('city', 'string',length=50), Field('state', 'string', length=2), Field('country','string',length=3), Field('active','integer'), format='%(name)s') or db.customers._format = '%(name)s' then when you create a SQLFORM based on the db.contacts table, the customer field will be a dropdown showing the names of existing customers in the db.customers table and the validator will enforce the reference. You can also add the IS_IN_DB validator manually. Anyway, I'm still not sure why you're getting the invalid table error in MSSQL. What happens if you only define the customers table and then try some operations with it -- does that work? Can you create two very simple tables with a reference from one to the other in MSSQL, or does that always generate this error? Anthony
Re: [web2py] Re: sqlite on production
It doesn't scale in the sense that you can't cluster sqlite, it writes everything in a single file, and the developers themselves say 'dont use it for sites that have 100k hits/day'. On Wednesday, March 21, 2012 1:06:38 PM UTC-7, Vasile Ermicioi wrote: It is not recommended. All updates will lock the entire database, since it is designed for one user. Also, it does not scale. enable wal (http://www.sqlite.org/draft/wal.htmlhttp://www.sqlite.org/draft/wal.html) and it will not lock Also, it does not scale do you have any numbers? at which point it doesn't scale?
[web2py] Re: creating relationship between two tables
On Thursday, March 22, 2012 2:08:06 PM UTC-7, Anthony wrote: Yes, it works on sqlite, it doesn't seem to enforce the reference, it asked me to manually type the reference, and when i put in something invalid, it put it as a zero instead of giving me an error in the form. According to the web2py documentation, this should be the default: reference tableIS_IN_DB(db,table.field,format) But it's not doing any checks at all apparently. I guess the book should be more clear -- the above default validator is only added if the referenced table includes a _format attribute. So, if you do: db.define_table('customers', Field('name', 'string',length=50), Field('sapID', 'string', length=10), Field('city', 'string',length=50), Field('state', 'string', length=2), Field('country','string',length=3), Field('active','integer'), format='%(name)s') or db.customers._format = '%(name)s' then when you create a SQLFORM based on the db.contacts table, the customer field will be a dropdown showing the names of existing customers in the db.customers table and the validator will enforce the reference. You can also add the IS_IN_DB validator manually. Anyway, I'm still not sure why you're getting the invalid table error in MSSQL. What happens if you only define the customers table and then try some operations with it -- does that work? Can you create two very simple tables with a reference from one to the other in MSSQL, or does that always generate this error? Anthony Thanks for your help Anthony. I'll try adding the format to see if that helps. I was using 'database administration' so maybe it's not using a SQLFORM there. I'll make a page with sqlform and see if that works better. yes, the table without references works just fine. the 'dog' and 'person' tables seem to work okay. This is what gives me an error, and I copied what I did with the person and dog tables (see that below). db.define_table('customers', Field('name', 'string',length=50), Field('sapID', 'string', length=10), Field('city', 'string',length=50), Field('state', 'string', length=2), Field('country','string',length=3), Field('active','integer')) db.define_table('contacts', Field('customer', db.customers), Field('lastname', 'string', length=25), Field('firstname', 'string', length=25), Field('phone','string',length=15), Field('email','string',requires=IS_EMAIL()), Field('active','integer')) db.contacts.customer.requires = IS_IN_DB(db, db.customers.id, '%(name)s') -- this fails with the SQL error. #db.define_table('person', #Field('name', requires=IS_NOT_EMPTY())) #db.define_table('dog', #Field('owner', db.person), #Field('name', requires=IS_NOT_EMPTY())) #db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%(name)s') -- this works fine. I don't know what is going on... the dog and person tables work, but the customers and contacts tables do not.
[web2py] infinite loop with form.process().accepted
i don't understand : def generate_invitation(number,word=4,num=1,numdigit=5): code = [ ['BELCHER', 'FIX', 'EEL', 'PANZERBOY', 'DESK_JOCKEY', 'CHILLED', 'ENFORCER', 'CHERRY_PICKING', 'COUNTRY_CLUB', 'BOMBSHELL', 'PLUGGED_IN', 'FINI', 'LEGIT', 'JAM', 'BONED_OUT', 'BLADE', 'ROUST', 'SAMURAI', 'DISK', 'INPUT', 'POST_TIME', 'SOUNDS', 'SKIP', 'FLATBACKER', 'WILSON', 'SHOEMAKER', 'DELTA_SIERRA', 'HEART', 'CROAK', 'HEAD_HUNTER', 'HOSHO_KAISHA', DELTA'D, 'FACE_(also,_FACE,_EYE-FACE,_I-FACE), 'WEEFLE', 'DIRTGIRL', 'KEYBOARD', 'BRAIN_BUCKET', 'DRYING_OUT', 'OVERCOOK', 'PIG', 'COLD_TEA', 'RECONFIG', 'PAD', 'LIT_UP', 'WRAITH', 'HANDLE', 'L.P.', 'PINCH', 'TAKE_A_CAB', 'SPILL', 'ACE_KOOL', 'DO', 'BIZ', 'BROWNIE', 'CANDLE_AND_BLOOD', 'BLUEBOY', 'UP_ON_IT', 'BURN', 'USER_INTERFACE', 'HOB', 'GYRO', 'STUFFIT', 'THATCH', 'ICEBREAKER', 'ZIP_GUN', 'PETERMAN', 'PLAY_DOUGH', 'TREY-EIGHT', 'SETTLE', CHIPPIN'_IN, 'MEATBALL', 'RAFFLES', 'YUBITSUME', 'CROAKER', 'SUCKER_POCKETS', 'L.A.M.A.', 'GEEK', 'BUTTONHEAD'], ['TAKE', 'TEKIYA', 'KURUMAKU', 'BLOC', 'GAT', 'JOHATSU', 'CRYSTAL', 'A.I.', 'ZEROED', 'OVER_THE_SHOULDER', 'GRAB_GEE', 'PANZER', 'GO_LEO', 'WASHED', 'I.C.E.', 'COPSHOP', 'COLLATERAL_DAMAGE', 'BIG_DARK', 'DOUBLE-DEUCE', 'ZONEDANCE', 'MARK', 'COBBERS', 'CHIMPIRA', 'TRIADS', 'SHANK', 'FRAG', 'BREATH_VAC', CHARLIE'S_ANGEL, 'MULE', 'BURNER', PACKIN', 'HOTDOGGER', 'BOSOZOKU', 'RIPPERDOC', 'THIRDMAN', 'MAXIMUM,_MAX', 'CHOOH2_(CHOO)', 'CRYO_MAX', 'HEATER', 'SHARK', 'JOYGIRL', 'GURENTAI', 'BANDIT', 'VENICE', 'MIZU_SHOBAI', 'PASTA_BOYS', 'SQUID', 'CYBERED_UP', 'DEAD_RECKONING', 'POPSICLE', 'FAUST', 'COLLARBOY', 'SHOES', 'TORCH', 'DELTAJOCK', 'BUTTERFLY_MAN', 'WISE_GUYS', 'BOOST', 'CAIN', 'FOUR-FIVE', 'BREAK-DOWN', 'POLYMER_ONE-SHOT', 'FLAG', 'CALL_GIRL', 'IN_THE_HUNT', 'HYDRO', 'DOCK', 'FENCE', 'SHAIKUJIN', 'GOMI', 'FILTER', 'SAINT_NICK', 'LINEFOOT', 'CAVALRY', 'PUKE', 'CONVERSION', 'FINGER', 'CONTRACT'], ['PLASTIC', 'CRYSTALJOCKEY,_CRYSTALJOCK', 'SCREW', 'TOYSTORE', 'DREAM_TIME', 'EXOTIC', 'WALKABOUT', 'DIAMOND_SEASON', 'SARAKIN', 'CHRISTMAS_BUNDLES', 'SHADES', 'BUTTON_MAN', 'FOXTROT_UNIFORM', 'KAI', 'UNDER_THE_PAINT', 'MINIMUM', 'TRIPLE_A', 'PIG_ON_A_WHEEL', 'BAG_MAN', 'DIP', 'PIGEONS', 'MAN', 'ADAM_HENRY', 'HIGH', 'HEAT', 'NINJO', 'KNIFE_FIGHT', 'MOUTHPIECE', 'AGRIPLEX', 'DATA_TERM', 'LIZ', 'CHROMER', 'OUTPUT', 'N.O.E.', 'CLOSE_A_CONTRACT', 'LASSIE', 'FLATLINE', 'CHIV', 'SING', 'AMMO', 'RAT', 'MATCHBOX', 'PULL_AN_ASH', 'BORYOKUDAN', 'SQUEEZE', 'RONIN', 'HIT', 'RAGS', 'TAKE_OUT', 'BEAT_THE_RAP', 'GIRI', 'RUNNING_THE_LINE', 'HARNESS', 'GRAVEROBBER', 'DROP_A_DIME', 'BADGE_ON_A_BEAVER', 'FLETCHER', 'AMPED-OUT', 'NEUTRALIZE', 'PETER', 'CONFIG', 'HARDFIRE', 'B.A.M.A.', 'CHROMATIC_ROCK', 'MOLDED', 'RAD', 'CREASED', 'CHATTER_BOX', 'HAND_CANNON', 'NIPPERS', 'SIERRA_HOTEL', 'HOOK_UP', '-JOCKEY,_-JOCK', 'BUG', 'BATMAN_AND_ROBIN', 'BLACK_OPERATIONS', D.C.'S, 'SO_KA'], ['_A.A.A.', 'HOME_PLATE', 'LITEJACK', 'PINEAPPLE', 'MAKE', 'THE_STREET', 'SITREP', 'HANGING_PAPER', 'PAINT_BOYS', 'WETWORK', 'NINER', 'BOOKIE', 'WHIPLASH', 'TORPEDO', 'HEATWAVE', 'SOLAR_WIND', 'QUIFF', 'BIKE', 'TRAFFIC', 'WIRE_ROOM', 'OYABUN', 'COWBOY', 'KOBUN', 'MUDBOY', 'COP_OUT', 'SOKAIYA', 'DORPH, 'JOYBOY', 'DIRTY', 'BOAT', 'DROP', 'GRAV_or_GEE', 'APOGEE', 'BOOSTER', 'BOOK', 'FRY', 'PULLING_TEETH', 'ONE_LARGE', 'COMBAT_DRUGS', 'THRASH', 'DO_A_GHOST', 'DELTA', 'RIN_TIN_TIN', 'DROP_OUT', 'GUMI', 'ROCKERBOY/GIRL', 'BULLET', 'DEB', 'THREADING_THE_NEEDLE', 'MOTOR', 'BLEEDER', 'ARC', 'BOPPER', 'WASTE', '___DEMUKAI', 'BREAK', 'HOLDING_DOWN', 'FEDS', 'GAP', 'RABBI', 'BAKUTO', 'CHOMBATTA_(CHOOMBA)', 'BIG_HATS', 'MR._JOHNSON', 'EXEC', 'BULL', 'BULLSEYE', 'POSERGANG', 'CHAOL', 'GEISHA', 'SLAMMIT_ON', 'POP_CAPS', 'HARD_TIME', 'BENJI', 'MAKING_BANK', 'PAPERHANGER', 'NETRUN', 'BOGEY'], ] i = 0 invits = [] print number while (i number): invit = j = 0 while (j word): debut = random.randint(0,len(code)-1) codepick = code[debut][random.randint(0,len(code[debut])-1)] j += 1 invit += codepick+- j = 0 while (j num): invit += randomdig(numdigit)+- j += 1 i+= 1 invit = invit[:-1] if invit not in invits : invits.append(invit[:-1]) print invit return invits def randomdig(number): max = 9*number max = int(max) rand = random.randint(0,max) rand = str(rand) rand = 0*(number-len(rand))+rand return rand #@auth.requires_membership('manager') def generate_invitationpage(): form=FORM(Nombre d'invit a générer:, INPUT(_name='nmbreinvit'), INPUT(_type='submit')) if form.process().accepted: i = form.vars.nmbreinvit invitsgenere = generate_invitation(i) for invit in invitsgenere : db.Invitation.insert(Code=invit) db.commit() session.flash = 'invitation inserted' return
[web2py] Re: creating relationship between two tables
I'll try adding the format to see if that helps. I was using 'database administration' so maybe it's not using a SQLFORM there. Yes, appadmin uses SQLFORM and should show the dropdown as well (but only if the referenced table has a format specified or you add the validator manually). I don't know what is going on... the dog and person tables work, but the customers and contacts tables do not. This is strange -- you can create the customers table by itself, add and query records, but if you then try to create the contacts table with a reference to customers, it gives you an error saying the customers table is invalid? I'm not sure what to make of that. Anthony
[web2py] Validating Registration fields
I'm using the auth.settengs.extra_fields to add an extra upload field for the user to upload an avatar, how can I add an IS_IMAGE validator to the upload field so that the user can't upload random files? Also, how would I add an IS_ALPHANUMERIC to the built in First name and Last name form fields? Right now there are users registering with names like !@#$%^~ and some such... Thanks!
[web2py] Re: creating relationship between two tables
Yeah, I know. Baffles me. Here's the traceback. I guess I'll go open an issue. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. Traceback (most recent call last): File C:\Temp\web2py\gluon\restricted.py, line 204, in restricted exec ccode in environment File C:/Temp/web2py/applications/newcustomers/models/db.py http://10.11.58.41:8000/admin/default/edit/newcustomers/models/db.py, line 123, in module Field('active','integer')) File C:\Temp\web2py\gluon\dal.py, line 5097, in define_table polymodel=polymodel) File C:\Temp\web2py\gluon\dal.py, line 705, in create_table self.create_sequence_and_triggers(query,table) File C:\Temp\web2py\gluon\dal.py, line 1348, in create_sequence_and_triggers self.execute(query) File C:\Temp\web2py\gluon\dal.py, line 1359, in execute return self.log_execute(*a, **b) File C:\Temp\web2py\gluon\dal.py, line 1353, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: ('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Foreign key 'contacts_customer_id__constraint' references invalid table 'customers'. (1767) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create constraint. See previous errors. (1750)) On Thursday, March 22, 2012 3:03:26 PM UTC-7, Anthony wrote: I'll try adding the format to see if that helps. I was using 'database administration' so maybe it's not using a SQLFORM there. Yes, appadmin uses SQLFORM and should show the dropdown as well (but only if the referenced table has a format specified or you add the validator manually). I don't know what is going on... the dog and person tables work, but the customers and contacts tables do not. This is strange -- you can create the customers table by itself, add and query records, but if you then try to create the contacts table with a reference to customers, it gives you an error saying the customers table is invalid? I'm not sure what to make of that. Anthony
[web2py] Smarttable SQLFORM.grid
Are these two equivalents?? I remember using smartables at some point. What I liked about it was the search feature without having to press any button to search for my text within a table. Does SQLFORM.grid provides something similar?? Thanks d
[web2py] Re: featured web2py apps
I know pyMantis would need some clean up but it has some really nice an unique features http://pymantis.org/ source: https://sourceforge.net/scm/?type=hggroup_id=304012 On Thursday, September 22, 2011 8:52:05 PM UTC+2, Massimo Di Pierro wrote: I think we should make a list of featured web2py apps. Please post links below. - it does matter if you wrote or just saw it, just post below - the app must be open source - the app must be under version control and available - the app must use Auth - avoid duplicates, but if you saw in a previous thread, please post it here again List: - app name - app author - app description - where to get it - possibly a link to a screenshot - whether you think it is stable or not (why not?) Massimo
[web2py] Re: infinite loop with form.process().accepted
if form.process().accepted: i = form.vars.nmbreinvit invitsgenere = generate_invitation(i) Try: invitsgenere = generate_invitation(int(i)) In your form, the submitted value is stored as a string, and as a string it will always evaluate to i in your generate_invitation() function, which causes the infinite while loop. So, convert it to an integer before passing it to the function. You should probably also add the IS_INT_IN_RANGE validator to the input field. An alternative is to build the form using SQLFORM.factory with Field('nmbreinvit', 'integer'), and I believe in that case form.process() will convert the value to an integer for you, so you can then pass it directly to the generate_invitation() function. Anthony
[web2py] Re: creating relationship between two tables
Well, it appears to have been caused by me manually deleting the tables in the database, hoping that web2py will recreate them. Apparently, web2py does not know if the tables exist or not, and assumes that they do, since it has a log that it created the tables in the first place. That's why I get the error. It was assuming that my customers table was already created, and that assumption was incorrect. On Thursday, March 22, 2012 3:12:50 PM UTC-7, Derek wrote: Yeah, I know. Baffles me. Here's the traceback. I guess I'll go open an issue. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. Traceback (most recent call last): File C:\Temp\web2py\gluon\restricted.py, line 204, in restricted exec ccode in environment File C:/Temp/web2py/applications/newcustomers/models/db.py http://10.11.58.41:8000/admin/default/edit/newcustomers/models/db.py, line 123, in module Field('active','integer')) File C:\Temp\web2py\gluon\dal.py, line 5097, in define_table polymodel=polymodel) File C:\Temp\web2py\gluon\dal.py, line 705, in create_table self.create_sequence_and_triggers(query,table) File C:\Temp\web2py\gluon\dal.py, line 1348, in create_sequence_and_triggers self.execute(query) File C:\Temp\web2py\gluon\dal.py, line 1359, in execute return self.log_execute(*a, **b) File C:\Temp\web2py\gluon\dal.py, line 1353, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: ('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Foreign key 'contacts_customer_id__constraint' references invalid table 'customers'. (1767) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create constraint. See previous errors. (1750)) On Thursday, March 22, 2012 3:03:26 PM UTC-7, Anthony wrote: I'll try adding the format to see if that helps. I was using 'database administration' so maybe it's not using a SQLFORM there. Yes, appadmin uses SQLFORM and should show the dropdown as well (but only if the referenced table has a format specified or you add the validator manually). I don't know what is going on... the dog and person tables work, but the customers and contacts tables do not. This is strange -- you can create the customers table by itself, add and query records, but if you then try to create the contacts table with a reference to customers, it gives you an error saying the customers table is invalid? I'm not sure what to make of that. Anthony
[web2py] Re: Validating Registration fields
On Thursday, March 22, 2012 6:09:25 PM UTC-4, Peter G. wrote: I'm using the auth.settengs.extra_fields to add an extra upload field for the user to upload an avatar, how can I add an IS_IMAGE validator to the upload field so that the user can't upload random files? When you define the field, you can do: Field('avatar', 'upload', requires=IS_IMAGE()) or after the tables have been defined: db.auth_user.avatar.requires = IS_IMAGE() Also, how would I add an IS_ALPHANUMERIC to the built in First name and Last name form fields? Right now there are users registering with names like !@#$%^~ and some such... After the tables have been defined, you can do: db.auth_user.first_name.requires.append(IS_ALPHANUMERIC()) That adds the validator to the existing IS_NOT_EMPTY validator. However, I wouldn't use that validator for names because it doesn't allow valid name characters such as spaces, hyphens, and apostrophes. Anyway, if you prevent fake names with special characters, those users will just create fake names with alphanumeric characters, so either way you don't have a real name. Anthony
[web2py] Re: creating relationship between two tables
On Thursday, March 22, 2012 6:27:03 PM UTC-4, Derek wrote: Well, it appears to have been caused by me manually deleting the tables in the database, hoping that web2py will recreate them. Apparently, web2py does not know if the tables exist or not, and assumes that they do, since it has a log that it created the tables in the first place. That's why I get the error. It was assuming that my customers table was already created, and that assumption was incorrect. Yes, web2py stores metadata about the tables in the *.table files in the /databases folder of the application. You can use web2py to drop the table via db.mytable.drop(). If you delete the table manually, you might just be able to delete the associated *.table from the /databases folder to get web2py to re-create it (I'm not sure about that, though). Anthony
Re: [web2py] Re: Systems Management Web App for Ubuntu
Hi Stodge, Thank for your reply. The tool is somewhat designed to manage and provision cloud servers. However, the project encourages collaborative development at this moment rather than making use of it. Thanks again. On Thu, Mar 22, 2012 at 9:46 PM, Stodge sto...@gmail.com wrote: Does this share any functionality with: http://cloudsilverlining.org/ Cheers On Mar 22, 8:43 am, Eduardo Bergavera j...@dnsc.edu.ph wrote: Hi Everyone! I would like to ask some guidance regarding anyone who may be interested in developing web-based python app for systems management in Ubuntu. The web-app acts as centralized interface to manage cloud based or physical Ubuntu servers in one location. I'd like it to be developed using web2py framework. The system has features found in Ubuntu's proprietary systems management tool like Landscape --(http://www.canonical.com/enterprise-services/ubuntu-advantage/landsca...) a remote management tool for Ubuntu servers and desktops. The project combines some essential features of Webmin (webmin.com) and Landscape. System Requirements: * web2py based web app * manages Ubuntu desktop or servers thru a single interface * require registration of clients (desktop or servers) to be managed by the system * install, remove, upgrade packages, update history * Manage users (create, remove, change password) * View system info (cpu, ram, io) * email notification such as status of services, package updates * support common basic configurations * ability to explore filesystem * reboot, shutdown remote servers * log viewer (/var/log) Thank you for your help and guidance. -- Eduardo B. -- Eduardo D. Bergavera, Jr. Faculty | System Administrator Davao del Norte State College dnsc.edu.ph/~edbergavera
[web2py] Re: cross-domain auth
Thanks Anthony. If I visit mydomain1.com and mydomain2.com (both pointing to the same web2py app) from the same browser, will both get the exact same session id cookie?. Aside from CAS, is there any other way (web2py / javascript) that both domains share the same session cookie?. Thanks again. On Thursday, March 22, 2012 12:49:28 PM UTC-6, Anthony wrote: Have you looked into using CAS ( http://web2py.com/books/default/chapter/29/9#Central-Authentication-Servicehttp://web2py.com/books/default/chapter/29/9#Central-Authentication-Service )? On Thursday, March 22, 2012 2:16:42 PM UTC-4, Carlos wrote: Hi, I'm wondering if it's possible to have cross-domain auth in web2py (different domains pointing to the same web2py app and sharing the same cookie)?. I believe this is not possible because cookies (web2py's session cookie) can not be shared across domains, correct?. Or is there some kind of trick I can do to accomplish this?. Thanks! Carlos
[web2py] Re: Modules: how to access db
I just ran into this problem too and decided to solve it like this: in my controller: from gluon import current a_module = local_import('a_module') def a_function(): a_module.something_cool(auth, current) The db connection is available as auth.db, and the request, session, and response are in current. On Thursday, February 9, 2012 11:31:08 PM UTC+11, spyker wrote: I am not ready with this project to try out Bruno's way of setting up a database using modules and not models. But I want to be able to do something like this in a module: def number_or_records(table): count = db(db[table]).count() -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3)
[web2py] exceptions in modules
I have some modules that I've written, called from a Web2Py controller. I use this: class CustomException(Exception): def __init__(self, errno, strerror): self.errno = errno self.strerror = strerror def __str__(self): return repr(str(self.errno)+-+self.strerror) Down in my lowest module, I have this: from CustomException import CustomException class Invoices(object) def __init__(self,db,customer_id): self.db=db self.customer_id=customer_id self.rows =db(db.invoices.customer_id==self.customer_id) \ .select(orderby=~db.invoices.invoice_date) if None==self.rows: raise CustomException(1,No invoices found) if 0==len(self.rows): raise CustomException(2,No invoices found) self.current = 0 self.high=len(self.rows) So I expect that I can try/except this. Here's my code, with some syslog statements. I'll post the syslog output afterwards. syslog(str(CustomException)) try: rows=Invoices(db,self.customer_id) except CustomException.CustomException: rows=[] except: syslog( Unexpected error:+ str(sys.exc_info()[0])) raise Imagine my surprise when I wind up in the catchall except. Especially given these two syslog entries: Mar 22 23:00:41 admin01 httpd: module 'applications.gw.modules.CustomException' from 'applications/gw/ modules/CustomException.py' Mar 22 23:00:41 admin01 httpd: Unexpected error:class 'applications.gw.modules.CustomException.CustomException' The two classes match, yet I cannot catch the exception. I hope somebody can point out the error of my ways... Ed Greenberg
[web2py] Re: exceptions in modules
I have to point out that my line except CustomException.CustomException: was earlier just except CustomException: The first version was an attempt during testing, and was accidentally pasted into the message. I've also tried except CustomException as e: and except CustomException, (m,s): I just can't catch the durned thing. Ed
[web2py] Re: Smarttable SQLFORM.grid
I think you mean SQLFORM.smartgrid. Book's 7.8 section (the features are explained there): ... A SQLFORM.smartgrid looks a lot like a grid, in fact it contains a grid but it is designed to take as input not a query but only one table and to browse said table and selected referencing tables. ... On Mar 22, 7:16 pm, greenpoise danel.sega...@gmail.com wrote: Are these two equivalents?? I remember using smartables at some point. What I liked about it was the search feature without having to press any button to search for my text within a table. Does SQLFORM.grid provides something similar?? Thanks d
[web2py] Re: Smarttable SQLFORM.grid
Thanks..I thought I was in that chapter...Thanks again..will try the examples. d On Thursday, 22 March 2012 16:15:23 UTC-7, Alan Etkin wrote: I think you mean SQLFORM.smartgrid. Book's 7.8 section (the features are explained there): ... A SQLFORM.smartgrid looks a lot like a grid, in fact it contains a grid but it is designed to take as input not a query but only one table and to browse said table and selected referencing tables. ... On Mar 22, 7:16 pm, greenpoise danel.sega...@gmail.com wrote: Are these two equivalents?? I remember using smartables at some point. What I liked about it was the search feature without having to press any button to search for my text within a table. Does SQLFORM.grid provides something similar?? Thanks d
[web2py] Re: efficient DB queries
i use: ids = [...generate your list of ids...] rows = db(db.board.id.belongs(ids[0:30]).select() for i in range(30,len(ids), 30): rows db(db.board.id.belongs(ids[i:i+30]).select() so that gets me my in statement working with GAE's 30 items per in limit. On Wednesday, March 21, 2012 10:05:46 PM UTC-7, Udi Milo wrote: I went with: query = '' for id in board_ids: query += 'db(db.board.id==%d).select()|' %id query = query[:-1] boards = eval(query) I have no idea how to evaluate performance of that query though if you have any other ideas (I cannot limit 30 right now without rethinking other things), please share them. On Wednesday, March 21, 2012 11:52:33 PM UTC-4, Anthony wrote: I think that is outdated -- according to this ( https://groups.google.com/d/msg/web2py/vWqOET74qg4/92DLUFTUsN0Jhttps://groups.google.com/d/msg/web2py/vWqOET74qg4/92DLUFTUsN0J), GAE does now support belongs but is limited to 30 items per query (so you have to break it up). Perhaps there is a better way, though. Anthony On Wednesday, March 21, 2012 9:26:44 PM UTC-4, Udi Milo wrote: It doesn't. I found this: GAE does not support belongs and does not support OR. You have to do: rows = db(db.media_type.name=='paper').select()db (db.media_type.name=='cd').select() The is done at the web2py level but since records are exclusive and you are not sorting them, there is no major slowdown. Since I'm a python newbie, how would you go about building the loop that creates a very long query? you need to do some kind of python eval tricks here that I don't know. I'm guessing its going to look like for id in board_ids: query = query + new query(id) but how do you do it in python? On Wednesday, March 21, 2012 8:30:54 PM UTC-4, Anthony wrote: I didn't realize you were on GAE. I'm not quite sure how GAE handles this, so perhaps someone with more GAE experience can chime in. In an RDBMS, you should be able to do: board_ids = set([a.board for a in articles]) boards = db(db.boards.id.belongs(board_ids)).select() But not sure if that works on GAE. Anthony On Wednesday, March 21, 2012 7:30:58 PM UTC-4, Udi Milo wrote: Anthony, Thanks for answering so quickly. I did mean board and not board_id My question is very basic. I know that the article table has an Id column that is really the board reference, but when I look at the result of the query and unification of: board_ids = set(map(lambda a: a.board, articles)) I get a set of references, how do I use that set in another query to get all the boards? also, just to be sure, running this lambda expression does not hit the db to fetch the boards, right? I can't use join b/c I'm running on GAE. On Wednesday, March 21, 2012 5:22:50 PM UTC-4, Anthony wrote: I have two db tables: board (name, created_on) article(board, name, title) currently, in my html I do a naive loop {{for article in articles}} {{=article.board.name}} {{pass}} I would like to change it and do something like: articles = db.select.all... board_ids = set(map(lambda a: a.board_id, articles)) Instead of a.board_id, do you mean a.board (I don't see a board_id field listed in your article table definition)? Also, is db.article.board a reference field to the db.board table? In that case, that means it is already storing the id of the referenced record in the db.board table (that's what reference fields store), so you don't need to retrieve it separately. Anyway, if you need the db.board.name value for all the records you are selecting from the db.article table, you should probably just do a join so you can get everything in a single query -- see http://web2py.com/books/default/chapter/29/6#Inner-joinshttp://web2py.com/books/default/chapter/29/6#Inner-joins . Anthony
[web2py] Re: efficient DB queries
i use: ids = [...generate your list of ids...] rows = db(db.board.id.belongs(ids[0:30]).select() for i in range(30,len(ids), 30): rows db(db.board.id.belongs(ids[i:i+30]).select() so that gets me my in statement working with GAE's 30 items per in limit. According to the GAE docs, under the hood that still results in a separate datastore query for every id: http://code.google.com/appengine/docs/python/datastore/gqlreference.html. Anthony
[web2py] Re: cross-domain auth
I'm not sure if you can share a cookie across domains (though you can share across sub-domains). So, you have a single web2py app accessible via two different domains, and you want a given user to be logged into this single app but able to access it from either domain simultaneously? Can you explain the use case for that setup a little more? Anthony On Thursday, March 22, 2012 7:02:56 PM UTC-4, Carlos wrote: Thanks Anthony. If I visit mydomain1.com and mydomain2.com (both pointing to the same web2py app) from the same browser, will both get the exact same session id cookie?. Aside from CAS, is there any other way (web2py / javascript) that both domains share the same session cookie?. Thanks again. On Thursday, March 22, 2012 12:49:28 PM UTC-6, Anthony wrote: Have you looked into using CAS ( http://web2py.com/books/default/chapter/29/9#Central-Authentication-Servicehttp://web2py.com/books/default/chapter/29/9#Central-Authentication-Service )? On Thursday, March 22, 2012 2:16:42 PM UTC-4, Carlos wrote: Hi, I'm wondering if it's possible to have cross-domain auth in web2py (different domains pointing to the same web2py app and sharing the same cookie)?. I believe this is not possible because cookies (web2py's session cookie) can not be shared across domains, correct?. Or is there some kind of trick I can do to accomplish this?. Thanks! Carlos
[web2py] Re: cross-domain auth
Hi Anthony, In summary, I need to have single-sign-on access across multiple websites, each website optionally running with its own full domain (not sub-domain). A single web2py app is already taking care of everything, except the cross-domain session/auth. Thanks. On Thursday, March 22, 2012 6:57:33 PM UTC-6, Anthony wrote: I'm not sure if you can share a cookie across domains (though you can share across sub-domains). So, you have a single web2py app accessible via two different domains, and you want a given user to be logged into this single app but able to access it from either domain simultaneously? Can you explain the use case for that setup a little more? Anthony On Thursday, March 22, 2012 7:02:56 PM UTC-4, Carlos wrote: Thanks Anthony. If I visit mydomain1.com and mydomain2.com (both pointing to the same web2py app) from the same browser, will both get the exact same session id cookie?. Aside from CAS, is there any other way (web2py / javascript) that both domains share the same session cookie?. Thanks again. On Thursday, March 22, 2012 12:49:28 PM UTC-6, Anthony wrote: Have you looked into using CAS ( http://web2py.com/books/default/chapter/29/9#Central-Authentication-Servicehttp://web2py.com/books/default/chapter/29/9#Central-Authentication-Service )? On Thursday, March 22, 2012 2:16:42 PM UTC-4, Carlos wrote: Hi, I'm wondering if it's possible to have cross-domain auth in web2py (different domains pointing to the same web2py app and sharing the same cookie)?. I believe this is not possible because cookies (web2py's session cookie) can not be shared across domains, correct?. Or is there some kind of trick I can do to accomplish this?. Thanks! Carlos
[web2py] Re: auth.login() from inside a component in a dialog
@anothony: I'm not sure how to do the raise HTTP() and get it to execute the response.js. I looked in the doc but it's pretty thin on the subject. I'm going to look at the source to get an idea of how web2py does it (I've always been curious about this), but in the mean time, if you could shed some light as to how and where to do this, I would appreciate it much. Thanks. @pbreit: I don't know. Maybe my project is the 1% :-) It just seemed like the logical evolution of my site to collapse a lot of pages down to one page. My site is audio-centric, and there didn't seem to be a good reason to stop the audio just because the user wanted to login, which is what would have happened if I redirected to a login page while listening to audio. So modal login seemed the right way to go. But it definitely requires some contortions in web2py. It ain't over yet, but when I do get it figured out, I don't think it will be all that hard to implement.
[web2py] Re: cross-domain auth
In summary, I need to have single-sign-on access across multiple websites, each website optionally running with its own full domain (not sub-domain). A single web2py app is already taking care of everything, except the cross-domain session/auth. Got it. I'm just curious why it has to be a single app running multiple websites, yet the same user is logged in across all the websites? I can see having a single user needing to access multiple websites that are separate apps, or having different groups of users accessing different versions of a website driven by a single app, but this case seems unusual. Anthony
[web2py] Re: auth.login() from inside a component in a dialog
@anthony: actually, on closer inspection, the doc does go into some details: http://web2py.com/books/default/chapter/29/4#HTTP-and-redirect but I'm still experimenting with how to get it to execute a script.
Re: [web2py] Re: sqlite on production
developers themselves say 'dont use it for sites that have 100k hits/day I disagree, look here http://www.sqlite.org/whentouse.html Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic. and that was written even before WAL appeared you can't cluster sqlite you can use a clustered file system I think cloud based hostings have such FS e.g. Amazon S3 many assumptions that were true for sqlite are not valid since version 3.7 SQLite is an awesome product, it supports 1) concurrency http://www.sqlite.org/draft/wal.html 2) full text search http://www.sqlite.org/fts3.html with contributions from some google engineers 3) R-Trees for geospacial systems http://www.sqlite.org/rtree.html
[web2py] Re: auth.login() from inside a component in a dialog
Thank you Anthony. You're my hero. Wasn't so hard after all. For those following, I did it by putting the response.js in myonaccept(form) function and then, the last thing to do in that function is HTTP(303,SCRIPT(response.js)) That did the trick. @pbreit: After it's all said and done, I am more convinced than ever that modal login is the right thing for my website, making it considerably more user friendly.
[web2py] auth.login() from inside a component in a dialog [closed]
.
[web2py] Re: auth.login() from inside a component in a dialog
@anthony: actually, on closer inspection, the doc does go into some details: http://web2py.com/books/default/chapter/29/4#HTTP-and-redirecthttp://web2py.com/books/default/chapter/29/4#HTTP-and-redirect but I'm still experimenting with how to get it to execute a script. Something like: def myonaccept(form): [do stuff] response.js = 'some JS code' raise HTTP(200, response.render()) In that case, raise HTTP() will immediately return a response without proceeding through the remainder of auth.login() (thus avoiding the subsequent redirect). As long as the original request was made via an Ajax component, setting response.js before calling raise HTTP() will result in web2py adding the JS code as a response header before returning the response. Note, response.render() can take a view argument and a context argument (i.e., a dict) if needed. HTTP() can also take arbitrary keyword arguments, which will be converted to response headers. Anthony
[web2py] Re: auth.login() from inside a component in a dialog
Thank you Anthony. You're my hero. Wasn't so hard after all. For those following, I did it by putting the response.js in myonaccept(form) function and then, the last thing to do in that function is HTTP(303,SCRIPT(response.js)) Typically, a 303 response would also set a Location header to tell the browser where to redirect. In this case, you probably just want to return a 200 status code (or is it supposed to redirect somewhere?). Anthony
[web2py] Re: auth.login() from inside a component in a dialog
No, in fact it's not going anywhere in particular. I tried 200 then decided 303. Probably will return to 200. Thanks again. On Mar 23, 11:12 am, Anthony abasta...@gmail.com wrote: Thank you Anthony. You're my hero. Wasn't so hard after all. For those following, I did it by putting the response.js in myonaccept(form) function and then, the last thing to do in that function is HTTP(303,SCRIPT(response.js)) Typically, a 303 response would also set a Location header to tell the browser where to redirect. In this case, you probably just want to return a 200 status code (or is it supposed to redirect somewhere?). Anthony
[web2py] Re: cross-domain auth
I'm building a SaaS (Software as a Service) / cloud platform with multiple apps/services (websites being one of them). If you or anyone else can think of a solution to cross-domain cookies/auth, using the exact same sessions, please let me know. Thanks. On Thursday, March 22, 2012 8:28:35 PM UTC-6, Anthony wrote: In summary, I need to have single-sign-on access across multiple websites, each website optionally running with its own full domain (not sub-domain). A single web2py app is already taking care of everything, except the cross-domain session/auth. Got it. I'm just curious why it has to be a single app running multiple websites, yet the same user is logged in across all the websites? I can see having a single user needing to access multiple websites that are separate apps, or having different groups of users accessing different versions of a website driven by a single app, but this case seems unusual. Anthony
[web2py] Getting started in Web2py
Hi, I am developing a new project, new to python. Project is mainly for CRUD, display data on website, and easy management of back end. I started Djangobook and finished it, I felt like it was great and I could go in to eclipse, create my models, validate, and then make my forms on site..pretty simple (Although I am sure I am missing something). Then I came to find Web2py, initially, I am super stoked about it, however I can't seem to mesh with the documentation very well. Maybe I am missing something. I feel like djangobook held my hand and spoke about the main concepts of django, but in web2py, it jumps right into these super long pages , and don't really explain whats happening in the back. Also, I am running web2py on my machine, ubuntu, as well as another win7 machine. It feels sluggish. Anyone else experience this? Is this whe web based IDE causing it? Its difficult to switch through browser tabs / windows to make changes to things, validate errors, read the book..It just felt like django + eclipse + djangobook + terminalx was easier to manipulate. I could use terminal to quickly validate things and find errors, which djangobook explained thouroughly. I recently went on to IRC and was told to look at the Vimeo videos. The first one just jumped into features, and did not seem like a in depth tutorial. I really want to use Web2py, I think it will make my life easier when deploying apps, creating forms quickly, etc, but it just doesnt feel streamlined, I feel like alt tabbing and inputting code makes me wait longer than I had to in eclipse. I am having these weird issues getting it going. Anyone experience anything like this? Should I just push through it ?