Re: [web2py] Re: Self-joins not working.
Would the test include a test of the Wizard's ability to implement this? The error first surfaced there. -- Luc. On Friday, 30 November 2012 15:15:39 UTC, Richard wrote: Ask again when you are ready I have little app dedicated to check for this issue. Richard On Fri, Nov 30, 2012 at 10:10 AM, Massimo Di Pierro massimo@gmail.comjavascript: wrote: Correction. Not fixed. On Friday, November 30, 2012 9:10:30 AM UTC-6, Massimo Di Pierro wrote: Can you check trunk? I just submitted a patch that should have fixed this problem. The price: slower table initilization but perhaps negligible. On Friday, November 30, 2012 8:51:06 AM UTC-6, Richard wrote: I open an issue in the pass about that. http://code.google.com/p/**web2py/issues/detail?id=382http://code.google.com/p/web2py/issues/detail?id=382 Richard On Fri, Nov 30, 2012 at 8:50 AM, Anthony abas...@gmail.com wrote: The format argument goes in the define_table() call -- is that where you have it? Anthony On Friday, November 30, 2012 1:58:09 AM UTC-5, Luc Chase wrote: Thanks for the suggestion. I had tried something similar but got an error and even with this I have an error referencing to the unexpected use of 'format'. type 'exceptions.TypeError' __init__() got an unexpected keyword argument 'format' VERSION web2py™ (2, 2, 1, datetime.datetime(2012, 10, 21, 16, 57, 4), 'stable') PythonPython 2.7: C:\Program Files\Python\web2py_win\**web2py**\web2py.exe TRACEBACK 1. 2. 3. 4. 5. Traceback (most recent call last): File gluon/restricted.py, line 212, in restricted File C:/Program Files/Python/web2py_win/**web2py**/applications/Timesheet/**models**/db_wizard.py http://127.0.0.1:8000/admin/default/edit/Timesheet/models/db_wizard.py, line 40, in module TypeError: __init__() got an unexpected keyword argument 'format' ERROR SNAPSHOT [image: help] type 'exceptions.TypeError'(__**init**__() got an unexpected keyword argument 'format') On Thursday, 29 November 2012 02:08:58 UTC, Massimo Di Pierro wrote: The problem is that it cannot assign the default validator unless the table is defined. You can do db.define_table('t_project', Field('f_name', type='string', label=T('Name')), Field('f_parent_project', type='reference t_project', label=T('Parent Project')), format='%(f_name)s', migrate=settings.migrate) db.t_project.f_name.requires = IS_EMPTY_OR(IS_IN_DB(db,'t_**pro** ject.id http://t_project.id',format=db.t_**project._**format)) The last line will restore the dropdown. On Wednesday, 28 November 2012 14:39:14 UTC-6, Jim S wrote: I'm seeing this as well. -Jim On Tuesday, November 27, 2012 12:09:18 PM UTC-6, Luc Chase wrote: If the reference is to a different table, the CRUD form renders the field as a list box allowing the user to select the record from the foreign table. But as a self-join the CRUD form renders the field as a simple text box and it seems to create a default value of 0 when saved. Then, I think that causes the record to generate an error when viewed ( but not when edited). I can post the entire models file if that would help. -- -- --
[web2py] LOAD form deferred by jQuery UI tabs -- how to?
So I'm designing the world's greatest user interface and I happened on the idea of making my numerous SQLFORMs easier to navigate by using jQuery UI tabs and the load ajax feature. Conceptually, what I want to do should be simple. Load the form using =LOAD, but only when the tab is clicked on. When the user clicks on another tab, another SQLFORM is ajax-loaded, and so forth. Both jQuery UI and the web2py LOAD features work perfectly alone. I can even use the LOAD function with jQuery tabs as long as I don't try to use the beforeLoad event to load the form. I just can't figure out the javascript secret sauce to get them to play together. I'm really impressed by the power of the web2py LOAD function. The contributor really knew what he was doing! If I can just understand its underpinnings a little better I can use it for more than the simple case in the book. --
[web2py] Re: LOAD form deferred by jQuery UI tabs -- how to?
load calls web2py_component(), that is defined in web2py_ajax.js . Look at that if you're looking to an integration with your code. On Saturday, December 1, 2012 10:45:49 AM UTC+1, Joe Barnhart wrote: So I'm designing the world's greatest user interface and I happened on the idea of making my numerous SQLFORMs easier to navigate by using jQuery UI tabs and the load ajax feature. Conceptually, what I want to do should be simple. Load the form using =LOAD, but only when the tab is clicked on. When the user clicks on another tab, another SQLFORM is ajax-loaded, and so forth. Both jQuery UI and the web2py LOAD features work perfectly alone. I can even use the LOAD function with jQuery tabs as long as I don't try to use the beforeLoad event to load the form. I just can't figure out the javascript secret sauce to get them to play together. I'm really impressed by the power of the web2py LOAD function. The contributor really knew what he was doing! If I can just understand its underpinnings a little better I can use it for more than the simple case in the book. --
[web2py] Re: Hide form and erase input
I ended up putting them in separate divs and hiding the entire div. Works like a charm! Thanks guys On Thursday, November 29, 2012 4:44:50 PM UTC, Anthony wrote: The easiest way is probably via a custom form: http://web2py.com/books/default/chapter/29/07#Custom-forms. Another option -- each table row or div containing a field input has an id that starts with [tablename]_, so you could use a jQuery selector like: jQuery('[id^=tutor_]').hide() That will hide all table rows whose id's start with tutor_, which should be all the field inputs in the form. Anthony On Thursday, November 29, 2012 11:07:46 AM UTC-5, Daniele wrote: I could do that. Would I need to add the div directly in the controller or the view? My controller looks something like this now: def mypage(): form = SQLFORM(db.mytable) return dict(form=form) I guess there should be a way to edit the SQLFORM to add an extra div? Thanks guys On Thursday, November 29, 2012 3:50:25 PM UTC, Anthony wrote: Maybe you could put all the fields inside a div and then hide/show the whole div. Anthony On Thursday, November 29, 2012 7:45:22 AM UTC-5, Daniele wrote: Hmm, that gets rid of the input boxes but not of the fieldnames as well. I guess I'll have to do it manually for each field. On Thursday, November 29, 2012 9:40:29 AM UTC, Niphlod wrote: $(:input) ? On Thursday, November 29, 2012 2:29:46 AM UTC+1, Daniele wrote: Hello all :) I have a db.define_table that defines a particular role and all its fields. One of the fields is a boolean, which will display as a checkbox in the SQLFORM. What I'd like to do is hide ALL the elements in the SQLFORM if the radiobutton is unchecked, and show all the elements if it's checked. So I have something like this: script jQuery(document).ready(function(){ jQuery('#tutor_biography__row').hide(); jQuery('#tutor_is_tutor').change(function(){ if(jQuery('#tutor_is_tutor').attr('checked')) jQuery('#tutor_biography__row').show(); else jQuery('#tutor_biography__row').hide();}); }); /script What I'd like to do is not just hide one field, but hide all the fields if the radio button is unclicked. Is there a shortcut to do this or must I input all the rows manually? Also, another thing I'd like to add in the jQuery is, if the radio button was checked, filled out, and then unchecked, I want the values to not be stored but to be erased. I assume I'd have to add something like .val('') but I'm not sure where to do that. Thanks! --
[web2py] Re: How to make an admin session longer?
look at the first line of applications/admin/models/0.py :P On Saturday, December 1, 2012 1:28:52 AM UTC+1, Luca wrote: I am developing an app, and I find it annoying that I get so many communication error when I try to save after working on the code for some length of time. Is there a way for me to increase the timeout of the admin session, so that I don't get so many disconnections when I edit? Security is not a concern, since I am using admin mode only from localhost. Many thanks! Luca --
[web2py] Re: Proper way to reference logged user
Hmmm that's one option, but here's the problem. Basically, I want users to sign up very easily. So I'm just using web2py's default auth for that. Then, I'd like them to pick if they are tutors/students or both. There is additional information they'd have to input in some forms for both roles. While I could just create two groups, the way I have it now as tutors are a table and students are another table in the database. I guess I'm a bit lost as to how the correct way to let the signed up users be either students/tutors or both is. Should it all be part of the signed up users table? Or should I have three tables? Should I just make groups? Any advice is much appreciated, Thanks! On Friday, November 23, 2012 7:24:42 PM UTC, Joe Barnhart wrote: Why not create a group for each class -- tutor and student -- and assign group membership for each student? A student can participate in more than one group. It's easy to test for group membership -- just use the decorator: @auth.requires_membership('tutor') -- Joe B. On Tuesday, November 20, 2012 5:57:57 PM UTC-8, Daniele wrote: I am trying to build a model where each logged user can decide if he/she is a tutor or student or both. So the tutor table has to 'reference auth.settings.table_user_name' and student also has to have the same reference. The tutor/student/logged user have to be related by their id key I imagine. Is this the proper way to go about this? Moreover, how can I check that the relationship is working? --
[web2py] About crud.update to edit or update a user's profile info !
Hello web2py users, I am in the process of completing the edit profile option for the web app members and I am experiencing a particular problem that is causing me a headache ! in the profile controller, I am using the following function to update a user's profile : def editprofile(): table = db.auth_user form= crud.update(table,request.args(0)) return dict(form=form) and in the view, just to test this function, I am starting out with a simple view with no customization like : {{extend 'profile/userlayout.html'}} h4This is editprofile /h4 {{=form}} in db.auth_user there is the picture or avatar for the user among other fields First observation ) When a user updates his profile, all other fields gets updated ... except the picture field ! ??? Second ) the fields that used checkboxes as widgets when the user was registering on the site do not show as checked on the edit profile view ! So : the user's profile keeps the old picture and old thumbnail even after uploading a new one to replace the old the new picture uploaded does not even make it to the table nor to the upload folder ! ... however, I do get the message that the uploaded pic was re-sized but ... it is not there ! and I wish to have that same picture to show up on the edit profile page before the submit (update) button is pressed ! And why doesn't the checkboxes show their status or value when in edit profile view ? any assistance on this will be greatly appreciated ! thank you Don --
[web2py] Re: LOAD form deferred by jQuery UI tabs -- how to?
The LOAD helper simply generates HTML like the following: script type=text/javascript!-- web2py_component(/test/comment/post.load,c282718984176) //--/scriptdiv id=c282718984176loading.../div So, a div with a particular id is created, and the web2py_component() Javascript function (defined in /static/js/web2py.js) is called with the id of that div. Instead of using the LOAD helper, you can manually create a div and set up an event handler that calls web2py_component() when the tab is clicked. Anthony On Saturday, December 1, 2012 4:45:49 AM UTC-5, Joe Barnhart wrote: So I'm designing the world's greatest user interface and I happened on the idea of making my numerous SQLFORMs easier to navigate by using jQuery UI tabs and the load ajax feature. Conceptually, what I want to do should be simple. Load the form using =LOAD, but only when the tab is clicked on. When the user clicks on another tab, another SQLFORM is ajax-loaded, and so forth. Both jQuery UI and the web2py LOAD features work perfectly alone. I can even use the LOAD function with jQuery tabs as long as I don't try to use the beforeLoad event to load the form. I just can't figure out the javascript secret sauce to get them to play together. I'm really impressed by the power of the web2py LOAD function. The contributor really knew what he was doing! If I can just understand its underpinnings a little better I can use it for more than the simple case in the book. --
[web2py] Re: Transactions in Web2Py over Google App Engine.
I found this: https://developers.google.com/appengine/docs/python/datastore/overview#Cross_Group_Transactions For example, to increment a counter field in an object, you need to read the value of the counter, calculate the new value, and then store it back. Without a transaction, it is possible for another process to increment the counter between the time you read the value and the time you update it, causing your application to overwrite the updated value. Doing the read, calculation, and write in a single transaction ensures that no other process can interfere with the increment. On Friday, November 30, 2012 12:19:29 PM UTC-6, Joe Barnhart wrote: Think hard before locking a table while a user is dawdling over his reservation. The feature you are dealing with is database isolation levelhttp://en.wikipedia.org/wiki/Isolation_%28database_systems%29 and is the subject that fills volumes of database theory. From what you describe I think you want the repeatable read level. I do not know enough about GAE to tell you which levels it supports. But here is an article on Google BigTable Isolationhttps://developers.google.com/appengine/articles/transaction_isolationwhich may help. -- Joe B. On Thursday, November 29, 2012 2:18:47 AM UTC-8, José Manuel López Muñoz wrote: I'm making a room reservation system in Web2Py over Google App Engine. When a user is booking a Room the system must be sure that this room is really available and no one else have reserved it just a moment before. To be sure I make a query to see if the room is available, then I make the reservation. The problem is how can I do this transaction in a kind of Mutual exclusion to be sure that this room is really for this user? Thank you!! :) --
[web2py] multiple profile images
i'm interested in allowing users to upload multiple profile pictures stored as blobs. Obviously I need an intermediate table, images, to store the images but I'm unclear how to link it to the users table following http://stackoverflow.com/questions/6334360/web2py-how-should-i-display-an-uploaded-image-that-is-stored-in-a-database and still get an upload box on the user's profile page. i'm using auth.settings.extra_fields -- Jon Molesa rjmol...@gmail.com --
[web2py] Re: Proper way to reference logged user
Put everyone in the auth_user table and use groups. That could save you heaps of time down the line. Otherwise I can imagine you'll start reinventing what's already available to you in web2py. Use the framework and the force will be with you! If you need to keep lots of different info depending on what group they are in, then you can always think about splitting that into different tables, but only as a last resort. Best wishes for your app, D On Saturday, 1 December 2012 13:13:13 UTC, Daniele wrote: Hmmm that's one option, but here's the problem. Basically, I want users to sign up very easily. So I'm just using web2py's default auth for that. Then, I'd like them to pick if they are tutors/students or both. There is additional information they'd have to input in some forms for both roles. While I could just create two groups, the way I have it now as tutors are a table and students are another table in the database. I guess I'm a bit lost as to how the correct way to let the signed up users be either students/tutors or both is. Should it all be part of the signed up users table? Or should I have three tables? Should I just make groups? Any advice is much appreciated, Thanks! On Friday, November 23, 2012 7:24:42 PM UTC, Joe Barnhart wrote: Why not create a group for each class -- tutor and student -- and assign group membership for each student? A student can participate in more than one group. It's easy to test for group membership -- just use the decorator: @auth.requires_membership('tutor') -- Joe B. On Tuesday, November 20, 2012 5:57:57 PM UTC-8, Daniele wrote: I am trying to build a model where each logged user can decide if he/she is a tutor or student or both. So the tutor table has to 'reference auth.settings.table_user_name' and student also has to have the same reference. The tutor/student/logged user have to be related by their id key I imagine. Is this the proper way to go about this? Moreover, how can I check that the relationship is working? --
[web2py] Re: Upload directly to the server: error
You cannot do: open(...,'wb').write(form.vars.myfile.file.read()) because this read the entire file in memory before writing it. You need to use http://docs.python.org/2/library/shutil.html and do shutil.copyfileobj(form.vars.myfile.file, open(...,'wb')) Massimo On Friday, 30 November 2012 10:11:48 UTC-6, Paulo wrote: Hi! I'm trying to create a very simple upload field, without any complex mechanism. A user just uploads a file to a folder in the server (apache), without web2py changing the file name, and without any db. I have some dozens of files already in a folder in the server, I just need an upload form to send new files easly, without having to go personally with an Usb Pen to the server to copy new files. But I'm having an hard time doing it, and dont know why. With small files (2mb docx file) it works perfectly. But when uploading a 300mbs wav file it gives an error ticket: type 'exceptions.MemoryError' TRACEBACK 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. Traceback (most recent call last): File D:\web2py\gluon\restricted.py, line 212, in restricted exec ccode in environment File D:/web2py/applications/Upload_Fala_Bracarense/controllers/default.py https://cehum.ilch.uminho.pt/admin/default/edit/Upload_Fala_Bracarense/controllers/default.py, line 121, in module File D:\web2py\gluon\globals.py, line 188, in lambda self._caller = lambda f: f() File D:/web2py/applications/Upload_Fala_Bracarense/controllers/default.py https://cehum.ilch.uminho.pt/admin/default/edit/Upload_Fala_Bracarense/controllers/default.py, line 28, in index form = SQLFORM.factory(Field('myfile', 'upload', uploadfolder='/static')).process() File D:\web2py\gluon\html.py, line 2170, in process self.validate(**kwargs) File D:\web2py\gluon\html.py, line 2109, in validate if self.accepts(**kwargs): File D:\web2py\gluon\sqlhtml.py, line 1281, in accepts **kwargs File D:\web2py\gluon\html.py, line 2022, in accepts self._traverse(False, hideerror) File D:\web2py\gluon\html.py, line 842, in _traverse newstatus = c._traverse(status, hideerror) and newstatus File D:\web2py\gluon\html.py, line 842, in _traverse newstatus = c._traverse(status, hideerror) and newstatus File D:\web2py\gluon\html.py, line 842, in _traverse newstatus = c._traverse(status, hideerror) and newstatus File D:\web2py\gluon\html.py, line 842, in _traverse newstatus = c._traverse(status, hideerror) and newstatus File D:\web2py\gluon\html.py, line 853, in _traverse self._postprocessing() File D:\web2py\gluon\html.py, line 1762, in _postprocessing _value = str(self['_value']) File C:\Python27\Lib\cgi.py, line 515, in __repr__ self.name, self.filename, self.value) MemoryError IN FILE: D:\WEB2PY\APPLICATIONS\UPLOAD_FALA_BRACARENSE\CONTROLLERS/DEFAULT.PY I have tried a lot of diferent ways. I have read everything I could find in the web. I found a topic with the same problem but no solution I could use. Anyone can help with some tips? This the code in the controller: import os def index(): form = FORM(INPUT(_type='file',_name='myfile'),INPUT(_type='submit')) if form.accepts(request.vars,session): open(os.path.join(request.folder,'uploads','filename.wav'),'wb').write(form.vars.myfile.file.read()) return dict(form=form) I have tried a lot of different ways, this only an example. I used SQLFORM.factory {form = SQLFORM.factory(Field('myfile', 'upload', uploadfolder='/static')).process()}, shutil {shutil.copyfileobj(request.vars.myfile.file,open(os.path.join(request.folder,'static','filename.txt'),'wb'))}, and a lot of different code variants but none worked. Its allways the same: with small files it works, with a 200mb file it gives an error. Anyone can help me understand this problem? The max file size I need to upload is 500mb. It will be used by only one person, with a login, so there is no need to a complex mechanism, and files need to mantain the same name. I just need the upload to work. Thanks and sorry for my bad english. I want a user to be able to upload a file to a directory in the server (apache), without changing the file name, and wihout databases. A simple and direct upload, so a friend of mine can store some files in --
[web2py] Re: importing issues
Did you restart web2py/web server? On Friday, 30 November 2012 15:07:26 UTC-6, Maggs wrote: Hm, ok, that makes sense. However I have changed the name of the module within my app and restart web2py but I'm still getting the same error. Now the case is: site-packages/mymodule/a.py site-packages/mymodule/b.py applications/myapp/modules/c.py a.py imports b.py and is saying it does not have the attribute 'function'. I have tried explicitly naming the package.module within a.py (import mymodule.b.py as opposed to just import b.py) but that made no difference. On Friday, November 30, 2012 12:10:29 PM UTC-8, Massimo Di Pierro wrote: consider this case: site-packages/mymodule/a.py site-packages/mymodule/b.py applications/myapp/modules/b.py if myapp import mymodule.a and a.py import b this worked fine before but does not work in 2.2. This because the latest web2py has a custom import that always looks first in myapp/modules/ technically it is a bug in mymodule/a.py which should not import .b and not import b since the module does not know what is the path. On Friday, 30 November 2012 12:32:16 UTC-6, Maggs wrote: Yes and this is what I was curious about. I do have a utility module under myapp/modules/, however this cm module is calling it's own utility module completely outside of my app, so I don't understand how it could be getting them confused. This was never an issues in 1.99. I will try changing the name of the utility module inside my app and see if it helps though. Thanks! On Friday, November 30, 2012 6:37:41 AM UTC-8, Massimo Di Pierro wrote: Do you have anything under yourapp/modules/? On Thursday, 29 November 2012 17:30:30 UTC-6, Maggs wrote: I recently upgraded to web2py 2.2.1 from 1.99. I have an external set of modules that I am importing into my application. Since I updated to 2.2.1 I am getting errors saying that the module does not have the attribute 'function'. To explain further, I have an external set of modules under the folder cmweb. This folder is in my python path. I have from cmweb import cm at the top of my controller. Within the cm module, a module called utility is being imported. This module is also inside the cmweb folder. Now when I call functions from the cm module, I am getting an error saying that the utility module has no attribute 'function'. This was not happening before I upgraded to 2.2.1. Any ideas what might be happening here? Thanks in advance. --
[web2py] Re: About crud.update to edit or update a user's profile info !
I will look into this shortly anyway... having a picture in the auth_user table is a vulnerability. This is because the upload entry may appear upon registration allowing un-registered users to uploading large files. On Saturday, 1 December 2012 08:59:21 UTC-6, Don_X wrote: Hello web2py users, I am in the process of completing the edit profile option for the web app members and I am experiencing a particular problem that is causing me a headache ! in the profile controller, I am using the following function to update a user's profile : def editprofile(): table = db.auth_user form= crud.update(table,request.args(0)) return dict(form=form) and in the view, just to test this function, I am starting out with a simple view with no customization like : {{extend 'profile/userlayout.html'}} h4This is editprofile /h4 {{=form}} in db.auth_user there is the picture or avatar for the user among other fields First observation ) When a user updates his profile, all other fields gets updated ... except the picture field ! ??? Second ) the fields that used checkboxes as widgets when the user was registering on the site do not show as checked on the edit profile view ! So : the user's profile keeps the old picture and old thumbnail even after uploading a new one to replace the old the new picture uploaded does not even make it to the table nor to the upload folder ! ... however, I do get the message that the uploaded pic was re-sized but ... it is not there ! and I wish to have that same picture to show up on the edit profile page before the submit (update) button is pressed ! And why doesn't the checkboxes show their status or value when in edit profile view ? any assistance on this will be greatly appreciated ! thank you Don --
[web2py] Two components + two forms
Hello everybody, I'm struggling for a while with a problem. I have a page with two components. Each component contains a form. I embedded both the components with LOAD. Unfortunately when I submit one of the two forms, all the values are deleted and apparently there is no submission. If then I submit that form a second time, it seems to work. The problem is for sure related to the presence of two components, since if I embed just one of them everything works fine. Am I missing something? Cheers, David --
Re: [web2py] Re: About crud.update to edit or update a user's profile info !
thank you for the response Massimo, I do agree with your thoughts regarding the vulnerability exposed upon a new registration ! that can easily be arranged by adding an additional table to manage all users profile pics ! ... that way, a user can only upload his avatar ( or picture ) only when they are already registered and when they decide to edit their profile, they will be able to upload their own pic ... However, I still foresee the same problem, when it comes to edit that profile pic, with the crud.update for that eventual userimage table that will referenced the appropriate auth_user table record... I come to realize that there are many issues or challenges regarding pictures, uploading pictures, *viewing pictures upon uploads before submitting or updating a form (or crud)* etc .. throughout the web2py forum This is a matter that needs to be addressed head on, through a slice or a how to article, we know that it certainly involves ajax ... but many before me had experienced that problem and though out this web2py user forum, no effective solutions or how tos really stands out .. there is no solid approach to this ! .. if there is one, then I have not found it ! ...or if someone knows ... please point me in a that direction ! Can someone stand up take the time and share or write a good slice about this ! ... a lot of users will benefit from this ! .. the few slices that exist about file uploads and ajax are not well explained or outdated or simply do not work ! thank you Don --
Re: [web2py] Two components + two forms
Do the two components point to the same action, or do they contain forms with same formname? Either case that would not work because multiple forms in the same page must have different formnames? On Saturday, 1 December 2012 13:32:48 UTC-6, David Sorrentino wrote: Hello everybody, I'm struggling for a while with a problem. I have a page with two components. Each component contains a form. I embedded both the components with LOAD. Unfortunately when I submit one of the two forms, all the values are deleted and apparently there is no submission. If then I submit that form a second time, it seems to work. The problem is for sure related to the presence of two components, since if I embed just one of them everything works fine. Am I missing something? Cheers, David --
[web2py] Re: V 2.2.1 linked_tables broken in smartgrid?
Hi, I also removed db.table.column.readable = False to enable the column to be displayed in the smartgrid. However, when searching the linked column for a value in the smartgrid, an error is encountered : type 'exceptions.ValueError' invalid literal for int() with base 10: 'JHB' In this case, JHB was the value I searched for. Using its numeric ID worked and displayed the correct result. Will the fix in trunk also address this issue? Many thanks Rakesh --
[web2py] Re: SQLFORM.grid and classes on GAE
this seems to me like a bug in polymodel on GAE. my guess is that the proper implementation would be to have 2 tables, location_outdoor and location_indoor in the GAE database. does this seem correct to you? i can't guarantee my speed right now...but i can look into the DAL and see if i can find a problem with polymodel on GAE. can you file a ticket in google code as well so we don't forget? thanks! christian On Friday, November 30, 2012 2:27:21 PM UTC-8, Gian Luca Decurtins wrote: HI cfh You're right. As far as I can see in the datastore viewer there is only one table. There is also a class value available. I did try a few more things (resetting local datastore and removing the entries in index.yaml) but I'm not able to access all three tables using the following controller: @auth.requires_signature() def form(): table = request.args(0) if not table in db.tables(): redirect(URL('error')) db[table].id.readable = False form = SQLFORM.grid(db[table],args=request.args[:1], user_signature=True) return dict(form=form) When I do call http://localhost:8080/init/location/form/location_outdoor?_signature=xxx' I receive: AttributeError: 'location' object has no attribute 'country' When I call http://localhost:8080/init/location/form/location_indoor?_signature=xxx' I receive: AttributeError: 'location_outdoor' object has no attribute 'location_outdoor' Right after resetting the datastore I'm able to access 'location, 'location_outdoor' and 'location_indoor'. Once I create an indoor or outdoor location I'm not able to access the other form anymore. The 'location' form is still available. I'm trying to store all location information (outdoor / indoor) in one polymodel. I do want to take advantage of having to have only one reference between devices and locations. Any suggestions? Greetings -Luca. Am Donnerstag, 29. November 2012 19:27:03 UTC+1 schrieb howesc: i have not used polymodels so i can't answer the last question.but about that last one, when you access the GAE datastore viewer (as provided by GAE), what is the name of the table/model that is stored there? does it store location_indoor and location_outdoor, or just location with optional fields? (i'd personally expect the former, but your experience sounds like the latter). for your other questions see the example under this heading http://web2py.com/books/default/chapter/29/07?search=grid#SQLFORM.grid-and-SQLFORM.smartgrida few paragraphs in it shows a controller that can handle any table. cfh On Thursday, November 29, 2012 6:41:40 AM UTC-8, Gian Luca Decurtins wrote: Hi all Given the following model (polymodel location - location_outdoor location_indoor) on GAE: define_table('location', Field('name', 'string'), Field('active', 'boolean'), polymodel = True) define_table('location_outdoor', db.location, Field('country', 'string'), Field('city', 'string'), Field('postcode', 'string'), Field('street', 'string'), Field('building', 'string'), polymodel = db.location) define_table('location_indoor', db.location Field('location_outdoor', db.location_outdoor), Field('floor', 'string'), Field('room', 'string'), polymodel = db.location) - Is there a way to create a generic controller (using SQLFORM.grid) which is able to create outdoor or indoor locations (display either location_outdoor or location_indoor fields)? I'm thinking of a select field where I can select the class. Depending on the class it will show the available fields. I should be able to modify the SQLFORM.grid to get view and edit operations to use the correct class. But what about the create operation? - How can I add an extra field to the SQLFORM.grid view form which displays the location? I would like to add a field which does contain a generated QR-code. - Why are the indexes in index.yaml always called location and not location_outdoor and location_indoor? I'm often receiving the error message that location_indoor does not contain 'city', which is true. Cheers -Luca. --
[web2py] Re: V 2.2.1 linked_tables broken in smartgrid?
Probably not but I am not sure I understand the problem. Can you explain step by step how to reproduce this? On Saturday, 1 December 2012 16:07:57 UTC-6, Rakesh Singh wrote: Hi, I also removed db.table.column.readable = False to enable the column to be displayed in the smartgrid. However, when searching the linked column for a value in the smartgrid, an error is encountered : type 'exceptions.ValueError' invalid literal for int() with base 10: 'JHB' In this case, JHB was the value I searched for. Using its numeric ID worked and displayed the correct result. Will the fix in trunk also address this issue? Many thanks Rakesh --
[web2py] Re: Cannot import module 'lpod'
Strange this is ok dependent. On Tuesday, 27 November 2012 14:39:30 UTC-6, omicron wrote: And with CentOS 6.3 and his Python 2.6, this problem doesn't exist !!! Le jeudi 15 novembre 2012 12:24:16 UTC+1, omicron a écrit : I use an Ubuntu 12.04LTS, python 2.7 and web2py 2.2.1 lpod is installed in /usr/local/lib/python2.7/dist-packages, and it's an egg import lpod.document as oodoc - import error import lpod.document - import error import ldoc - no import error, but error document isn't found in lpod module And, I repeat, with python shell and web2py 1.99.7 it's ok (i make a new test this morning) And now, if i copy the lpod folder from the egg to : - web2py/site-packages folder - import error - web2py/applications/myapp/modules - it's ok !!! So i have a solution, but it's strange. Perhaps the lpod library is particular, because this code is ok inweb2py 2.2.1 : import dateutil.relativedelta as rd Le mercredi 14 novembre 2012 15:26:28 UTC+1, Massimo Di Pierro a écrit : Moreover. Where is lpod? How was it installed? On Wednesday, 14 November 2012 08:26:09 UTC-6, Massimo Di Pierro wrote: Does it work if you simply do: import lpod.document ? On Tuesday, 13 November 2012 04:37:43 UTC-6, omicron wrote: With web2py 1.99.7 this import was Ok : import lpod.document as oodoc But with version 2.2.1, I have this error : File /home/myhome/Applications/web2py/gluon/custom_import.py, line 77, in custom_importer raise ImportError, 'Cannot import module %s' % str(e) ImportError: Cannot import module 'lpod' But if I replace with this: import lpod It's ok !!! And, of course, in a python shell it's ok. Thanks --
[web2py] small typo in Book: Caching with Redis
http://www.web2py.com/books/default/chapter/29/13#Caching-with-Redis _cache missing in the module name: from gluon.contrib.redis*_cache* import RedisCache cache.redis = RedisCache('localhost:6379',db=None, debug=True) Best regards --
[web2py] Re: Hide form and erase input
Just curious... did you end up using a completely custom form or were you able to manipulate the SQLFORM inside the controller? On Saturday, December 1, 2012 7:03:33 AM UTC-6, Daniele wrote: I ended up putting them in separate divs and hiding the entire div. Works like a charm! Thanks guys On Thursday, November 29, 2012 4:44:50 PM UTC, Anthony wrote: The easiest way is probably via a custom form: http://web2py.com/books/default/chapter/29/07#Custom-forms. Another option -- each table row or div containing a field input has an id that starts with [tablename]_, so you could use a jQuery selector like: jQuery('[id^=tutor_]').hide() That will hide all table rows whose id's start with tutor_, which should be all the field inputs in the form. Anthony On Thursday, November 29, 2012 11:07:46 AM UTC-5, Daniele wrote: I could do that. Would I need to add the div directly in the controller or the view? My controller looks something like this now: def mypage(): form = SQLFORM(db.mytable) return dict(form=form) I guess there should be a way to edit the SQLFORM to add an extra div? Thanks guys On Thursday, November 29, 2012 3:50:25 PM UTC, Anthony wrote: Maybe you could put all the fields inside a div and then hide/show the whole div. Anthony On Thursday, November 29, 2012 7:45:22 AM UTC-5, Daniele wrote: Hmm, that gets rid of the input boxes but not of the fieldnames as well. I guess I'll have to do it manually for each field. On Thursday, November 29, 2012 9:40:29 AM UTC, Niphlod wrote: $(:input) ? On Thursday, November 29, 2012 2:29:46 AM UTC+1, Daniele wrote: Hello all :) I have a db.define_table that defines a particular role and all its fields. One of the fields is a boolean, which will display as a checkbox in the SQLFORM. What I'd like to do is hide ALL the elements in the SQLFORM if the radiobutton is unchecked, and show all the elements if it's checked. So I have something like this: script jQuery(document).ready(function(){ jQuery('#tutor_biography__row').hide(); jQuery('#tutor_is_tutor').change(function(){ if(jQuery('#tutor_is_tutor').attr('checked')) jQuery('#tutor_biography__row').show(); else jQuery('#tutor_biography__row').hide();}); }); /script What I'd like to do is not just hide one field, but hide all the fields if the radio button is unclicked. Is there a shortcut to do this or must I input all the rows manually? Also, another thing I'd like to add in the jQuery is, if the radio button was checked, filled out, and then unchecked, I want the values to not be stored but to be erased. I assume I'd have to add something like .val('') but I'm not sure where to do that. Thanks! --
[web2py] cron job not running at all
I am trying to get the basic cron job to run on a new web2py application but amnot having any success. I read about starting web2py with the -Y option I am running on ubuntu and using the native web2py server I have a db.commit() in the controller function the function runs perfectly when i run thru the browser. I have modified the application crontab file (see below) #crontab */10 * * * * root*tagme/tagme.py I think this should cause the controller function to run every 10 minutes. I also am not 100% familiar with cron and am unsure how and where i can see if it is throwing any errors. any advice would be appreciated. --
[web2py] Re: getting access to sqlform.grid forms in a view
You are right. As usual. Thanks. --
[web2py] Re: MARKMIN line break
I am trying these: td class=span8{{=(row.body1)+ \n\n +(row.body2)}}/td td class=span8{{=(row.body1)+ ' \n\n '+(row.body2)}}/td td class=span8{{=(row.body1)+ [[NEWLINE]] +(row.body2)}}/td td class=span8{{=(row.body1)+ '[[NEWLINE]]' +(row.body2)}}/td and they are not working. What am i missing? Regards, Ashraf --
[web2py] Re: MARKMIN line break
On Saturday, 1 December 2012 21:43:22 UTC-6, apps in tables wrote: I am trying these: td class=span8{{=(row.body1)+ \n\n +(row.body2)}}/td td class=span8{{=(row.body1)+ ' \n\n '+(row.body2)}}/td td class=span8{{=(row.body1)+ [[NEWLINE]] +(row.body2)}}/td td class=span8{{=(row.body1)+ '[[NEWLINE]]' +(row.body2)}}/td and they are not working. What am i missing? Regards, Ashraf --
[web2py] Why does 'group' field cause web2py to stall?
I'm editing my data model in db.py and trying to add a field to a table of accounts that groups them using a foreign key. Field('group', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), causes a ticket that reads: and causes web2py to freeze (must force quit and reopen); however, Field('groupd', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), works fine. Can someone explain why this is? Also, is there a better/more elegant way to specify a default for 'reference' types? Basically I want the default to be the first entry in the 'groups' table (which is a generic 'ungrouped' group). Thank you for any help, I'm a web2py noob coming from a PHP/MySQL background. --
[web2py] Re: MARKMIN line break
You are missing that you need to generate html br/ and {{=anything}} always escape anything. You want: td class=span8{{=(row.body1)}}br/{{=(row.body2)}}/td or td class=span8{{=CAT(row.body1,BR(),row.body2)}}/td or td class=span8{{=CAT(row.body1,XML('br/'),row.body2)}}/td or td class=span8{{=XML(row.body1+'br/'+row.body2, sanitize=True)}}/td The latter is not quite the same as the others as it allows some HTML in the row.body1/2. On Saturday, 1 December 2012 21:43:22 UTC-6, apps in tables wrote: I am trying these: td class=span8{{=(row.body1)+ \n\n +(row.body2)}}/td td class=span8{{=(row.body1)+ ' \n\n '+(row.body2)}}/td td class=span8{{=(row.body1)+ [[NEWLINE]] +(row.body2)}}/td td class=span8{{=(row.body1)+ '[[NEWLINE]]' +(row.body2)}}/td and they are not working. What am i missing? Regards, Ashraf --
Re: [web2py] Re: web3py?
Interesting development. This seems to address the common criticisms of web2py, which aren't an issue for me but surely deter others. On Friday, November 30, 2012 3:51:20 AM UTC+11, LightDot wrote: Some valid and interesting questions can get unanswered, slip below the radar, that's bound to happen everywhere. I have a feeling that web2py community is very active when compared to some others, taking the number of members into account. It would be interesting to put some numbers behind this and prove one way or another, but alas, I don't really have the time... :/ My personal observations are that unanswered questions are often either a) accompanied by complex, long examples of code, which many readers don't have time to decipher; b) answered many times before or so general, that they aren't web2py specific at all (ie. general css or html questions); c) very specific, with sparse information about the problem itself (such as individual web server configurations, etc.). I might be wrong though, as I naturally don't read everything... Regards, Ales On Thu, Nov 29, 2012 at 3:25 PM, Jim S j...@qlf.com javascript: wrote: +1 to what Peter said. On Thursday, November 29, 2012 4:06:30 AM UTC-6, peter wrote: In my experience, and what I have seen from following the threads, the norm is for questions to be answered very well and very quickly. One of the many pleasures of using Web2py is the responsiveness of the users group. There might be the odd exception to this, but this is unusual I believe. So sorry if you had a bad exprience Daniele, but I do not think most users find this. Peter On Thursday, 29 November 2012 01:14:52 UTC, Daniele wrote: I really believe web2py will indeed become the rails for python as someone mentioned. Actually, I believe it's much better, easier to use and comprehend, and more pleasant to develop in. That said, I agree web2py needs to reach a critical mass of users because as of now, it's too hard to get the support to even simple answers, which sometime require days to be answered on google groups. A much wider user base would rapidly solve this problem quite naturally. I think the solution to this would be word of mouth: more users need to use web2py and spread the word of how good it is by mere word of mouth. It's possible, I believe the project can really outshine all the other python web frameworks. On Tuesday, November 27, 2012 4:39:06 AM UTC, User wrote: I noticed a thread over in web2py-developers web3py - important! which was exciting to read. I've flirted with web2py and there's a lot that I like about it. For some reason I find web2py exciting whereas django doesn't provide that. I've used Yii on the php side which is great framework as far as php goes and asp.net mvc which is great as well. I'd love to work with python but the main thing making me hesitate with web2py is critical mass. It seems like it wouldn't be hard for web2py to really dominate the python web framework space if some of the core criticisms were addressed. I'm not fully up to speed on what they are but I usually hear about unit testing and global variables. It feels like there is a roadblock preventing the project from skyrocketing. Python needs a rails. I understand that the design decisions are by choice with pros and cons. My questions are: 1. Will web3py likely address these often repeated core criticisms? (I saw point 5 from the thread linked to above: 5) No more global environment. Apps will do from web3py import * (see below)) 2. The developer thread is over in the developers section. Will you have a more open forum for users (as opposed to developers) to have input on web3py? -- --
[web2py] Bug when rendering nested dictionaries as JSON? -- depends on specific values of keys
I've found a strange behavior in 1.99.7 (which is the same in 2.2.1 except for a code cleanup issue). This is either a bug or I'm confused (don't rule that out). This is a long message -- I thought it was important to include a detailed demo of the phenomenon. The idea of generic views is wonderful -- a controller function can return a dict; and based on the extension used to request the page, data is returned using the formatting logic of the generic view of that type. This works well and is demonstrated clearly in section 10.1.1 of the book. A simple example: In default.py def test(): return dict(status='200 OK') Then from a unix command line $ curl -L 'http://localhost:8000/default/test.load' 200 OK $ curl -L 'http://localhost:8000/default/test.xml' ?xml version=1.0 encoding=UTF-8?documentstatus200 OK/status/ document $ curl -L 'http://localhost:8000/default/test.json' { status: 200 OK } ## note in JSON, I made a change in gluon / serializers.py to add indents So far so good. But something bad happens when the dictionary is nested: In updated default.py def test(): return dict(response=dict(status='200 OK')) requesting ...test.json creates an error file in my app/err folder Traceback (most recent call last): File /Users/chris/dev/hsmaster/web2py_v1.99.7/gluon/main.py, line 508, in wsgibase serve_controller(request, response, session) File /Users/chris/dev/hsmaster/web2py_v1.99.7/gluon/main.py, line 207, in serve_controller run_view_in(response._view_environment) File /Users/chris/dev/hsmaster/web2py_v1.99.7/gluon/compileapp.py, line 596, in run_view_in badv = \'invalid view (%s)\' % response.view AttributeError: \'dict\' object has no attribute \'view\' Observations The book says Any dictionary can be rendered in HTML, XML and JSON as long as it only contains python primitive types (int, float, string, list, tuple, dictionary). so this seems in-bounds. json.dumps (serializer users) has no problem with nested dicts. This may be a clue -- if we service-enable the same function and call differently ... @service.json def test(): return dict(response=dict(status='200 OK')) ... the result is fine ... $ curl -L 'http://localhost:8000/default/call/json/test' { response: { status: 200 OK } } or if we don't service-enable it, call like we did the first time, but change the name of the top-level key like this: def test(): return dict(blahblah=dict(status='200 OK')) ... the result is fine too ... $ curl -L 'http://localhost:8000/default/test.json' { blahblah: { status: 200 OK } } Conclusion After a long Wingare debugging session, I think this code is the proximate cause of the problem: in gluon / main.py / serve_controller(): ... page = run_controller_in(request.controller, request.function,environment ) if isinstance(page, dict): response._vars = page for key in page: response._view_environment[key] = page[key] ### AAA run_view_in(response._view_environment) page = response.body.getvalue() ... Basically it appears that the line marked AAA overwrites data in the response._view_environment structure with data from the dict the test() function returns. The problem only happens when a key in the top level (not nested) of the dict matches an existing key in response._view_environment. response._view_environment has 129 keys: A B BEAUTIFY ... auth cache crud ... response request service etc.) and when one of these is in common with the dict being rendered, the value of dict[key] overwrites it. The traceback above was from gluon / compileapp.py / run_view_in() -- that relies on response._view_environment['response'] to have a key 'view', which is present before line AAA; but gone after -- response._view_environment['response'] has been clobbered. Remediation In my debugging, I changed line AAA to be a pass statement and nothing bad happened. I don't know if that is the right approach or not. The same little block of code I showed above (from main.py) also occurs twice in compileapp.py. I don't know enough to judge whether eliminating line AAA as I did is a good idea or not; or if it should be done in some or all of the three location. Request Can someone say if my solution is on the right track; and why the dict is being merged with the response? Maybe the right approach for a different payload -- but dicts can't avoid using these keys. view, title, status, db -- these are pretty common keys. Best regards and thanks -- --
Re: [web2py] Why does 'group' field cause web2py to stall?
try DAL(..., check_reserved=['all']) You cannot name a field group it is a SQL reserved keyword. Bruno Rocha http://rochacbruno.com.br mobile Em 02/12/2012 02:46, David Tucker dmtuc...@ucsc.edu escreveu: I'm editing my data model in db.py and trying to add a field to a table of accounts that groups them using a foreign key. Field('group', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), causes a ticket that reads: and causes web2py to freeze (must force quit and reopen); however, Field('groupd', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), works fine. Can someone explain why this is? Also, is there a better/more elegant way to specify a default for 'reference' types? Basically I want the default to be the first entry in the 'groups' table (which is a generic 'ungrouped' group). Thank you for any help, I'm a web2py noob coming from a PHP/MySQL background. -- --
[web2py] Re: Why does 'group' field cause web2py to stall?
That name is probably a reserved word in the database engine you're using. Every DBMS has a list of words that are off-limits for use as object (table, field, index, function etc.) names. GROUP is a pretty common one because of the GROUP BY operation. Take a look at gluon / reserved_sql_keywords.py for a list per DBMS. If you care about DBMS portability, a good practice is to instantiate your DAL object with option check_reserved='all' -- this will prevent you from using table / field / etc. names that conflict with your current DBMS or a future one you may move to someday (one of the reasons I really like web2py -- have moved between 4 DBMSs with no code changes!) Regards -- On Saturday, December 1, 2012 5:01:17 PM UTC-5, David Tucker wrote: I'm editing my data model in db.py and trying to add a field to a table of accounts that groups them using a foreign key. Field('group', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), causes a ticket that reads: and causes web2py to freeze (must force quit and reopen); however, Field('groupd', 'reference groups', ondelete='CASCADE', required=True, default=db(db.groups).select().first().id), works fine. Can someone explain why this is? Also, is there a better/more elegant way to specify a default for 'reference' types? Basically I want the default to be the first entry in the 'groups' table (which is a generic 'ungrouped' group). Thank you for any help, I'm a web2py noob coming from a PHP/MySQL background. --