[web2py] Re: How to create object of 'Storage' In class I created?
Thanks , It works :) On Thursday, July 10, 2014 1:00:30 PM UTC+3, Niphlod wrote: from gluon.storage import Storage mydict = dict(a=1,b=1) print mydict['a'] print mydict.a -- exception mydict = Storage(mydict) print mydict['a'] print mydict.a -- no exception On Thursday, July 10, 2014 4:23:41 AM UTC+2, Omri Levy wrote: Hi , I have created a class (that i put in models folder), and all it methods returns complicated dictionaries. When I try to access these variables like Storage (foo.bar) I get the following exception: 'dict' object has no attribute I thought that all dictionaries are being converted automatically into Storage, but i guess they don't. I've tried to wrap the return value with Storage constructor but then I get an exception saying that there is no such thing as Storage. Can someone please enlighten me? Thanks , Omri. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] How to create object of 'Storage' In class I created?
Hi , I have created a class (that i put in models folder), and all it methods returns complicated dictionaries. When I try to access these variables like Storage (foo.bar) I get the following exception: 'dict' object has no attribute I thought that all dictionaries are being converted automatically into Storage, but i guess they don't. I've tried to wrap the return value with Storage constructor but then I get an exception saying that there is no such thing as Storage. Can someone please enlighten me? Thanks , Omri. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Debug Web2py with Wing IDE
Hi , I asked Wing support the following question: I am using Web2py framework. I saw a video that says the Wing can debug a running python code no matter if it launched it itself. When reading this: http://wingware.com/doc/howtos/web2py I see that I can only debug Web2py in a way that I need to rerun the server from Wing for each time I hit 'Debug'. Is there any better way to do it? *They replied:* *This is our recommended approach because of the difficulties reloading code in Python. Does web2py have code reloading? It's been some time since I worked with it. Or does it have a master process that spawns a new sub process when things change? django and some other frameworks work this way.* Do someone know what is the answer to these two questions? Thanks! -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: A way to trigger method on update?
Thank you! :) On Thursday, June 26, 2014 12:25:00 AM UTC+3, 黄祥 wrote: afaik, compute didn't work on update. for onupdate, is execute on form level not on dal, please take a look at book chapter about that. ref: http://web2py.com/books/default/chapter/29/07/forms-and-validators best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: A way to trigger method on update?
Yes. I have read ALL the DAL section from the manual and I think you are right. I just wonder if I could use the 'compute' or 'filter in' function as well. I never heard of form 'on update'. Is it web2py feature? Thanks! :) On Wednesday, June 25, 2014 9:58:41 AM UTC+3, 黄祥 wrote: i think you can achieve it using before and after update callback (handle in dal), another way is using onupdate (handle in form) best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] A way to trigger method on update?
Hi, Is there a way to call a method when certain field is updated? The intention is *not* to change the value of the field/represent it otherwise, but it has general purpose. Thanks! Omri. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Ticket in Appadmin when viewing a table
Hi Massimo , Thank you very much! Error still happens. I think it's corrupt data in DB, because when removing the DB and repeating the same actions it's OK. Thanks , On Friday, June 20, 2014 6:04:34 AM UTC+3, Massimo Di Pierro wrote: Download this: https://github.com/web2py/web2py/archive/master.zip Unzip it and copy web2py over the old one. On Thursday, 19 June 2014 17:28:41 UTC-5, Omri Levy wrote: Hi Massimo, Thanks , I experience this bug a lot, I think it's when I update list of references to the same table in the db. Can you please explain how to update? (do I need Git?) / Manually fix it? Thanks again , Omri. On Friday, June 20, 2014 1:17:08 AM UTC+3, Massimo Di Pierro wrote: think it is a bug. pushing a new version that should fix that. Check trunk in 5 minutes. On Monday, 16 June 2014 09:17:01 UTC-5, Omri Levy wrote: type 'exceptions.TypeError' sequence item 0: expected string, long foundVersionweb2py™Version 2.9.5-stable+timestamp.2014.03.16.02.35.39 PythonPython 2.7.6: C:\Python27\python.exe (prefix: C:\Python27) Traceback 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Traceback (most recent call last): File G:\Dropbox\Coding Projects\web2py\gluon\restricted.py, line 220, in restricted exec ccode in environment File G:/Dropbox/Coding Projects/web2py/applications/goals/views/appadmin.html http://192.168.1.14:8000/admin/default/edit/goals/views/appadmin.html, line 183, in module h4{{=T(DISK)}}/h4 File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 3049, in __init__ r = represent(field, r or [], record) File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 59, in represent return f(value) File G:\Dropbox\Coding Projects\web2py\gluon\dal.py, line 7252, in list_ref_repr return (refs and ', '.join(f(r,x.id) for x in refs) or '') TypeError: sequence item 0: expected string, long found -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Thank you Anthony! This works :) Thank you too Carlos On Monday, June 16, 2014 4:33:05 PM UTC+3, Anthony wrote: If you want to dynamically add a component in the browser, you cannot use the LOAD helper, which is a Python helper that is serialized on the server. Instead, use the $.web2py.component() Javascript function. Something like: input type=button value=Edit onclick=$.web2py.component('{{=URL(' default', 'edit_page.load')}}', 'edit-form'); div id=edit-form/div Anthony On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: Hi , So I have a ticket system, and I want to allow user to edit the ticket without leaving the page. I don't want to LOAD the edit_page and hide it, but only load it once user is clicking on the ticket body. Another thing is, when user edits the ticket, he should again see changes on the same page. Is this possible? I'm a bit confused, because LOAD works fine, but not when using conditions with JS. Thanks. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Ticket in Appadmin when viewing a table
type 'exceptions.TypeError' sequence item 0: expected string, long found Versionweb2py™Version 2.9.5-stable+timestamp.2014.03.16.02.35.39PythonPython 2.7.6: C:\Python27\python.exe (prefix: C:\Python27)Traceback 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Traceback (most recent call last): File G:\Dropbox\Coding Projects\web2py\gluon\restricted.py, line 220, in restricted exec ccode in environment File G:/Dropbox/Coding Projects/web2py/applications/goals/views/appadmin.html http://192.168.1.14:8000/admin/default/edit/goals/views/appadmin.html, line 183, in module h4{{=T(DISK)}}/h4 File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 3049, in __init__ r = represent(field, r or [], record) File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 59, in represent return f(value) File G:\Dropbox\Coding Projects\web2py\gluon\dal.py, line 7252, in list_ref_repr return (refs and ', '.join(f(r,x.id) for x in refs) or '') TypeError: sequence item 0: expected string, long found -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Ticket in Appadmin when viewing a table
Hi Massimo, Thanks , I experience this bug a lot, I think it's when I update list of references to the same table in the db. Can you please explain how to update? (do I need Git?) / Manually fix it? Thanks again , Omri. On Friday, June 20, 2014 1:17:08 AM UTC+3, Massimo Di Pierro wrote: think it is a bug. pushing a new version that should fix that. Check trunk in 5 minutes. On Monday, 16 June 2014 09:17:01 UTC-5, Omri Levy wrote: type 'exceptions.TypeError' sequence item 0: expected string, long found Versionweb2py™Version 2.9.5-stable+timestamp.2014.03.16.02.35.39PythonPython 2.7.6: C:\Python27\python.exe (prefix: C:\Python27)Traceback 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Traceback (most recent call last): File G:\Dropbox\Coding Projects\web2py\gluon\restricted.py, line 220, in restricted exec ccode in environment File G:/Dropbox/Coding Projects/web2py/applications/goals/views/appadmin.html http://192.168.1.14:8000/admin/default/edit/goals/views/appadmin.html, line 183, in module h4{{=T(DISK)}}/h4 File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 3049, in __init__ r = represent(field, r or [], record) File G:\Dropbox\Coding Projects\web2py\gluon\sqlhtml.py, line 59, in represent return f(value) File G:\Dropbox\Coding Projects\web2py\gluon\dal.py, line 7252, in list_ref_repr return (refs and ', '.join(f(r,x.id) for x in refs) or '') TypeError: sequence item 0: expected string, long found -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Trying to use the LOAD helper, if a button is clicked
Hi , So I have a ticket system, and I want to allow user to edit the ticket without leaving the page. I don't want to LOAD the edit_page and hide it, but only load it once user is clicking on the ticket body. Another thing is, when user edits the ticket, he should again see changes on the same page. Is this possible? I'm a bit confused, because LOAD works fine, but not when using conditions with JS. Thanks. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Adding information to certain input before added to db?
When using SQLFORM, is it possible to check for certain input and change it before it is being stored in db? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Can I change a value from a form before it is processed?
Hi , So the situation is this: I have table for posts - Only the user posted a message may see it and then table for shared_posts - The user created a post may enter user_ids here, and those users may also see the post I don't want to add record for each share, so shared posts is defined like this: db.define_table('shared_goals', Field('goal','reference posts',readable=False,writable=False,requires=IS_NOT_EMPTY()), Field('user_id','list:reference auth_user'), auth.signature) Notice that user_id is a list. When I produce a form (with given id, so it is actually an edit form), it shows user_id as a list of all the people registered. I don't want this. people should not see who else is registered. So, In the view I wrote this: {{=shared_goals_form.custom.begin}} {{=INPUT(_name=user_id,_id=shared_goals_user_id)}} {{=shared_goals_form.custom.submit}} {{=shared_goals_form.custom.end}} And then, after being processed, the list in DB only contains one user_id (latest). The question is: Can I change the value of user_id input after submission and before the process, so that it will include previous user_ids? Thanks! Omri. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Speeding up the admin interface
Hi dear list, I am using web2py mainly as a JSON-RPC server and gateway to the database. As a client I use qooxdoo with asynchronous json-rpc calls to communicate between the two. I currently have in my database 74 tables, and expect the number to grow a bit in the future. I mainly use two files, the models file to define the tables and controllers/default.py to handle all the traffic. This file is ~4300 lines long. My problem is that when I try to access the admin interface, usually to use the database admin, it takes a really long time to load, and actually also sometimes hangs. In addition to what I described above, I have the qooxdoo application in the static directory, along with the framework since I need to do the development while the server is running. When I deploy the app, the qooxdoo framework won't be needed anymore (it will be 'compiled' to one minified js file). Do you have any suggestions as to how to speed up the admin interface? Or, for that matter, the server response time which is sometimes quite long? Thanks, Omri Har-Shemesh --
Re: [web2py] Re: Suggestion - a pickled DAL field
Hi Derek, thanks! the as_dict method has already been fixed in trunk to handle my use-case. best wishes, Omri On Sat, Aug 11, 2012 at 12:26 AM, Derek sp1d...@gmail.com wrote: You could monkey patch it in 0.py in models, perhaps. On Thursday, July 26, 2012 1:10:43 AM UTC-7, Omri Har-Shemesh wrote: I use the pickled field to store a dictionary. Since dictionary is not defined as a serializable type for the as_dict function, it is not returned when calling to as_dict. Adding it (dal.py line 6183) solved my problem, but I would like to keep this change when I update my web2py next. Is there a different way (without changing the dal) to achieve this? Could you add it to the dal.py? Is it without risks? Thanks, Omri On Thu, Jul 26, 2012 at 9:46 AM, Omri omr...@gmail.com wrote: So I tried it out, and it works great, except for one thing - when I try to use record.as_dict() to get the structure which I can return to a JSON-RPC call which I normally use to communicate with my client, it simply does not return the field. I tried to print it out and I see very clearly that as long as it is a Row object there is no problem, but as soon as I run .as_dict() it disappears. My definitions are as follows: from gluon.dal import SQLCustomType pickled = SQLCustomType( type = 'text', native = 'text', encoder = (lambda x: pickle.dumps(x)), decoder = (lambda x: pickle.loads(x)) ) then I use db.define_table(my_table, Field(pickled_field, type=pickled) ) but when I fetch the record it does not go to as_dict() (actually I use as_list() but both don't work). Any suggestions? Is there a way to teach as_dict to interpret this field type? Best wishes, Omri On Wed, Jul 25, 2012 at 9:20 PM, howesc how...@umich.edu wrote: For what it is worth i have used custom fields for this type of thing with great success! On Tuesday, July 24, 2012 8:20:03 AM UTC-7, Anthony wrote: You could use a SQLCustomType field: http://web2py.com/**books** /default/chapter/29/6#**Custom-**Field-types-(**experimental)http://web2py.com/books/default/chapter/29/6#Custom-Field-types-%28experimental%29 . Anthony On Tuesday, July 24, 2012 8:34:07 AM UTC-4, Omri Har-Shemesh wrote: Hi web2pyers, very often, I have a field in the table which has to hold a complicated value (most often numpy arrays). The way I implement it is that I use text as the type of field, and then simply pickle.dumps(my_value) when I save the field, and then pickle.loads(value_from_db) to access the field again. My suggestion is simple - create field that automatically pickles the values it gets and unpickles them on extraction. Is this already implemented? Do you have other suggestions on how to implement this so that I won't need to pickle every time I access the table? Best wishes, Omri -- -- --
[web2py] Re: Add dict to SERIALIZABLE_TYPES in Row object's as_dict method
It seems to have been already done by Anthony, thanks for the quick fix! :) Omri On Friday, July 27, 2012 4:33:34 PM UTC+2, Massimo Di Pierro wrote: Send me a patch and I will take a look. It is probably safe. On Friday, 27 July 2012 06:30:54 UTC-5, Omri Har-Shemesh wrote: I recently defined a pickled SQLCustomType field for automatic dumping/loading of inserted types to the field. The definition is: pickled = SQLCustomType( type = 'text', native = 'text', encoder = (lambda x: pickle.dumps(x)), decoder = (lambda x: pickle.loads(x)) ) I use it to store a dictionary of values, which I later retrieve and send to the client via an jsonrpc service. For this to work, I need to call the as_dict() method of the Row object I obtained from the database. The problem is that dict is not recognized as a serializable by the as_dict method. Is it safe to simply add it to the list of values already defined there? Is there a different way of letting the Row object know how to decode the value? Is there a way to do it so that next time when I update web2py it will stay defined? Thanks! Omri --
[web2py] Add dict to SERIALIZABLE_TYPES in Row object's as_dict method
I recently defined a pickled SQLCustomType field for automatic dumping/loading of inserted types to the field. The definition is: pickled = SQLCustomType( type = 'text', native = 'text', encoder = (lambda x: pickle.dumps(x)), decoder = (lambda x: pickle.loads(x)) ) I use it to store a dictionary of values, which I later retrieve and send to the client via an jsonrpc service. For this to work, I need to call the as_dict() method of the Row object I obtained from the database. The problem is that dict is not recognized as a serializable by the as_dict method. Is it safe to simply add it to the list of values already defined there? Is there a different way of letting the Row object know how to decode the value? Is there a way to do it so that next time when I update web2py it will stay defined? Thanks! Omri --
Re: [web2py] Re: Suggestion - a pickled DAL field
So I tried it out, and it works great, except for one thing - when I try to use record.as_dict() to get the structure which I can return to a JSON-RPC call which I normally use to communicate with my client, it simply does not return the field. I tried to print it out and I see very clearly that as long as it is a Row object there is no problem, but as soon as I run .as_dict() it disappears. My definitions are as follows: from gluon.dal import SQLCustomType pickled = SQLCustomType( type = 'text', native = 'text', encoder = (lambda x: pickle.dumps(x)), decoder = (lambda x: pickle.loads(x)) ) then I use db.define_table(my_table, Field(pickled_field, type=pickled) ) but when I fetch the record it does not go to as_dict() (actually I use as_list() but both don't work). Any suggestions? Is there a way to teach as_dict to interpret this field type? Best wishes, Omri On Wed, Jul 25, 2012 at 9:20 PM, howesc how...@umich.edu wrote: For what it is worth i have used custom fields for this type of thing with great success! On Tuesday, July 24, 2012 8:20:03 AM UTC-7, Anthony wrote: You could use a SQLCustomType field: http://web2py.com/** books/default/chapter/29/6#**Custom-Field-types-(**experimental)http://web2py.com/books/default/chapter/29/6#Custom-Field-types-%28experimental%29 . Anthony On Tuesday, July 24, 2012 8:34:07 AM UTC-4, Omri Har-Shemesh wrote: Hi web2pyers, very often, I have a field in the table which has to hold a complicated value (most often numpy arrays). The way I implement it is that I use text as the type of field, and then simply pickle.dumps(my_value) when I save the field, and then pickle.loads(value_from_db) to access the field again. My suggestion is simple - create field that automatically pickles the values it gets and unpickles them on extraction. Is this already implemented? Do you have other suggestions on how to implement this so that I won't need to pickle every time I access the table? Best wishes, Omri -- --
Re: [web2py] Re: Suggestion - a pickled DAL field
I use the pickled field to store a dictionary. Since dictionary is not defined as a serializable type for the as_dict function, it is not returned when calling to as_dict. Adding it (dal.py line 6183) solved my problem, but I would like to keep this change when I update my web2py next. Is there a different way (without changing the dal) to achieve this? Could you add it to the dal.py? Is it without risks? Thanks, Omri On Thu, Jul 26, 2012 at 9:46 AM, Omri omri...@gmail.com wrote: So I tried it out, and it works great, except for one thing - when I try to use record.as_dict() to get the structure which I can return to a JSON-RPC call which I normally use to communicate with my client, it simply does not return the field. I tried to print it out and I see very clearly that as long as it is a Row object there is no problem, but as soon as I run .as_dict() it disappears. My definitions are as follows: from gluon.dal import SQLCustomType pickled = SQLCustomType( type = 'text', native = 'text', encoder = (lambda x: pickle.dumps(x)), decoder = (lambda x: pickle.loads(x)) ) then I use db.define_table(my_table, Field(pickled_field, type=pickled) ) but when I fetch the record it does not go to as_dict() (actually I use as_list() but both don't work). Any suggestions? Is there a way to teach as_dict to interpret this field type? Best wishes, Omri On Wed, Jul 25, 2012 at 9:20 PM, howesc how...@umich.edu wrote: For what it is worth i have used custom fields for this type of thing with great success! On Tuesday, July 24, 2012 8:20:03 AM UTC-7, Anthony wrote: You could use a SQLCustomType field: http://web2py.com/** books/default/chapter/29/6#**Custom-Field-types-(**experimental)http://web2py.com/books/default/chapter/29/6#Custom-Field-types-%28experimental%29 . Anthony On Tuesday, July 24, 2012 8:34:07 AM UTC-4, Omri Har-Shemesh wrote: Hi web2pyers, very often, I have a field in the table which has to hold a complicated value (most often numpy arrays). The way I implement it is that I use text as the type of field, and then simply pickle.dumps(my_value) when I save the field, and then pickle.loads(value_from_db) to access the field again. My suggestion is simple - create field that automatically pickles the values it gets and unpickles them on extraction. Is this already implemented? Do you have other suggestions on how to implement this so that I won't need to pickle every time I access the table? Best wishes, Omri -- --
[web2py] Re: Suggestion - a pickled DAL field
Thanks! I will try it out :) On Wednesday, July 25, 2012 3:55:39 AM UTC+2, Anthony wrote: On Tuesday, July 24, 2012 5:58:29 PM UTC-4, Derek wrote: Make it a computed field? I'm not sure that would be helpful in this case. A computed field computes its value automatically based on other fields in the record, but in this case, he needs to pickle an object, which is not one of the other fields. Also, it needs to be unpickled when queried, which a computed field wouldn't handle. Anthony --
[web2py] Suggestion - a pickled DAL field
Hi web2pyers, very often, I have a field in the table which has to hold a complicated value (most often numpy arrays). The way I implement it is that I use text as the type of field, and then simply pickle.dumps(my_value) when I save the field, and then pickle.loads(value_from_db) to access the field again. My suggestion is simple - create field that automatically pickles the values it gets and unpickles them on extraction. Is this already implemented? Do you have other suggestions on how to implement this so that I won't need to pickle every time I access the table? Best wishes, Omri --
[web2py] Re: Watching a table for changes
Thanks for all your help! Now I understand web2py a little better :-) Since I do not want to add to each insert the appending of the function - I simply added it after creating the table in the model, and now it works well since it is being executed together with the model code. Are there good reasons not to do it? Since I use web2py mainly as a back-end to JSON-RPC calls and gateway to the database, my application is basically built out of a huge default controller and a huge model file. I don't think I would know where to put it otherwise. Best wishes, Omri On Monday, June 11, 2012 6:25:15 PM UTC+2, Anthony wrote: Model (i.e., DAL Table) definitions do not survive across requests -- during a request, you define the table, and then you use the table object to access the db, etc. In your workflow, you are adding the _after_insert function in one request (i.e., the RPC request) but doing the insert in a separate request. This is not how web2py works -- you have to add the _after_insert function in the same request as the insert. More generally, keep in mind that your application code is executed on each request -- whatever you define in a given request is specific to that request and does not persist to subsequent requests (unless, of course, you explicitly store it in the cache, session, db, filesystem, etc.). Anthony On Monday, June 11, 2012 11:56:36 AM UTC-4, Omri Har-Shemesh wrote: In order to attach the function, I have a function which is being called through JSON-RPC, and looks like this: @service.jsonrpc def append_listeners(): print db.comments._after_insert # prints [] db.comments._after_insert.append(MyFunction) print db.comments._after_insert # prints [function MyFunction at 0xabfb8df4] No matter how many times I call this function, the print statements stay the same (except for the address of the function MyFunction). I modified the insert function in dal.py for debugging: def insert(self, **fields): print _after_insert array: , self._after_insert # prints _after_insert array: [] print table name: , self._tablename # prints table name: comments self._attempt_upload(fields) if any(f(fields) for f in self._before_insert): return 0 ret = self._db._adapter.insert(self,self._listify(fields)) ret and [f(fields,ret) for f in self._after_insert] return ret and indeed, when I insert something to the comments table, I get two lines printed out as shown in the comments text. It seems that the additional function is not saved in the table object. Am I doing something fundamentally wrong? Should I add the function from the model file? Or at any other place? Thanks, Omri On Monday, June 11, 2012 5:33:53 PM UTC+2, Anthony wrote: I tried adding a method using: def SomeMethod(fields,res): print inside SomeMethod db.my_table._after_insert.append(SomeMethod) but nothing seems to happen. Is it possible that the implementation of the adapters does not call the methods inside _after_insert, _after_update and _after_delete? I would think it should work. Have you also defined any _before_insert functions -- if they return anything, the insert will be aborted? Also, are you sure the insert is happening -- if not, the _after_insert functions won't run. You may need to show more code. Anthony
[web2py] Re: Watching a table for changes
Hi Anthony, thanks for the reply! I have been looking at the code and there is something I don't really understand (sorry for a noob question): when the functions get called, they are called using a pattern: ret = ... ret and [f(fields,ret) for f in self._after_insert] return ret The question is - should the function I define return something? Is the result of the function call used somehow, somewhere? I suspect that using ret and [] is simply in order to invoke the functions, but then I don't understand why not use something like [f(fields,ret) for f in self._after_insert] without using the and operator. Best wishes, Omri On Wednesday, June 6, 2012 3:44:46 PM UTC+2, Anthony wrote: In trunk, there are now triggers for DAL tables: self._before_insert = [] self._before_update = [lambda self,fs:self.delete_uploaded_files( fs)] self._before_delete = [lambda self:self.delete_uploaded_files()] self._after_insert = [] self._after_update = [] self._after_delete = [] You could define a function that stores a timestamp in the cache and add it to the three _after_ triggers for the relevant tables. Then just check the timestamp to see if it is more recent than the last request. To determine the time of the last request, you could store a timestamp in the session upon each request (so it will be specific to each user). Anthony On Wednesday, June 6, 2012 5:30:56 AM UTC-4, Omri Har-Shemesh wrote: Is it possible to watch a table for changes and define a callback whenever the table is changed? I am trying to implement a mechanism where the client is asking for data every 5 seconds from the server and the server should only return not a null value whenever the data has changed. The problem is that the data is quite complex and is inferred from several tables. Therefore, in order to save processing time, I want to calculate this data and return it only when I know it has changed. Thanks, Omri
[web2py] Re: Watching a table for changes
Hi Again, I tried adding a method using: def SomeMethod(fields,res): print inside SomeMethod db.my_table._after_insert.append(SomeMethod) but nothing seems to happen. Is it possible that the implementation of the adapters does not call the methods inside _after_insert, _after_update and _after_delete? Best wishes, Omri On Monday, June 11, 2012 3:06:35 PM UTC+2, Omri Har-Shemesh wrote: Hi Anthony, thanks for the reply! I have been looking at the code and there is something I don't really understand (sorry for a noob question): when the functions get called, they are called using a pattern: ret = ... ret and [f(fields,ret) for f in self._after_insert] return ret The question is - should the function I define return something? Is the result of the function call used somehow, somewhere? I suspect that using ret and [] is simply in order to invoke the functions, but then I don't understand why not use something like [f(fields,ret) for f in self._after_insert] without using the and operator. Best wishes, Omri On Wednesday, June 6, 2012 3:44:46 PM UTC+2, Anthony wrote: In trunk, there are now triggers for DAL tables: self._before_insert = [] self._before_update = [lambda self,fs:self.delete_uploaded_files( fs)] self._before_delete = [lambda self:self.delete_uploaded_files()] self._after_insert = [] self._after_update = [] self._after_delete = [] You could define a function that stores a timestamp in the cache and add it to the three _after_ triggers for the relevant tables. Then just check the timestamp to see if it is more recent than the last request. To determine the time of the last request, you could store a timestamp in the session upon each request (so it will be specific to each user). Anthony On Wednesday, June 6, 2012 5:30:56 AM UTC-4, Omri Har-Shemesh wrote: Is it possible to watch a table for changes and define a callback whenever the table is changed? I am trying to implement a mechanism where the client is asking for data every 5 seconds from the server and the server should only return not a null value whenever the data has changed. The problem is that the data is quite complex and is inferred from several tables. Therefore, in order to save processing time, I want to calculate this data and return it only when I know it has changed. Thanks, Omri
[web2py] Re: Watching a table for changes
In order to attach the function, I have a function which is being called through JSON-RPC, and looks like this: @service.jsonrpc def append_listeners(): print db.comments._after_insert # prints [] db.comments._after_insert.append(MyFunction) print db.comments._after_insert # prints [function MyFunction at 0xabfb8df4] No matter how many times I call this function, the print statements stay the same (except for the address of the function MyFunction). I modified the insert function in dal.py for debugging: def insert(self, **fields): print _after_insert array: , self._after_insert # prints _after_insert array: [] print table name: , self._tablename # prints table name: comments self._attempt_upload(fields) if any(f(fields) for f in self._before_insert): return 0 ret = self._db._adapter.insert(self,self._listify(fields)) ret and [f(fields,ret) for f in self._after_insert] return ret and indeed, when I insert something to the comments table, I get two lines printed out as shown in the comments text. It seems that the additional function is not saved in the table object. Am I doing something fundamentally wrong? Should I add the function from the model file? Or at any other place? Thanks, Omri On Monday, June 11, 2012 5:33:53 PM UTC+2, Anthony wrote: I tried adding a method using: def SomeMethod(fields,res): print inside SomeMethod db.my_table._after_insert.append(SomeMethod) but nothing seems to happen. Is it possible that the implementation of the adapters does not call the methods inside _after_insert, _after_update and _after_delete? I would think it should work. Have you also defined any _before_insert functions -- if they return anything, the insert will be aborted? Also, are you sure the insert is happening -- if not, the _after_insert functions won't run. You may need to show more code. Anthony
[web2py] Watching a table for changes
Is it possible to watch a table for changes and define a callback whenever the table is changed? I am trying to implement a mechanism where the client is asking for data every 5 seconds from the server and the server should only return not a null value whenever the data has changed. The problem is that the data is quite complex and is inferred from several tables. Therefore, in order to save processing time, I want to calculate this data and return it only when I know it has changed. Thanks, Omri
[web2py] db.table.insert() inserts a field with id=None but returns an id number
Hi, I suddenly came across a weird bug, where when I add a record to a specific table (it doesn't happen with other tables), it inserts the record with the id field == null, but returns a number as if it is the id. Furthermore, the number returned is close to (but not exactly) the number of records in the table (it is a little bigger than the number of rows in the table). The thing is that the highest id field in the table (which was obviously inserted prior to the bug) is 219, while the new ids generated are around 70, and the number of records in the table is 65. I am using web2py 1.99.7 dev with pysqlite2. Any advice as to how to debug this will be greatly appreciated!
[web2py] Re: db.table.insert() inserts a field with id=None but returns an id number
Additional information: after going through my revision history, it seems that the problem started after I changed the type of a field from string (didn't notice I forgot to define it as integer and therefore it defaulted to string, even though the default=0 was specified). Then, since sqlite doesn't really allow you to change the type of a column, I used Sqliteman to do that (it was critical to change the field type). What sqliteman does is essentially drop the table and recreate it with the new definitions. I'm suspecting that web2py is unhappy about this. Is there a way to make web2py happy again? I'm guessing that now the table's definition as it really is, is different from what web2py expects. Any help would be greatly appreciated! Omri On Wednesday, May 9, 2012 11:14:57 AM UTC+2, Omri Har-Shemesh wrote: Hi, I suddenly came across a weird bug, where when I add a record to a specific table (it doesn't happen with other tables), it inserts the record with the id field == null, but returns a number as if it is the id. Furthermore, the number returned is close to (but not exactly) the number of records in the table (it is a little bigger than the number of rows in the table). The thing is that the highest id field in the table (which was obviously inserted prior to the bug) is 219, while the new ids generated are around 70, and the number of records in the table is 65. I am using web2py 1.99.7 dev with pysqlite2. Any advice as to how to debug this will be greatly appreciated!
[web2py] Re: db.table.insert() inserts a field with id=None but returns an id number
Sorry for the frequent e-mails. I just solved the problem - I forgot to set the type of the ID field to INTEGER PRIMARY KEY AUTOINCREMENT, since Sqliteman does not show it as an option. Best, Omri On Wednesday, May 9, 2012 12:15:31 PM UTC+2, Omri Har-Shemesh wrote: Additional information: after going through my revision history, it seems that the problem started after I changed the type of a field from string (didn't notice I forgot to define it as integer and therefore it defaulted to string, even though the default=0 was specified). Then, since sqlite doesn't really allow you to change the type of a column, I used Sqliteman to do that (it was critical to change the field type). What sqliteman does is essentially drop the table and recreate it with the new definitions. I'm suspecting that web2py is unhappy about this. Is there a way to make web2py happy again? I'm guessing that now the table's definition as it really is, is different from what web2py expects. Any help would be greatly appreciated! Omri On Wednesday, May 9, 2012 11:14:57 AM UTC+2, Omri Har-Shemesh wrote: Hi, I suddenly came across a weird bug, where when I add a record to a specific table (it doesn't happen with other tables), it inserts the record with the id field == null, but returns a number as if it is the id. Furthermore, the number returned is close to (but not exactly) the number of records in the table (it is a little bigger than the number of rows in the table). The thing is that the highest id field in the table (which was obviously inserted prior to the bug) is 219, while the new ids generated are around 70, and the number of records in the table is 65. I am using web2py 1.99.7 dev with pysqlite2. Any advice as to how to debug this will be greatly appreciated!
[web2py] Sharing application across development machines - what files to synchronize from databases directory
Hey List, I am developing a database application with web2py as the server back-end, and a client application in qooxdoo, which interacts with the server through JSON-RPC. I use Mercurial as my VCS and synchronize the code from qooxdoo, the code from the controller and the code of the model (I do not use any views since it is handled by qooxdoo) using Mercurial to Bitbucket. I also added the database (SQLite) file to the repository so that I can develop on more than one machine. I do not synchronize the web2py code and the qooxdoo framework code because it will make the repository bloated and I don't really need to do that. My question is the following - which files should I synchronize in order to use the database in more than one computer? Tables are being continuously added and changed. I tried synchronizing only the database file, but then the application complained about the structure of the tables in the database. To solve it, I deleted everything from the databases directory, let web2py rebuild the files and then replaced the storage.sqlite file with the one from the repository. Is there a better way to do that? Should I add to the repository all the files from the databases directory? And a different question which occurred to me - is there a way to tell web2py to clear the database before deployment, or should I simply delete everything from the 'databases' directory and let it rebuild the tables? Thanks, Omri
[web2py] Re: Using regular expressions in DAL queries
I do not know, but I did some internet research and found the following: *PostgreSQL*: supports POSIX style regexps, described to great detail in: http://www.postgresql.org/docs/9.0/static/functions-matching.html *MySQL*: supports a style which is aimed at conformance with POSIX 1003.2, described here: http://dev.mysql.com/doc/refman/5.1/en/regexp.html *Oracle*: supports IEEE Portable Operating System Interface (POSIX) standard draft 1003.2/D11.2, described: http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm *MSSQL*: not sure, I think you probably need to define a function on your own using CLR language (?). *FireBird*: Support RegExp, but didn't specify according to which syntax exactly. Details: http://www.firebirdsql.org/rlsnotesh/rlsnotes25.html#rnfb25-dml-regex *DB2*: Need to implement a function that does it, details: http://www.ibm.com/developerworks/data/library/techarticle/0301stolze/0301stolze.html *Informix, Ingres*: Not sure, wasn't able to find something definitive, but probably need to extend the language to support regexps. In addition I found the following article of someone who explored the regexp support of popular SQL databases: http://trentrichardson.com/2008/10/23/exploring-various-sql-regex-syntax/ All in all, seems that most systems support some version of POSIX standard, except when you need to extend the SQL with a user defined function, then I guess you can chose the implementation you want. Hope this help, Omri
[web2py] Re: Using regular expressions in DAL queries
Hi Massimo, I already opened an issuehttp://code.google.com/p/web2py/issues/detail?id=678at Google code, its link is in my second e-mail in this discussion. I will add there a link to this discussion. Best, Omri
[web2py] Using regular expressions in DAL queries
Hi All, I have been wondering if there is somewhere a hidden method of using regexps in queries. I found this discussionhttps://groups.google.com/d/topic/web2py/-XnMx24to8s/discussion on the mailing list, where a way to do it was suggested and it was said there that this will be added to web2py. However, upon looking at the current code (version 1.99.2) I did not find the implementation suggested there. Is there a reason why this was not implemented or why this is not a good solution? I don't mind patching the code myself but I'm not sure how this will affect the automatic updates of the framework, and I don't want it in a future version to be overwritten. Thanks! Omri
[web2py] Re: Using regular expressions in DAL queries
I opened an issue: http://code.google.com/p/web2py/issues/detail?id=678 Thanks for finding out how this should be done, I don't mind helping nagging about it ;-) Best, Omri
[web2py] Re: regexp in like expressions
Hi, I have been looking for this option in the DAL and came across this discussion, however it seems that this is no longer defined in the dal.py I have (version 1.99.2). Has this option been dropped again? Is it possible to achieve this behavior in a different way? I looked through the book but didn't find any mention of this in the DAL chapter. Cheers, Omri
[web2py] (Very) small improvement suggestion
Hi All, I have an extremely small suggestion to make life a tiny bit easier - in the beginning when starting web2py using python web2py.py there appears a dialog box. In the dialog box, the password field has a binding on the 'Return' to start the server when the return key is pressed. I suggest adding a similar binding to the port field (and maybe IP field as well), since usually the focus is on the password field I fill it in first, and since I need a different port and change it next and it will be very helpful if it automatically opens the window after a return press. the only change necessary is in the gluon.widget, around line 214 one has to add: self.port_number.bind('Return', lambda e: self.start()) and maybe around line 202 the same for the ip field. Thanks, Omri
[web2py] importing gluon to a module in the modules directory
Hello, I'm writing a module to contain some class definitions I need for my application's business logic and I would like to access gluon from my module. I placed my module inside the modules directory and import it using local_import. I want to have the classes in the module access the database (which I managed by passing the db DAL instance to the classe's constructor), but I would like to be able to check that the expected DAL object is transferred during construction of the object. To that end I would like to write something like: if isinstance(db, gluon.dal.DAL) or just if isinstance(db,DAL). I have tried to import web2py in the usual way (import web2py) - and it raised an exception - TclError: image pyimage2 doesn't exist. and opened a white triangular window without any borders that will not go away unless I close the web2py application. It does the same when I try to import only web2py.gluon.dal. I'm running on Ubuntu 10.10 with web2py version 1.94.6. Thanks, Omri
[web2py] Re: importing gluon to a module in the modules directory
This is stable - I only use the stable version and frequently update using the Update link.
[web2py] Re: importing gluon to a module in the modules directory
I thought I tried it before, but apparently I didn't, or I changed something because this way seems to work. It also works if I use import gluon.dal and check for gluon.dal.DAL. Sorry to have bothered you, but beforehand I got an error saying that gluon is not recognized. I'm not so sure what changed exactly. Thanks anyway for the help, Omri
[web2py] Re: datetime, DAL and JSON serialization
Sorry for the long reply time (I am working at two jobs and didn't have time to get to it yet). I can supply the following simple example: the data model is: db.define_table(timestamps, Field(by, db.auth_user), Field(at, datetime, default=request.now)) and the controller function is: @service.jsonrpc def test_json(): data = [] timestamps = db(db.timestamps.id 0).select() for ts in timestamps: data.append(dict(by = ts.by.first_name, at = ts.at)) return data When I try to call this from my application (qooxdoo app) I receive the following JSONRPCError: TypeError: datetime.datetime(2010, 11, 10, 10, 33, 22) is not JSON serializable. I think this is different from the behavior in previous versions where I simply got a string back in return. If I go to the test_json view directly through the browser I get the following response: {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 10, 56, 58), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 10, 58, 40), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 44, 11), 'by': 'Andreas'} {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 11, 48, 17), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 55, 12), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 58, 7), 'by': 'Andreas'} {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 12, 7, 50), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 12, 17, 9), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 12, 20, 20), 'by': 'Andreas'} I think it might be related to the detect_types change nick name has hinted at. Am i right? I have tried to look through the Service class source to understand if it uses as_list or not, but I haven't been able to ascertain when a function receives the as_list attribute. Any help would be greatly appreciated, and thanks for the extremely good work on web2py (it seems I keep saying it, but it is really and truly appreciated!) Omri
[web2py] Re: datetime, DAL and JSON serialization
Sorry for the long reply time (I am working at two jobs and didn't have time to get to it yet). I can supply the following simple example: the data model is: db.define_table(timestamps, Field(by, db.auth_user), Field(at, datetime, default=request.now)) and the controller function is: @service.jsonrpc def test_json(): data = [] timestamps = db(db.timestamps.id 0).select() for ts in timestamps: data.append(dict(by = ts.by.first_name, at = ts.at)) return data When I try to call this from my application (qooxdoo app) I receive the following JSONRPCError: TypeError: datetime.datetime(2010, 11, 10, 10, 33, 22) is not JSON serializable. I think this is different from the behavior in previous versions where I simply got a string back in return. If I go to the test_json view directly through the browser I get the following response: {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 10, 56, 58), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 10, 58, 40), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 44, 11), 'by': 'Andreas'} {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 11, 48, 17), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 55, 12), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 11, 58, 7), 'by': 'Andreas'} {'2 {'at': 2 {'at': datetime.datetime(2010, 11, 10, 12, 7, 50), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 12, 17, 9), 'by': 'Andreas'} 2 {'at': datetime.datetime(2010, 11, 10, 12, 20, 20), 'by': 'Andreas'} I think it might be related to the detect_types change nick name has hinted at. Am i right? I have tried to look through the Service class source to understand if it uses as_list or not, but I haven't been able to ascertain when a function receives the as_list attribute. Any help would be greatly appreciated, and thanks for the extremely good work on web2py (it seems I keep saying it, but it is really and truly appreciated!) Omri
[web2py] Web2py uses the wrong database
Hello all, I have recently come across a strange problem: I copied my application to a different name, because I wanted to create a branch for beta testing of my application. I emptied the database from all my tests (using Sqliteman - btw - is there a better way to clear the database and reset the auto incrementing fields?). Now when I opened my development (trunk) version, I discovered that it uses the same (clean) database as the branch. I checked that it really is the same database by using one application to add data, and view the data with the second app. This does not happen with the web2py database administrator, only when I access the data through my application. For both applications I use the default db = DAL('sqlite:// storage.sqlite'). I am accessing the server through JSONRPC (using qooxdoo). Any suggestions? Thanks, Omri
[web2py] Re: Web2py uses the wrong database
I have found my problem - it was some stupid configuration problem. But I will still want to leave the question open - What is the best way to create a new 'clean' copy of the database file, resetting all the auto-increment fields? Thanks, Omri On Tue, Mar 29, 2011 at 11:36, Omri omri...@gmail.com wrote: Hello all, I have recently come across a strange problem: I copied my application to a different name, because I wanted to create a branch for beta testing of my application. I emptied the database from all my tests (using Sqliteman - btw - is there a better way to clear the database and reset the auto incrementing fields?). Now when I opened my development (trunk) version, I discovered that it uses the same (clean) database as the branch. I checked that it really is the same database by using one application to add data, and view the data with the second app. This does not happen with the web2py database administrator, only when I access the data through my application. For both applications I use the default db = DAL('sqlite:// storage.sqlite'). I am accessing the server through JSONRPC (using qooxdoo). Any suggestions? Thanks, Omri
[web2py] Re: Web2py uses the wrong database
Thanks for your quick reply! Omri
[web2py] datetime, DAL and JSON serialization
Hey, I have a problem with datetime json serialization. I am using the DAL with sqlite, and accessing web2py using JSONRPC. Today I started getting an error when trying to pass datetime fields back to the client. I haven't changed anything in the code for the routines, but it seems that the DAL returns a datetime object which is not JSON-serializable. Has anything changed recently with the DAL? I don't think I have changed any configuration properties on my database - but could this be a reason for it suddenly stop working? Thanks for the time and great work on web2py! Omri
Re: [web2py] Re: UnicodeDecodeError: 'ascii' codec can't decode byte ...
sorry for the stupid question - but how can I call the print data function inside a function that is called through JSONRPC? where will I see the output? in case it helps - I know that at least I get the two fields that I sent, because the last line (where I name them specifically) works. On Tue, Nov 9, 2010 at 21:01, mdipierro mdipie...@cs.depaul.edu wrote: As a debug check. I'd like to see what you gate if you print data before the update. Just in case what you put it in it is not what you get. On Nov 9, 1:25 pm, Omri omri...@gmail.com wrote: in the qooxdoo application, I define data as data = {name: Prüfung, textfield : Etwas mit umlaut- üäüöö} and then send it through an asynchronous call (using qx.io.remote.Rpc.callAsync) On Tue, Nov 9, 2010 at 19:42, mdipierro mdipie...@cs.depaul.edu wrote: can you print data? What is in data? On Nov 9, 12:20 pm, Omri omri...@gmail.com wrote: I did some tryouts and it seems that the only problem is with the update method, and then only when called through service.jsonrpc. I created the following model: db.define_table(debug_stuff, Field(name, length=100), Field(textfield, text), format=%(name)s) and defined the following function in the controller (default): @service.jsonrpc def debug_umlauts(data): # db[debug_stuff].insert(**data) # --- Worked, no problem # db(db[debug_stuff][id] == 2).update(**data) # --- Didn't work db(db[debug_stuff][id] == 2).update(name = data['name'], textfield=data['textfield']) # --- Worked return OK update The only line that didn't work was the second one, where I tried to use the **data for the update method. The problem is that I want the method to be general, and therefore cannot use the method of the third line to specify for .update what fields I'm updating. Thanks, Omri On Nov 8, 5:19 pm, mdipierro mdipie...@cs.depaul.edu wrote: Can you try put a u in front of the string u... On Nov 8, 5:30 am, Omri omri...@gmail.com wrote: Hello, I'm having a unicode problem with the DAL. I'm developing a (mainly) RPC database application with qooxdoo as JS framework and web2py as the webserver. I have created a fairly generic update_record function which simply gets two input variables - a table name and a data dictionary with name/value pairs which correspond to the fields of the table. My function looks like this: def update_record(table_name, data): db(db[table_name]['id'] == data['id']).update(**data) return db(db[table_name]['id'] == data['id']).select() My application should work both in English and in German, and my problem is that when I try to update a string value with an Umlaut (example - Überwlad) I get an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position... I am able to insert records to the database with Umlauts, but I use a different method for the insert. I use the syntax of .insert(name = value, name2 = value2,...). I tried to encode all the data keys which are unicode objects without success, it keeps raising the same error. Am I missing something here, or is this a bug? And more interestingly, how can it be solved? Thanks, Omri
[web2py] Small suggestion regarding auth.add_membership
Hello all, I used auth.add_membership today for the first time, and I realized that the add_membership function adds a membership also if the user already has this membership. Wouldn't it make more sense if the function first uses the has_membership function to check if the user is already a part of the group? Thanks for the great work with web2py! I love it :) Omri
Re: [web2py] Re: UnicodeDecodeError: 'ascii' codec can't decode byte ...
I should have thought about that.. the result from the print data function is: {u'textfield': u'Viele Umlauts: \xe4\xe4\xe4\xfc\xfc\xfc\xdc\xdc\xdc\xd6\xd6\xd6\xe4\xe4\xe4', u'name': u'\xdcberprufen'} for the following data sent: data = { name : Überprufen, textfield : Viele Umlauts: äääüüüÜÜÜÖÖÖäää } On Wed, Nov 10, 2010 at 15:23, mdipierro mdipie...@cs.depaul.edu wrote: If you start web2py from the console you should see the output to the console. You can also print to a file or log the output if that makes it easier. On Nov 10, 5:47 am, Omri omri...@gmail.com wrote: sorry for the stupid question - but how can I call the print data function inside a function that is called through JSONRPC? where will I see the output? in case it helps - I know that at least I get the two fields that I sent, because the last line (where I name them specifically) works. On Tue, Nov 9, 2010 at 21:01, mdipierro mdipie...@cs.depaul.edu wrote: As a debug check. I'd like to see what you gate if you print data before the update. Just in case what you put it in it is not what you get. On Nov 9, 1:25 pm, Omri omri...@gmail.com wrote: in the qooxdoo application, I define data as data = {name: Prüfung, textfield : Etwas mit umlaut- üäüöö} and then send it through an asynchronous call (using qx.io.remote.Rpc.callAsync) On Tue, Nov 9, 2010 at 19:42, mdipierro mdipie...@cs.depaul.edu wrote: can you print data? What is in data? On Nov 9, 12:20 pm, Omri omri...@gmail.com wrote: I did some tryouts and it seems that the only problem is with the update method, and then only when called through service.jsonrpc. I created the following model: db.define_table(debug_stuff, Field(name, length=100), Field(textfield, text), format=%(name)s) and defined the following function in the controller (default): @service.jsonrpc def debug_umlauts(data): # db[debug_stuff].insert(**data) # --- Worked, no problem # db(db[debug_stuff][id] == 2).update(**data) # --- Didn't work db(db[debug_stuff][id] == 2).update(name = data['name'], textfield=data['textfield']) # --- Worked return OK update The only line that didn't work was the second one, where I tried to use the **data for the update method. The problem is that I want the method to be general, and therefore cannot use the method of the third line to specify for .update what fields I'm updating. Thanks, Omri On Nov 8, 5:19 pm, mdipierro mdipie...@cs.depaul.edu wrote: Can you try put a u in front of the string u... On Nov 8, 5:30 am, Omri omri...@gmail.com wrote: Hello, I'm having a unicode problem with the DAL. I'm developing a (mainly) RPC database application with qooxdoo as JS framework and web2py as the webserver. I have created a fairly generic update_record function which simply gets two input variables - a table name and a data dictionary with name/value pairs which correspond to the fields of the table. My function looks like this: def update_record(table_name, data): db(db[table_name]['id'] == data['id']).update(**data) return db(db[table_name]['id'] == data['id']).select() My application should work both in English and in German, and my problem is that when I try to update a string value with an Umlaut (example - Überwlad) I get an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position... I am able to insert records to the database with Umlauts, but I use a different method for the insert. I use the syntax of .insert(name = value, name2 = value2,...). I tried to encode all the data keys which are unicode objects without success, it keeps raising the same error. Am I missing something here, or is this a bug? And more interestingly, how can it be solved? Thanks, Omri
[web2py] Re: UnicodeDecodeError: 'ascii' codec can't decode byte ...
I did some tryouts and it seems that the only problem is with the update method, and then only when called through service.jsonrpc. I created the following model: db.define_table(debug_stuff, Field(name, length=100), Field(textfield, text), format=%(name)s) and defined the following function in the controller (default): @service.jsonrpc def debug_umlauts(data): # db[debug_stuff].insert(**data) # --- Worked, no problem # db(db[debug_stuff][id] == 2).update(**data) # --- Didn't work db(db[debug_stuff][id] == 2).update(name = data['name'], textfield=data['textfield']) # --- Worked return OK update The only line that didn't work was the second one, where I tried to use the **data for the update method. The problem is that I want the method to be general, and therefore cannot use the method of the third line to specify for .update what fields I'm updating. Thanks, Omri On Nov 8, 5:19 pm, mdipierro mdipie...@cs.depaul.edu wrote: Can you try put a u in front of the string u... On Nov 8, 5:30 am, Omri omri...@gmail.com wrote: Hello, I'm having a unicode problem with the DAL. I'm developing a (mainly) RPC database application with qooxdoo as JS framework and web2py as the webserver. I have created a fairly generic update_record function which simply gets two input variables - a table name and a data dictionary with name/value pairs which correspond to the fields of the table. My function looks like this: def update_record(table_name, data): db(db[table_name]['id'] == data['id']).update(**data) return db(db[table_name]['id'] == data['id']).select() My application should work both in English and in German, and my problem is that when I try to update a string value with an Umlaut (example - Überwlad) I get an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position... I am able to insert records to the database with Umlauts, but I use a different method for the insert. I use the syntax of .insert(name = value, name2 = value2,...). I tried to encode all the data keys which are unicode objects without success, it keeps raising the same error. Am I missing something here, or is this a bug? And more interestingly, how can it be solved? Thanks, Omri
Re: [web2py] Re: UnicodeDecodeError: 'ascii' codec can't decode byte ...
in the qooxdoo application, I define data as data = {name: Prüfung, textfield : Etwas mit umlaut- üäüöö} and then send it through an asynchronous call (using qx.io.remote.Rpc.callAsync) On Tue, Nov 9, 2010 at 19:42, mdipierro mdipie...@cs.depaul.edu wrote: can you print data? What is in data? On Nov 9, 12:20 pm, Omri omri...@gmail.com wrote: I did some tryouts and it seems that the only problem is with the update method, and then only when called through service.jsonrpc. I created the following model: db.define_table(debug_stuff, Field(name, length=100), Field(textfield, text), format=%(name)s) and defined the following function in the controller (default): @service.jsonrpc def debug_umlauts(data): # db[debug_stuff].insert(**data) # --- Worked, no problem # db(db[debug_stuff][id] == 2).update(**data) # --- Didn't work db(db[debug_stuff][id] == 2).update(name = data['name'], textfield=data['textfield']) # --- Worked return OK update The only line that didn't work was the second one, where I tried to use the **data for the update method. The problem is that I want the method to be general, and therefore cannot use the method of the third line to specify for .update what fields I'm updating. Thanks, Omri On Nov 8, 5:19 pm, mdipierro mdipie...@cs.depaul.edu wrote: Can you try put a u in front of the string u... On Nov 8, 5:30 am, Omri omri...@gmail.com wrote: Hello, I'm having a unicode problem with the DAL. I'm developing a (mainly) RPC database application with qooxdoo as JS framework and web2py as the webserver. I have created a fairly generic update_record function which simply gets two input variables - a table name and a data dictionary with name/value pairs which correspond to the fields of the table. My function looks like this: def update_record(table_name, data): db(db[table_name]['id'] == data['id']).update(**data) return db(db[table_name]['id'] == data['id']).select() My application should work both in English and in German, and my problem is that when I try to update a string value with an Umlaut (example - Überwlad) I get an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position... I am able to insert records to the database with Umlauts, but I use a different method for the insert. I use the syntax of .insert(name = value, name2 = value2,...). I tried to encode all the data keys which are unicode objects without success, it keeps raising the same error. Am I missing something here, or is this a bug? And more interestingly, how can it be solved? Thanks, Omri
[web2py] UnicodeDecodeError: 'ascii' codec can't decode byte ...
Hello, I'm having a unicode problem with the DAL. I'm developing a (mainly) RPC database application with qooxdoo as JS framework and web2py as the webserver. I have created a fairly generic update_record function which simply gets two input variables - a table name and a data dictionary with name/value pairs which correspond to the fields of the table. My function looks like this: def update_record(table_name, data): db(db[table_name]['id'] == data['id']).update(**data) return db(db[table_name]['id'] == data['id']).select() My application should work both in English and in German, and my problem is that when I try to update a string value with an Umlaut (example - Überwlad) I get an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position... I am able to insert records to the database with Umlauts, but I use a different method for the insert. I use the syntax of .insert(name = value, name2 = value2,...). I tried to encode all the data keys which are unicode objects without success, it keeps raising the same error. Am I missing something here, or is this a bug? And more interestingly, how can it be solved? Thanks, Omri
[web2py] JSON-RPC best practices
Hello All, I'm writing a web application using qooxdoo as the client framework and web2py as the server. Almost all of the communication between the client and the server are done through the JSON-RPC service. Since I found myself writing @service.jsonrpc functions by the dozens, I was beginning to wonder what would be considered as best-practices. Should I write a very general function that basically exposes the database to the client side? Should a write many small functions, each wrapping a database call (perhaps sometimes also doing some calculations in the background)? Should I opt to transfer large amounts of data at each JSON-RPC call (to minimize server calls), or only ask for the data when needed? This web-application is intended to be internal to my company, with no more than 30 users, and probably no more than 10 simultaneously. Any thoughts/opinions/discussions are welcome :) Cheers, Omri
[web2py] Re: 'DEMO_MODE' is not defined
I came here to report this bug as well. I did a workaround - it comes from the beginning of the appadmin.py file. For the meantime I put the if DEMO_MODE: inside a try..except block. I'm not sure this is robust but at least it works: try: if DEMO_MODE: response.flash = T('disabled in demo mode') redirect(URL('default','site')) except: pass hope this helps, Omri On Oct 13, 11:50 am, DenesL denes1...@yahoo.ca wrote: Same problem here. Create new app, click on database administration link, error. On Oct 13, 2:43 am, Joe J joe.jasin...@gmail.com wrote: Hi all, I have a newly updated web2py install. If I create a new application and click on any controller associated with the appadmin.py, I get a DEMO_MODE is not defined error. This is before doing any sort of coding. Am I missing some sort of configuration setting? Any help is much appreciated. Joe Version web2py Version 1.87.2 (2010-10-12 15:23:17) Error traceback 1. 2. 3. 4. 5. 6. 7. Traceback (most recent call last): File /Users/jjasinsk/Sites/web2py/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /Users/jjasinsk/Sites/web2py/web2py/applications/asdf/ controllers/appadmin.py, line 14, in module if DEMO_MODE: NameError: name 'DEMO_MODE' is not defined Error snapshot Detailed traceback description * Exception: type 'exceptions.NameError'(name 'DEMO_MODE' is not defined) Exception instance attributes o __setattr__: method-wrapper '__setattr__' of exceptions.NameError object at 0x10160cc68 o __reduce_ex__: built-in method __reduce_ex__ of exceptions.NameError object at 0x10160cc68 o __getslice__: method-wrapper '__getslice__' of exceptions.NameError object at 0x10160cc68 o __getitem__: method-wrapper '__getitem__' of exceptions.NameError object at 0x10160cc68 o __setstate__: built-in method __setstate__ of exceptions.NameError object at 0x10160cc68 o __getattribute__: method-wrapper '__getattribute__' of exceptions.NameError object at 0x10160cc68 o __str__: method-wrapper '__str__' of exceptions.NameError object at 0x10160cc68 o args: (name 'DEMO_MODE' is not defined,) o __reduce__: built-in method __reduce__ of exceptions.NameError object at 0x10160cc68 o __format__: built-in method __format__ of exceptions.NameError object at 0x10160cc68 o __class__: type 'exceptions.NameError' o __dict__: {} o __delattr__: method-wrapper '__delattr__' of exceptions.NameError object at 0x10160cc68 o __subclasshook__: built-in method __subclasshook__ of type object at 0x10011b640 o __repr__: method-wrapper '__repr__' of exceptions.NameError object at 0x10160cc68 o __init__: method-wrapper '__init__' of exceptions.NameError object at 0x10160cc68 o __hash__: method-wrapper '__hash__' of exceptions.NameError object at 0x10160cc68 o __sizeof__: built-in method __sizeof__ of exceptions.NameError object at 0x10160cc68 o __doc__: 'Name not found globally.' o __unicode__: built-in method __unicode__ of exceptions.NameError object at 0x10160cc68 o __new__: built-in method __new__ of type object at 0x10011b640 * Python 2.6.1: /opt/local/bin/python File /Users/jjasinsk/Sites/web2py/web2py/gluon/restricted.py in restricted at line 188 [ code | arguments | variables ] Function argument list: (code='# -*- coding: utf-8 -*-\n\n# #...k=disk)\n\n \nresponse._vars=response._caller(index)\n', environment={'A': class 'gluon.html.A', 'Auth': class 'gluon.tools.Auth', 'B': class 'gluon.html.B', 'BEAUTIFY': class 'gluon.html.BEAUTIFY', 'BODY': class 'gluon.html.BODY', 'BR': class 'gluon.html.BR', 'CENTER': class 'gluon.html.CENTER', 'CLEANUP': class 'gluon.validators.CLEANUP', 'CODE': class 'gluon.html.CODE', 'CRYPT': class 'gluon.validators.CRYPT', ...}, layer='/Users/ jjasinsk/Sites/web2py/web2py/applications/asdf/controllers/ appadmin.py') 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. if type(code) == types.CodeType: ccode = code else: ccode = compile2(code,layer) exec ccode in environment except HTTP: raise except Exception: # XXX Show exception in Wing IDE if running in debugger * environment: {'A': class 'gluon.html.A', 'Auth': class 'gluon.tools.Auth', 'B': class 'gluon.html.B', 'BEAUTIFY': class 'gluon.html.BEAUTIFY', 'BODY': class 'gluon.html.BODY', 'BR': class 'gluon.html.BR', 'CENTER': class 'gluon.html.CENTER', 'CLEANUP': class 'gluon.validators.CLEANUP', 'CODE': class 'gluon.html.CODE', 'CRYPT': class 'gluon.validators.CRYPT', ...} * ccode: code object
[web2py] Embedding the web2py code editor in my application
Hello, I was wondering whether it is possible (or rather if there is a plugin that does it simply) to embed the source code editor of web2py to edit Python code in my application? I want to be able to receive small portions of Python code from the user and save them in the database and later execute them in a predefined python environment. Thanks! Omri Har-Shemesh
[web2py] Validators with Dependencies
Hello, I'm writing a relatively big database application. A small part of it requires me to handle lists of values, where every list can only exist once, and where each item in the list can only exist once (but different lists can have items named the same way). A simplified model is: db.define_table('lists', Field('name')) and db.define_table('list_items', Field('list',db.lists), Field('name')). (there exists more fields but they are irrelevant to the current case). I am now writing an interface to define new lists. I would like to use SQLFORM to generate the forms required. I would like to use the validators IS_NOT_EMPTY() and IS_NOT_IN_DB() to make sure there will not exist two lists with the same name. The problem is that I would also like to make a similar validation on the items of the list, but to restrict the IS_NOT_IN_DB() to a set containing the list items. In the book it gives an example using SQLFORM.factory() on how this should be done, but when I simply use SQLFORM(db.list_items) I don't know how to access the different fields to add a requires validator in the action. I've tried looking in the book and the group but was unable to find a way to do so. Thanks, Omri Har-Shemesh