[web2py] Re: component-generated field not getting accepted first time
Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: Virtual Fields. Strange behavior when saving db result sets Build in types
For the time being you can use this syntax: db=DAL() db.define_table('a',Field('b','integer')) for i in range(10): db.a.insert(b=i) def lazy(f): def g(self,f=f): import copy self=copy.copy(self) return lambda *a,**b: f(self,*a,**b) return g class Scale: @lazy def c(self,scale=1): return self.a.b*scale db.a.virtualfields.append(Scale()) for row in db(db.a).select(): print row.b, row.c(1), row.c(2), row.c(3) On Aug 14, 10:57 am, Santiago Gilabert santiagogilab...@gmail.com wrote: anyone? I found that someone else asked about the same issue 5 month ago but there are no comments about it. http://groups.google.com/group/web2py/browse_thread/thread/845e6cdef5... Thanks Santiago On Sat, Aug 13, 2011 at 7:07 PM, Santiago santiagogilab...@gmail.comwrote: Hello, I have the following definitions in db.py class ElectionVirtualField(object): ... def is_presidential(self): def lazy(self=self): return self.election.category == 'P' return lazy ... db.define_table('election', ... Field('category', length=1, label=T('Category') ... The problem I have is that when I add a bunch of elections in dict() (key = election.id, value = election row) and then traverse the dict, I get wrong values from is_presidential() Example: elections = dict() for election in db(db.election).select(): elections[election.id] = election for (k, v) in elections.items(): print k , ' ', v.category, ' ', v.is_presidential() Output: 81 D True 79 P True As you can see, it returns True for both, but for the first one, it should return False. If I change the code to reload the election from the database, the output is different: Example: elections = dict() for election in db(db.election).select(): elections[election.id] = election for (k, v) in elections.items(): reloaded_election = db.election(k) print k , ' ', v.category, ' ', v.is_presidential() Output: 81 D False 79 P True Does this mean that we can't save rows from DB on Build in types ? Thanks in advance, Santiago
[web2py] Re: component-generated field not getting accepted first time
Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: routes.py and rewriting URLs
Ok, it's good to know I'd need to use the pattern-matching router and not the parametric one. Basically what I'm trying to do is avoid having all my controllers in the one directory - in a recent Kohana project for example I had them split up in different subdirectories, according to user role: admin, manager etc. So for now I'll just have to have controllers called admin_courses, admin_users, admin_files etc. and have those in the URLs - when I've got more time I'll work out how to change the URLs (which shouldn't affect how the app works if I don't hard code any URLs I'm assuming) On Aug 14, 6:08 pm, Jonathan Lundell jlund...@pobox.com wrote: On Aug 14, 2011, at 3:26 AM, fishwebby wrote: I'm struggling with the routing in web2py and I'm hoping someone can point me in the right direction (I'm a web2py newbie). I want to change this (which works): http://127.0.0.1:8000/init/admin_courses/index to this: http://127.0.0.1:8000/admin/courses You could probably figure out how to do this eventually using the pattern-matching router (the parametric router won't do it for you), but it's going to be a lot easier if you start out without the need to rename/split controller items. It's hard to say what would work best without knowing more about the patterns you'd see and the controllers and functions you have. but I can't get it to work with the variousroutes.pyfiles. I've followed the suggestions here: http://wiki.web2py.com/URL_Re_writing and here: http://www.web2py.com/book/default/chapter/04#URL-Rewrite and various others from this forum but I can't get anything other than invalid request. I want to do this for various controllers, for example: http://127.0.0.1:8000/admin/users http://127.0.0.1:8000/admin/users/3/assignments (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do something that isn't the web2py way?) If anyone can point me in the right direction it would be greatly appreciated!
[web2py] Re: new Reference.get (polymorphic with Row.get)
in trunk. Thanks. On Aug 14, 8:52 pm, Carlos carlosgali...@gmail.com wrote: Hi Massimo, Can you please include the following in trunk for Reference?: def get(self, key): return self.__getattr__(key) This way, Reference and Row both respond to the 'get' method, polymorphism. I believe this does not break anything else. Thanks, Carlos
[web2py] Re: please help me test new form API
I agree with you that having three ways to do the same thing is not good but: There are three reasons: 1) some people may want to validate without processing the form fully (no insert). shortcut to accepts(...dbio=True) 2) it allows to write onliners: form = SQLFORM().process() 3) no longer need to pass request and session. see process() replacing accepts() and I see validate() as a way to check if form validates without insertion. There are also some different defaults. If you do not pass a session to accepts(...) you do not get CRSF protection. In process(...) you must pass session=None explicitly to disable RSCF protection. We can talk more about these pros, cons, etc. These functions have been in web2py for a while. We just made them work better. On Aug 15, 12:25 am, pbreit pbreitenb...@gmail.com wrote: I'm not totally clear on the gain here. Is it that flash messages get automatically set? Is this going to splinter implementations (ie some will use .accepts, some will use .process, others will use .validate)? Is that a good thing?
[web2py] Re: component-generated field not getting accepted first time
If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: downloads
Thanks for your reply Anthony. That bit is actually working fine. I have put the album folder deliberately in web2py rather than within the application. This makes it easier to backup the application or the albums independently. I will explain my problem with an example. If I have a url .../default/my_download/abc.mp3?album=deffilename=ghi.mp3 Then it does correctly download web2py/albums/def/ghi.mp3 The popup for the user say 'do you want to open or save abc.mp3 So the filename for the message comes from the first argument of my_downloads. As you can see I do not mention args(0) in my routine, so stream or something below must be accessing args(0). It is this that I cannot change. I would like abc.mp3 to come from one of the 'vars' rather than the 'args' (because the args are more restrictive about characters). Thanks Peter On Aug 12, 8:08 pm, Anthony abasta...@gmail.com wrote: On Friday, August 12, 2011 5:24:24 AM UTC-4, peter wrote: path=os.getcwd()+/+'albums'+/+request.vars.album +/+request.vars.filename os.getcwd() refers to the web2py folder, not your application folder. Assuming the 'albums' folder is in your application folder, you can instead use request.folder. Also, you should use os.path.join instead of concatenating the path together. Try: path=os.path.join(request.folder,'albums',request.vars.album,request.vars.filename) Anthony
[web2py] Re: bulkloader web2py
Amnon, i'm using this in my bulkloader.yaml: - property: __key__ external_name: key export_transform: str import_transform: datastore.Key that seems to be working for me - it converts that key to its string hash on the way out and converts from the hash to the original key on the way in. cfh
[web2py] Doing a select in a Virtual Field
Hi All, I'm new to web2py and am trying to get my mind around how virtual fields work. Given the following table: db.define_table(trip, Field(date, date), Field(odo, integer) ) which represents a trip taken by car on a specific date and the odometer reading at the end of each trip: trips = [ {'date': datetime.date(2011, 1, 1), 'odo': 1100}, {'date': datetime.date(2011, 1, 2), 'odo': 1200}, {'date': datetime.date(2011, 1, 3), 'odo': 1300} ] db.trip.bulk_insert(trips) I am trying to add a virtual field to calculate the distance traveled for each trip, such that: distance = (odo of this trip record) - (odo of previous trip record) I add the following virtual fields class and associate it with the table: class tripVirtualFields(object): def distance(self): q = (db.trip.dateself.trip.date) # Query for previous record o = (~db.trip.date, ~db.trip.odo) # Order descending by date r = db(q).select(db.trip.odo, orderby=o, limitby=(0,1)).first() d = (self.trip.odo - r.odo) if r else None # Calc trip distance return (d, self.trip.odo, r) # Return extra info to see problem db.trip.virtualfields.append(tripVirtualFields()) Then when I test this in ipyhton: In [17]: for n in db(db.trip.id0).select(): print n.date, '|', n.odo, '|', n.distance : : 2011-01-01 | 1100 | (None, 1100, None) 2011-01-02 | 1200 | (0, 1100, Row {'odo': 1100}) 2011-01-03 | 1300 | (0, 1200, Row {'odo': 1200}) Notice that for the second and 3rd rows the the calculated distance is always 0 because it seems that the 'self' row passed in to the distance() virtual field function gets 'overwritten' with the row returned with the select in the same function. The question is: can one do a new select inside virtual field function to get data back from another table or from the same table the virtual function acts upon? If not, any other ideas on how to implement this type of requirement in a web2py app? Any help would be much appreciated. Thanks, Tom
[web2py] Re: component-generated field not getting accepted first time
There is no img in this LOAD in particular. However, there is an image being downloaded in a separate LOAD during the refresh sequence. I don't see how it could affect this LOAD, could it? On Aug 15, 3:57 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: component-generated field not getting accepted first time
The view for the LOAD in question is here: {{=DIV( form.custom.begin, FIELDSET( form.custom.widget.text_field, _class='some-class', ), my_button(), form.custom.end, ) }} and my_button is defined: my_button(): return DIV( INPUT( _type='submit', _value=T('do it'), _title=T('do it'), _alt=T('do it'), _class='button', ), _class='some-other-class', ) So it seems there are no images being downloaded here. On Aug 15, 3:57 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: Problem with multiple forms
Thanks weheh, that helped a lot! On Aug 14, 12:12 am, weheh richard_gor...@verizon.net wrote: Each form needs to have a unique name. I suppose you could use uuid to make a unique name. Then something like this pseudocode might work: allforms=dict(form_id=new_form_id(),form=SQLFORM(...)) for f in allforms: if f['form'].accepts(request.vars,formname=f['form_id']): # do something if form accepts else: # do something else if form doesn't accept return dict(allforms=allforms) Then in views you will need to loop on allforms to make your form. You will probably want a custom form and make sure you have a hidden input with id=f['form_id'] Obviously, if the order of forms is important, you will want to modify this code to make the forms into a list instead of a dict. Hope this helps. Good luck. On Aug 13, 9:24 pm, Karthik karthikparameswa...@gmail.com wrote: Is there a way to dynamically name the forms? I don't know how many forms I'll need to display, it depends on an external factor. (I have a textarea and depending on the lines filled in the textarea by the user, I need to create that many forms). Is this possible withing web2py's FORM() helper or would using the default HTML be a better idea? Thanks! On May 6 2010, 9:17 am, mdipierro mdipie...@cs.depaul.edu wrote: If you have two forms you have to name them: if form_back.accepts(request.vars, session, formname='back'): ... if form_membership.accepts(request.vars, session,formname='membership'): On May 6, 7:19 am, Sverre sverreodeg...@gmail.com wrote: I'm using this design in a controller to have buttons on the page: form_membership = FORM('', INPUT(_type='submit',_value='New')) form_back = FORM('', INPUT(_type='submit',_value='Back to user')) if form_back.accepts(request.vars, session): redirect(URL(r=request,c='sysuser',f='edit_user',args=userid)) if form_membership.accepts(request.vars, session): redirect(URL(r=request,c='sysuser',f='new_membership',args=userid)) return dict(msg=rows,form_membership=form_membership,form_back=form_back) But this isn't working. I'm don't get the right redirections. The Back to user' button gives me the redirection of the other button. Has someone a clue?
[web2py] Re: downloads
On Monday, August 15, 2011 6:09:00 AM UTC-4, peter wrote: If I have a url .../default/my_download/abc.mp3?album=deffilename=ghi.mp3 Then it does correctly download web2py/albums/def/ghi.mp3 The popup for the user say 'do you want to open or save abc.mp3 I'm not sure web2py is doing anything to affect that -- I think it's probably the browser -- when it receives the audio stream, it assumes the name is the last part of the URL before the query string. You might be able to fix that by setting the Content-Dispostion header response.headers['Content-Disposition'] = 'inline; filename=%s' % request.vars.filename # for streaming response.headers['Content-Disposition'] = 'attachment; filename=%s' % request.vars.filename # to force download as attachment Note, be careful accepting arbitrary albums and filenames in your request.vars -- a malicious user could employ a directory traversal attack if you don't put some restrictions on allowed values for the album and filename values (web2py's upload/download functionality provides built-in protection against this kind of attack). For example, with your current my_downloads function, here is how someone could steal your parameters_8000.py file: /default/my_downloads/abc.mp3?album=..filename=parameters_8000.py Anthony
[web2py] navbar missing space before bracket
Hello, Would you correct this little glitch (gluon tools.py line 1101) : Change : bar = SPAN(prefix,self.user.first_name,' [ ', logout, ']',_class='auth_navbar') For : bar = SPAN(prefix,self.user.first_name,' [ ', logout, ' ]',_class='auth_navbar') Thanks Richard
[web2py] Birth Date
Hello, dudes!! I want to know which the date of Birth of Web2Py and how many Years. :) * Obrigado, Renato Fabro* C2C Balloon - Humanizing Technology +55 (19) 3289-9610 http://www.c2cballoon.com
[web2py] weird errors about not finding classes / objects when multiple simultaneous requests from different browsers/sessions.
Hi, I'm having some weird errors about web2py/python not finding classes / objects in my models when multiple simultaneous requests come from different browsers/sessions. I'm still running locally (not in production), using the latest web2y trunk on windows 7 with postgresql and rocket. My models are huge for the moment and all in root, which is ok for now. I know I can use the new model sub-folders, modules, etc., but that's not the issue here. Is web2py (or rocket) actually capable of handling simultaneous / parallel web requests without mixing environments (data / models) from these multiple requests?. In one of such cases, I have one class that gets instantiated in my very first model, and suddenly I get an error in my 3rd. model that such instance is None !, which makes no sense because I did instantiate that in my model # 1 and I never reset such var. All these errors do NOT occur at all when I do one web request at a time. Is it because I'm using rocket?, will these problems disappear as soon as I move to apache or nginx?, or is this directly related to web2py or python?. Remember, this is specifically for handling *simultaneous* web requests (from different browsers/sessions) with a long execution time (big models). Thanks for your input. Carlos
Re: [web2py] GAE deployment issue on Ubuntu
It works for me on Ubuntu, though I am not on 11.04. If you have used multiple google accounts for upload, you may face issues of 404 error due to appcfg cache On Sunday, August 14, 2011, Pystar aitoehi...@gmail.com wrote: I just decided to use the appcfg.py tool to deploy my app and it was successful. Anyone who has had success deploying an app from inside web2py to GAE should comment. thanks On Aug 14, 12:14 am, Pystar aitoehi...@gmail.com wrote: Hi, I am running Web2py 1.98.2 on Ubuntu 11.04, when I try to deploy my application to Google app engine via the deploy to GAE in the web2py web console, I do not get any GAE output no matter how long I try. I know there is a disclaimer that response from GAE depends on network speed but I havent gotten any response from GAE after trying to deploy for some hours now. I would like to know if anyone has had success deploying to GAE from web2py. Thanks Pystar -- Thanks and regards Ramaseshan
[web2py] Re: component-generated field not getting accepted first time
No it should not. The extra request must come somewhere. Google Chrome can help. On Aug 15, 9:51 am, weheh richard_gor...@verizon.net wrote: There is no img in this LOAD in particular. However, there is an image being downloaded in a separate LOAD during the refresh sequence. I don't see how it could affect this LOAD, could it? On Aug 15, 3:57 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: component-generated field not getting accepted first time
Could it be in the containing page, or maybe some javascript that is adding to the DOM dynamically? Check the browser developer tools for outgoing requests. Anthony On Monday, August 15, 2011 10:56:19 AM UTC-4, weheh wrote: The view for the LOAD in question is here: {{=DIV( form.custom.begin, FIELDSET( form.custom.widget.text_field, _class='some-class', ), my_button(), form.custom.end, ) }} and my_button is defined: my_button(): return DIV( INPUT( _type='submit', _value=T('do it'), _title=T('do it'), _alt=T('do it'), _class='button', ), _class='some-other-class', ) So it seems there are no images being downloaded here. On Aug 15, 3:57 am, Massimo Di Pierro massimo@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abas...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: Birth Date
The first version was written in August 2007. It was made public on Oct 1, 2007. This group was created on Oct 19, 2007. We moved to Mercurial in Dec 4, 2009. Things have sped up a lot since than. Since 2007 web2py has doubled in size and more than 70% has been rewritten (while keeping backward compatibility). Massimo On Aug 15, 11:09 am, Re Fabro renato.fa...@gmail.com wrote: Hello, dudes!! I want to know which the date of Birth of Web2Py and how many Years. :) * Obrigado, Renato Fabro* C2C Balloon - Humanizing Technology +55 (19) 3289-9610http://www.c2cballoon.com
Re: [web2py] Re: Birth Date
Thx... Perfect! 8) * Obrigado, Renato Fabro* C2C Balloon - Humanizing Technology +55 (19) 3289-9610 http://www.c2cballoon.com 2011/8/15 Massimo Di Pierro massimo.dipie...@gmail.com The first version was written in August 2007. It was made public on Oct 1, 2007. This group was created on Oct 19, 2007. We moved to Mercurial in Dec 4, 2009. Things have sped up a lot since than. Since 2007 web2py has doubled in size and more than 70% has been rewritten (while keeping backward compatibility). Massimo On Aug 15, 11:09 am, Re Fabro renato.fa...@gmail.com wrote: Hello, dudes!! I want to know which the date of Birth of Web2Py and how many Years. :) * Obrigado, Renato Fabro* C2C Balloon - Humanizing Technology +55 (19) 3289-9610http://www.c2cballoon.com
[web2py] Doing a select in a Virtual Field
I think you might have to dereference r. Something like r[0].odo since queries return a set even if there's only one element.
[web2py] web2py.com starts
total requests/day 07/Aug/2011 40024 08/Aug/2011 68275 09/Aug/2011 75787 10/Aug/2011 101568 11/Aug/2011 262590 12/Aug/2011 102468 13/Aug/2011 67747 14/Aug/2011 63734 distinct visitors/day 07/Aug/2011 1159 08/Aug/2011 1972 09/Aug/2011 2102 10/Aug/2011 2496 11/Aug/2011 5119 12/Aug/2011 2551 13/Aug/2011 1737 14/Aug/2011 1659 Aug 11 the day of the Info World article. Notice that sunday/sunday we got a +50% in the number of visitors/requests.
[web2py] Re: routes.py and rewriting URLs
I'm a newbie too, but I see myself also prettying up my URL's with routes.py. Is your routes.py in the correct directory? If it is in an application directory, it won't work. it should be in the web2py directory. A hint: You can always put print statements in any of your .py files to verify they are being executed. For your example, I would guess routes.py would look like: --- routes_in = ( ('admin/courses','init/admin_courses/index'),) routes_out = ( ('init/admin_courses/index', 'admin/courses'),) print routing lists initialized... --- and it would be in your web2py directory. (...time passes, trying it out) I discovered one other thing! If you edit routes.py, SHUTDOWN AND RESTART WEB2PY! The routing lists are initted at web2py startup, not on every http request! Rufus On Aug 14, 6:26 am, fishwebby pastelva...@gmail.com wrote: Hi, I'm struggling with the routing in web2py and I'm hoping someone can point me in the right direction (I'm a web2py newbie). I want to change this (which works): http://127.0.0.1:8000/init/admin_courses/index to this: http://127.0.0.1:8000/admin/courses but I can't get it to work with the various routes.py files. I've followed the suggestions here:http://wiki.web2py.com/URL_Re_writing and here:http://www.web2py.com/book/default/chapter/04#URL-Rewrite and various others from this forum but I can't get anything other than invalid request. I want to do this for various controllers, for example: http://127.0.0.1:8000/admin/usershttp://127.0.0.1:8000/admin/users/3/assignments (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do something that isn't the web2py way?) If anyone can point me in the right direction it would be greatly appreciated! Many thanks Dave
[web2py] Re: bulkloader web2py
Thanks. It did the trick. I appreciate your help, Amnon On Aug 15, 3:53 pm, howesc how...@umich.edu wrote: Amnon, i'm using this in my bulkloader.yaml: - property: __key__ external_name: key export_transform: str import_transform: datastore.Key that seems to be working for me - it converts that key to its string hash on the way out and converts from the hash to the original key on the way in. cfh
[web2py] Re: component-generated field not getting accepted first time
@ MDP Anthony: could you clarify, please? Are you saying that any image on the page from any other LOAD or containing HTML would trigger another pass through the LOADed action that's failing in my case? Or must the image actually be within the failing LOADed action/model/ view? On Aug 15, 12:38 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: No it should not. The extra request must come somewhere. Google Chrome can help. On Aug 15, 9:51 am, weheh richard_gor...@verizon.net wrote: There is no img in this LOAD in particular. However, there is an image being downloaded in a separate LOAD during the refresh sequence. I don't see how it could affect this LOAD, could it? On Aug 15, 3:57 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: routes.py and rewriting URLs
On Monday, August 15, 2011 2:06:23 PM UTC-4, Rufus wrote: For your example, I would guess routes.py would look like: --- routes_in = ( ('admin/courses','init/admin_courses/index'),) routes_out = ( ('init/admin_courses/index', 'admin/courses'),) print routing lists initialized... --- And be careful -- if you want to be able to access the 'admin' app that comes with web2py, make sure your routes still allow that. I discovered one other thing! If you edit routes.py, SHUTDOWN AND RESTART WEB2PY! You can also do: import gluon.rewrite gluon.rewrite.load() You should also be able to go to /admin/default/reload_routes to reload routes.py, but it looks like there is currently a bug that is causing that to fail. Anthony
Re: [web2py] weird errors about not finding classes / objects when multiple simultaneous requests from different browsers/sessions.
It should not be an issue with mixing environments. Can you provide more information? Marin On Mon, Aug 15, 2011 at 6:27 PM, Carlos carlosgali...@gmail.com wrote: Hi, I'm having some weird errors about web2py/python not finding classes / objects in my models when multiple simultaneous requests come from different browsers/sessions. I'm still running locally (not in production), using the latest web2y trunk on windows 7 with postgresql and rocket. My models are huge for the moment and all in root, which is ok for now. I know I can use the new model sub-folders, modules, etc., but that's not the issue here. Is web2py (or rocket) actually capable of handling simultaneous / parallel web requests without mixing environments (data / models) from these multiple requests?. In one of such cases, I have one class that gets instantiated in my very first model, and suddenly I get an error in my 3rd. model that such instance is None !, which makes no sense because I did instantiate that in my model # 1 and I never reset such var. All these errors do NOT occur at all when I do one web request at a time. Is it because I'm using rocket?, will these problems disappear as soon as I move to apache or nginx?, or is this directly related to web2py or python?. Remember, this is specifically for handling *simultaneous* web requests (from different browsers/sessions) with a long execution time (big models). Thanks for your input. Carlos
[web2py] Re: routes.py and rewriting URLs
I tried your suggestion, with routes.py in the web2py directory, but alas it didn't work. Not sure what I'm doing wrong (nice suggestion about the print statement though to make sure it's working). Hmm... On Aug 15, 8:06 pm, Rufus rufusvsm...@gmail.com wrote: I'm a newbie too, but I see myself also prettying up my URL's with routes.py. Is your routes.py in the correct directory? If it is in an application directory, it won't work. it should be in the web2py directory. A hint: You can always put print statements in any of your .py files to verify they are being executed. For your example, I would guess routes.py would look like: --- routes_in = ( ('admin/courses','init/admin_courses/index'),) routes_out = ( ('init/admin_courses/index', 'admin/courses'),) print routing lists initialized... --- and it would be in your web2py directory. (...time passes, trying it out) I discovered one other thing! If you edit routes.py, SHUTDOWN AND RESTART WEB2PY! The routing lists are initted at web2py startup, not on every http request! Rufus On Aug 14, 6:26 am, fishwebby pastelva...@gmail.com wrote: Hi, I'm struggling with the routing in web2py and I'm hoping someone can point me in the right direction (I'm a web2py newbie). I want to change this (which works): http://127.0.0.1:8000/init/admin_courses/index to this: http://127.0.0.1:8000/admin/courses but I can't get it to work with the various routes.py files. I've followed the suggestions here:http://wiki.web2py.com/URL_Re_writing and here:http://www.web2py.com/book/default/chapter/04#URL-Rewrite and various others from this forum but I can't get anything other than invalid request. I want to do this for various controllers, for example: http://127.0.0.1:8000/admin/usershttp://127.0.0.1:8000/admin/users/3/... (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do something that isn't the web2py way?) If anyone can point me in the right direction it would be greatly appreciated! Many thanks Dave
Re: [web2py] weird errors about not finding classes / objects when multiple simultaneous requests from different browsers/sessions.
Hi, I will provide more information in order to reproduce the problem, as soon as I can. But I just want to make sure: are the environments created by web2py fully independent in every single web request (even with multiple concurrent requests) ?. If anybody has more information or has experienced these kind of issues, please let me know. Thanks again, Carlos
[web2py] Scope authenticated users in accounts
(web2py newbie here) - I've got user authentication working ok, but I'd like to be able to scope the auth_users inside an account. My plan is to have accounts identified by subdomains, e.g. account_one.example.com, and then inside that the users can login (a la Basecamp). I've got the following working to get the account model based on the subdomain, redirecting to an account not found page: def requires_account(f): subdomain = request.env.http_host.split('.')[:-2].pop() account = db(db.account.subdomain==subdomain).select().first() if not account: redirect(URL('default', 'account_not_found')) return f @requires_account @auth.requires_login def index(): ... However, I'm a bit stumped as to how to restrict the login to only those users in that account. I've added an account_id field to the auth_users table, but I'm not sure how to proceed - I think ideally I'd like to extend / override the requires_login method so it uses the account but I can't work out how to do it - any help (or suggestions of a better way to do it!) are greatly appreciated! Many thanks Dave
[web2py] [TIP] dowloading attachments with AJAX
Suppose you want to make an AJAX call that starts a file download. How can you do that? 1. form submission 2. a element href 3. iframe Too complex! of course *web2py* comes to rescue... BIG NOTE: the following is based on 'data:' url type and was tested only on FF and chrome. I do not have IE but I suppose that is not compatible with the standard! In your view put a web2py ajax call similar to the following wherever you need it: ajax('%s',[],':eval'); % URL('gen_pdf') ex. {{=A(T('be brave!'), _onclick=ajax('%s',[],':eval'); % URL('gen_pdf'), _class='button')}} in the controller use embed64. def gen_pdf(): from gluon.contrib.pyfpdf import FPDF pdf=FPDF() pdf.add_page() pdf.set_font('Arial','B',16) pdf.cell(40,10,'Hello World at %s!' % request.now) doc=pdf.output(dest='S') doc64=embed64(data=doc,extension='application/pdf') return 'window.location=%s;' % doc64 have fun! mic
[web2py] Re: Scope authenticated users in accounts
You might want to consider using this: https://groups.google.com/d/msg/web2py/NrvxeWQJvH0/wbafxppaf1QJ (note, 'request_precinct' has been changed to the more general 'request_tenant', as noted later in that thread). Otherwise, I suppose you could use the Auth groups functionality ( http://web2py.com/book/default/chapter/08#Authorization) -- create a group for each subdomain and assign/check permissions based on the current request's subdomain. Note, the full multi-tenancy solution (first link) might be better because it allows you to easily segment every single database table by subdomain so any queries return only results related to the particular subdomain. Also, rather than creating your own requires_account decorator, you could probably just use auth.requires (see http://web2py.com/book/default/chapter/08#Combining-Requirements). Anthony On Monday, August 15, 2011 4:31:33 PM UTC-4, fishwebby wrote: (web2py newbie here) - I've got user authentication working ok, but I'd like to be able to scope the auth_users inside an account. My plan is to have accounts identified by subdomains, e.g. account_one.example.com, and then inside that the users can login (a la Basecamp). I've got the following working to get the account model based on the subdomain, redirecting to an account not found page: def requires_account(f): subdomain = request.env.http_host.split('.')[:-2].pop() account = db(db.account.subdomain==subdomain).select().first() if not account: redirect(URL('default', 'account_not_found')) return f @requires_account @auth.requires_login def index(): ... However, I'm a bit stumped as to how to restrict the login to only those users in that account. I've added an account_id field to the auth_users table, but I'm not sure how to proceed - I think ideally I'd like to extend / override the requires_login method so it uses the account but I can't work out how to do it - any help (or suggestions of a better way to do it!) are greatly appreciated! Many thanks Dave
[web2py] Ace now powering GitHub edit
https://github.com/blog/905-edit-like-an-ace
[web2py] Re: Scope authenticated users in accounts
I wonder if you could write some sort of custom validator that checks that the subdomain matches auth.user.account_id?
[web2py] Re: routes.py and rewriting URLs
I'm a newbie and I try to avoid at all costs using routes.py just to re-organize my controllers. It's much safer, easier and predictable to organize controllers and functions to map directly to URLs. If you are moving from another system and want to make sure old users continue to be supported, that's a reasonable reason to use routes.py like this.
[web2py] Re: component-generated field not getting accepted first time
As Massimo suggests, I think it would have to be a broken link, not just any image loading. However, I can't seem to replicate the problem even with a broken image link, so maybe Massimo can offer more detail. Anthony On Monday, August 15, 2011 2:31:40 PM UTC-4, weheh wrote: @ MDP Anthony: could you clarify, please? Are you saying that any image on the page from any other LOAD or containing HTML would trigger another pass through the LOADed action that's failing in my case? Or must the image actually be within the failing LOADed action/model/ view? On Aug 15, 12:38 pm, Massimo Di Pierro massimo@gmail.com wrote: No it should not. The extra request must come somewhere. Google Chrome can help. On Aug 15, 9:51 am, weheh richard...@verizon.net wrote: There is no img in this LOAD in particular. However, there is an image being downloaded in a separate LOAD during the refresh sequence. I don't see how it could affect this LOAD, could it? On Aug 15, 3:57 am, Massimo Di Pierro massimo@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abas...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 11:38 AM, Anthony wrote: You should also be able to go to /admin/default/reload_routes to reload routes.py, but it looks like there is currently a bug that is causing that to fail. Any idea why (or how)?
Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 1:20 PM, fishwebby wrote: I tried your suggestion, with routes.py in the web2py directory, but alas it didn't work. Not sure what I'm doing wrong (nice suggestion about the print statement though to make sure it's working). You can also revise the doctests in routes.py to match your rules, and use that for some basic testing.
Re: [web2py] Re: routes.py and rewriting URLs
On Monday, August 15, 2011 5:14:01 PM UTC-4, Jonathan Lundell wrote: On Aug 15, 2011, at 11:38 AM, Anthony wrote: You should also be able to go to /admin/default/reload_routes to reload routes.py, but it looks like there is currently a bug that is causing that to fail. Any idea why (or how)? It calls gluon.rewrite.load() without importing gluon.rewrite. I submitted a patch to Massimo. Anthony
Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 2:40 PM, Anthony wrote: On Monday, August 15, 2011 5:14:01 PM UTC-4, Jonathan Lundell wrote: On Aug 15, 2011, at 11:38 AM, Anthony wrote: You should also be able to go to /admin/default/reload_routes to reload routes.py, but it looks like there is currently a bug that is causing that to fail. Any idea why (or how)? It calls gluon.rewrite.load() without importing gluon.rewrite. I submitted a patch to Massimo. Ah, thanks.
[web2py] Re: {{web2py_conflict}}
I will be interested to hear how this works out, as I'm also interested in Angular.
[web2py] Speeding up model execution for large models
Hello, I'm using web2py with a relatively large legacy database. We have about 70 tables, and models/db.py is close to 1000 lines long. The problem I'm facing is that all of these Field() constructors and define_table() calls take about 150-200ms to execute, and this overhead occurs each time any request is made to web2py. Compare this to a minimal web2py app, which might have a (reasonable) 10-30ms of overhead before response data starts flowing to the client. I was hoping that a simple solution would be to declare the DAL structure once in an importable module, which would be run once on web2py startup rather than at each request. I could then deepcopy it in my model file (which I think would be faster than all the calls to define_table(), Field(), etc.), and then establish a connection to the database from this copied DAL. Unfortunately, there are a few problems with this: 1. If a DAL instance is to be connected to the database, it must happen in the constructor. It doesn't seem that you can do db = DAL(None) and then establish a connection after the fact. Also, it looks like some db-specific behavior is set up in the DAL constructor based on the connection URL - this wouldn't happen in the case of DAL(None). 2. Table and Field instances have a reference to db, so it seems that define_table() needs to be called *after* the DAL connection has been established in order to set up these references. I suppose it would be possible to deepcopy a DAL(None) instance that has been established with Tables and Fields, and monkey-patch the db references thoughout the DAL structure, but chances seem good that this will create subtle bugs down the road if the internal DAL implementation ever changes. Can anyone suggest a better way to speed up DAL creation for large schemas? Thanks, Kevin
[web2py] Re: Speeding up model execution for large models
First, have you set migrate to False for all tables, and have you bytecode compiled the app? That should speed things up. Also, do you need all 70 tables for any requests, or can they be broken up based on the particular controller/function called? If so, you may speed things up with conditional models. Any files in /models/controller1 will only be executed on requests for controller1, and any files in /models/controller1/function1 will only be executed on requests for controller1/function1. (We're working on more general functionality for conditional models that won't be based solely on the controller and function.) Anthony On Monday, August 15, 2011 6:30:06 PM UTC-4, Kevin Ivarsen wrote: Hello, I'm using web2py with a relatively large legacy database. We have about 70 tables, and models/db.py is close to 1000 lines long. The problem I'm facing is that all of these Field() constructors and define_table() calls take about 150-200ms to execute, and this overhead occurs each time any request is made to web2py. Compare this to a minimal web2py app, which might have a (reasonable) 10-30ms of overhead before response data starts flowing to the client. I was hoping that a simple solution would be to declare the DAL structure once in an importable module, which would be run once on web2py startup rather than at each request. I could then deepcopy it in my model file (which I think would be faster than all the calls to define_table(), Field(), etc.), and then establish a connection to the database from this copied DAL. Unfortunately, there are a few problems with this: 1. If a DAL instance is to be connected to the database, it must happen in the constructor. It doesn't seem that you can do db = DAL(None) and then establish a connection after the fact. Also, it looks like some db-specific behavior is set up in the DAL constructor based on the connection URL - this wouldn't happen in the case of DAL(None). 2. Table and Field instances have a reference to db, so it seems that define_table() needs to be called *after* the DAL connection has been established in order to set up these references. I suppose it would be possible to deepcopy a DAL(None) instance that has been established with Tables and Fields, and monkey-patch the db references thoughout the DAL structure, but chances seem good that this will create subtle bugs down the road if the internal DAL implementation ever changes. Can anyone suggest a better way to speed up DAL creation for large schemas? Thanks, Kevin
[web2py] Re: Scope authenticated users in accounts
Fantastic, the request_tenant method is just what I was looking for! So this is what I've got working: def requires_account(f): Redirect to the account not found page if there is no account (decorator function) if not get_account(): redirect(URL('accounts', 'not_found')) return f def get_account(): Get the account from the subdomain and store it in the session, if not already stored if not session.account: subdomain = request.env.http_host.split('.')[:-2].pop() session.account = db(db.account.subdomain==subdomain).select(db.account.id, db.account.title).first() return session.account defined in db.py (is that the best place to put them?) - then after I've defined the account table, I've got this: db._request_tenant = 'account_id' db._common_fields=[Field('account_id',default=session.account.id, writable=False, readable=False)] Which seems to work rather nicely. Thank you very much for your reply! On Aug 15, 10:53 pm, Anthony abasta...@gmail.com wrote: You might want to consider using this:https://groups.google.com/d/msg/web2py/NrvxeWQJvH0/wbafxppaf1QJ(note, 'request_precinct' has been changed to the more general 'request_tenant', as noted later in that thread). Otherwise, I suppose you could use the Auth groups functionality (http://web2py.com/book/default/chapter/08#Authorization) -- create a group for each subdomain and assign/check permissions based on the current request's subdomain. Note, the full multi-tenancy solution (first link) might be better because it allows you to easily segment every single database table by subdomain so any queries return only results related to the particular subdomain. Also, rather than creating your own requires_account decorator, you could probably just use auth.requires (seehttp://web2py.com/book/default/chapter/08#Combining-Requirements). Anthony On Monday, August 15, 2011 4:31:33 PM UTC-4, fishwebby wrote: (web2py newbie here) - I've got user authentication working ok, but I'd like to be able to scope the auth_users inside an account. My plan is to have accounts identified by subdomains, e.g. account_one.example.com, and then inside that the users can login (a la Basecamp). I've got the following working to get the account model based on the subdomain, redirecting to an account not found page: def requires_account(f): subdomain = request.env.http_host.split('.')[:-2].pop() account = db(db.account.subdomain==subdomain).select().first() if not account: redirect(URL('default', 'account_not_found')) return f @requires_account @auth.requires_login def index(): ... However, I'm a bit stumped as to how to restrict the login to only those users in that account. I've added an account_id field to the auth_users table, but I'm not sure how to proceed - I think ideally I'd like to extend / override the requires_login method so it uses the account but I can't work out how to do it - any help (or suggestions of a better way to do it!) are greatly appreciated! Many thanks Dave
[web2py] Re: Speeding up model execution for large models
Hi Anthony, Thanks for the quick response. I do use migrate=False already. I have not tried bytecode compiling the app, but earlier today I did a quick test: I wrapped the contents of my long db.py in an if False: block (causing it to compile, but not run, the code for each request), and compared this to an empty db.py (nothing to compile or run). It looks like compiling the code took about 7ms - about 5% of the total overhead. I don't think bytecode compiling will produce the dramatic improvement that I'm hoping to find (though I will of course try it when I get a chance.) Conditional models might help some - at the expense of additional planning and maintenance required during development. In any case, I still worry about the number of tables that need to be shared across at least two controllers, and the lower bound on performance those will impose. I was hoping to find a more global way to speed up models. Optimizing DAL creation would be an interesting area for future web2py development, IMHO. When I get some more time I might try to look at this in more detail. Cheers, Kevin On Aug 15, 3:59 pm, Anthony abasta...@gmail.com wrote: First, have you set migrate to False for all tables, and have you bytecode compiled the app? That should speed things up. Also, do you need all 70 tables for any requests, or can they be broken up based on the particular controller/function called? If so, you may speed things up with conditional models. Any files in /models/controller1 will only be executed on requests for controller1, and any files in /models/controller1/function1 will only be executed on requests for controller1/function1. (We're working on more general functionality for conditional models that won't be based solely on the controller and function.) Anthony On Monday, August 15, 2011 6:30:06 PM UTC-4, Kevin Ivarsen wrote: Hello, I'm using web2py with a relatively large legacy database. We have about 70 tables, and models/db.py is close to 1000 lines long. The problem I'm facing is that all of these Field() constructors and define_table() calls take about 150-200ms to execute, and this overhead occurs each time any request is made to web2py. Compare this to a minimal web2py app, which might have a (reasonable) 10-30ms of overhead before response data starts flowing to the client. I was hoping that a simple solution would be to declare the DAL structure once in an importable module, which would be run once on web2py startup rather than at each request. I could then deepcopy it in my model file (which I think would be faster than all the calls to define_table(), Field(), etc.), and then establish a connection to the database from this copied DAL. Unfortunately, there are a few problems with this: 1. If a DAL instance is to be connected to the database, it must happen in the constructor. It doesn't seem that you can do db = DAL(None) and then establish a connection after the fact. Also, it looks like some db-specific behavior is set up in the DAL constructor based on the connection URL - this wouldn't happen in the case of DAL(None). 2. Table and Field instances have a reference to db, so it seems that define_table() needs to be called *after* the DAL connection has been established in order to set up these references. I suppose it would be possible to deepcopy a DAL(None) instance that has been established with Tables and Fields, and monkey-patch the db references thoughout the DAL structure, but chances seem good that this will create subtle bugs down the road if the internal DAL implementation ever changes. Can anyone suggest a better way to speed up DAL creation for large schemas? Thanks, Kevin
[web2py] Re: can I turn off the auto back-references?
Hi Massimo, Can you please let me know if this switch can be implemented in web2py?. Many thanks, Carlos
[web2py] Re: Speeding up model execution for large models
This thread from the developers list a few months ago may interest you: https://groups.google.com/d/topic/web2py-developers/rYKg1TUXem0/discussion Anthony On Monday, August 15, 2011 8:18:30 PM UTC-4, Kevin Ivarsen wrote: Hi Anthony, Thanks for the quick response. I do use migrate=False already. I have not tried bytecode compiling the app, but earlier today I did a quick test: I wrapped the contents of my long db.py in an if False: block (causing it to compile, but not run, the code for each request), and compared this to an empty db.py (nothing to compile or run). It looks like compiling the code took about 7ms - about 5% of the total overhead. I don't think bytecode compiling will produce the dramatic improvement that I'm hoping to find (though I will of course try it when I get a chance.) Conditional models might help some - at the expense of additional planning and maintenance required during development. In any case, I still worry about the number of tables that need to be shared across at least two controllers, and the lower bound on performance those will impose. I was hoping to find a more global way to speed up models. Optimizing DAL creation would be an interesting area for future web2py development, IMHO. When I get some more time I might try to look at this in more detail. Cheers, Kevin On Aug 15, 3:59 pm, Anthony abas...@gmail.com wrote: First, have you set migrate to False for all tables, and have you bytecode compiled the app? That should speed things up. Also, do you need all 70 tables for any requests, or can they be broken up based on the particular controller/function called? If so, you may speed things up with conditional models. Any files in /models/controller1 will only be executed on requests for controller1, and any files in /models/controller1/function1 will only be executed on requests for controller1/function1. (We're working on more general functionality for conditional models that won't be based solely on the controller and function.) Anthony On Monday, August 15, 2011 6:30:06 PM UTC-4, Kevin Ivarsen wrote: Hello, I'm using web2py with a relatively large legacy database. We have about 70 tables, and models/db.py is close to 1000 lines long. The problem I'm facing is that all of these Field() constructors and define_table() calls take about 150-200ms to execute, and this overhead occurs each time any request is made to web2py. Compare this to a minimal web2py app, which might have a (reasonable) 10-30ms of overhead before response data starts flowing to the client. I was hoping that a simple solution would be to declare the DAL structure once in an importable module, which would be run once on web2py startup rather than at each request. I could then deepcopy it in my model file (which I think would be faster than all the calls to define_table(), Field(), etc.), and then establish a connection to the database from this copied DAL. Unfortunately, there are a few problems with this: 1. If a DAL instance is to be connected to the database, it must happen in the constructor. It doesn't seem that you can do db = DAL(None) and then establish a connection after the fact. Also, it looks like some db-specific behavior is set up in the DAL constructor based on the connection URL - this wouldn't happen in the case of DAL(None). 2. Table and Field instances have a reference to db, so it seems that define_table() needs to be called *after* the DAL connection has been established in order to set up these references. I suppose it would be possible to deepcopy a DAL(None) instance that has been established with Tables and Fields, and monkey-patch the db references thoughout the DAL structure, but chances seem good that this will create subtle bugs down the road if the internal DAL implementation ever changes. Can anyone suggest a better way to speed up DAL creation for large schemas? Thanks, Kevin
[web2py] migrate file system uploads to database?
Hello, I read the docs and searched the posts to see if there was an easy way to migrate file system uploads to database. I could not find anything.. Please excuse me if I missed something obvious, but does anyone know of a way to accomplish this in a batch process? Thanks. Patrick
[web2py] Re: can I turn off the auto back-references?
I think you can also do: myrow.fieldname or othervalue
[web2py] Re: can I turn off the auto back-references?
Hi pbreit, Thanks for your input, but that will not work, since row.fieldname still incorrectly returns the Set object (therefore not executing the 'or' statement). Secondly, fieldname is a str variable in my case, which can't be used directly with the dot notation. I just need to not have these back references automatically added to the row dictionary, maybe via a new switch, if possible. Massimo, what do you think?. Thanks, Carlos
[web2py] Re: component-generated field not getting accepted first time
Massimo, can you be more explicit? What do you suggest using in Chrome that will help? What tool should I be using to look for this? I mostly use Firebug in Firefox and Eclipse for debugging. Sometimes use Chrome for inspecting elements but not much else. On Aug 15, 12:38 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: No it should not. The extra request must come somewhere. Google Chrome can help. On Aug 15, 9:51 am, weheh richard_gor...@verizon.net wrote: There is no img in this LOAD in particular. However, there is an image being downloaded in a separate LOAD during the refresh sequence. I don't see how it could affect this LOAD, could it? On Aug 15, 3:57 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard_gor...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard_gor...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard_gor...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abasta...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have an idea what's going on?
[web2py] Re: component-generated field not getting accepted first time
Firebug shows only 1 outgoing request to each of the .load actions on the page, including the offending one. I've checked for broken links and there are none. I'm checking but I'm 99.999% confident there is no js adding to the DOM with respect to this form. If it helps, you can see the problem at http://beta.yakitome.com and click on the Upload tab and then the From Text accordion. Click the TTS button and nothing happens the first time. After that, it works ok. On Aug 15, 12:43 pm, Anthony abasta...@gmail.com wrote: Could it be in the containing page, or maybe some javascript that is adding to the DOM dynamically? Check the browser developer tools for outgoing requests. Anthony On Monday, August 15, 2011 10:56:19 AM UTC-4, weheh wrote: The view for the LOAD in question is here: {{=DIV( form.custom.begin, FIELDSET( form.custom.widget.text_field, _class='some-class', ), my_button(), form.custom.end, ) }} and my_button is defined: my_button(): return DIV( INPUT( _type='submit', _value=T('do it'), _title=T('do it'), _alt=T('do it'), _class='button', ), _class='some-other-class', ) So it seems there are no images being downloaded here. On Aug 15, 3:57 am, Massimo Di Pierro massimo@gmail.com wrote: If your view contains something like img src= / you would get a second call to the URL itself. On Aug 15, 2:44 am, weheh richard...@verizon.net wrote: Just as you predicted, kimosabe, there is a second pass through the action. I made an var in my model and assigned the env.path_info to it. Here's what I see in Eclipse: ... ENV_PATH_INFO str: /YAKiToMe/my_controller/my_action.load ENV_PATH_INFO (126270224) str: /YAKiToMe/my_controller/my_action.load ... I'm not sure where the 2nd pass is coming from. Also, I don't know what to make of the number in parenthesis ... Eclipse is trying to tell me something ... do you know what it is? On Aug 15, 3:03 am, weheh richard...@verizon.net wrote: Very interesting. Yes, it makes sense now that I see for 1st time that models are being called for each every LOAD. Now it is obvious why browser refresh is slow for me! I am tracing it through and will let you know what I find. Thanks for the lead. On Aug 14, 6:04 pm, Massimo Di Pierro massimo@gmail.com wrote: in your models add a print request.env.path_info you may find somehow you have one more call than you think which resets the session. This may be due to a broken link in the view. On 14 Ago, 14:01, weheh richard...@verizon.net wrote: As you can see, nothing really fancy here. def my_action(): form=SQLFORM.factory( Field('text_field','text', length=10 if auth.user_id else 50, default=T(default text) if not auth.user_id else '', requires=IS_NOT_EMPTY()), _id='text-form') if form.accepts(request.vars,session): # the body of this won't be executed the first time the form # is loaded, but it does get executed every time thereafter # so this is not where the problem is elif form.errors: # this condition is tested the first time the form is # submitted, but not thereafter because the form # accepts properly the second and subsequent times return dict(form=form) The view is down below some widgets and stuff. It always displays properly. Here's the actual LOAD statement: div{{=LOAD('my_controller','my_action.load',ajax=True)}}/div On Aug 14, 2:36 pm, Anthony abas...@gmail.com wrote: Can you show your controller and view code? On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: I have a componentized form that is behaving very strangely. The form is very simple -- just a text field. form=SQLFORM.factory(Field('text_in','text')) if form.accepts(request.vars, session): do stuff ... The first time I load the form, it loads fine. I traced it in Eclipse and saw the form getting created with SQLFORM.factory. When I fill in text, however, the form does not accept, nor does it generate any error. Inspecting in Eclipse shows form.vars is empty. OK, so now the form is still visible since it was reloaded. I enter the same text again and click submit. This time, the form.accepts(...) accepts the form and processes it. I upgraded to the latest and greatest version but still get this strange behavior. Anybody have
Re: [web2py] Doing a select in a Virtual Field
On Monday 15 August 2011 19:47:09 pbreit wrote: I think you might have to dereference r. Something like r[0].odo since queries return a set even if there's only one element. From my tests, the .first() in the query: r = db(q).select(db.trip.odo, orderby=o, limitby=(0,1)).first() seems to return only one Row. This is confirmed where r is returned by the distance function in a tuple: return (d, self.trip.odo, r) # Return extra info to see problem and then printed out in the test loop: 2011-01-03 | 1300 | (0, 1200, Row {'odo': 1200}) Here the tuple at the end is the return value from the distance function, with r the row selected in the virtual function, showing thaqt the selected row odo value is 1200. The second value in the tuple is supposed to be the trip.odo value of the record passed into the virtual function (should be 1300 in this case shown as the second field printed), but inside the virtual function, after doing a select for the previous row, *self* seems to be *replaced* by the select result. It's almost like a buffer is being overwritten when doing a select in the virtual field function which causes the original record passed into the function to be lost. Thanks for your reply though. /Tom
Re: [web2py] Doing a select in a Virtual Field
Oh, yeah, that's right. Sorry about that. I suspect the problem could indeed be with a query in a virtual field but I don't know enough about it to say for sure. Another option might be to implement it as just a regular function.
[web2py] Re: Speeding up model execution for large models
Very interesting reading Anthony - thanks for the link. Kevin On Aug 15, 6:27 pm, Anthony abasta...@gmail.com wrote: This thread from the developers list a few months ago may interest you:https://groups.google.com/d/topic/web2py-developers/rYKg1TUXem0/discu... Anthony On Monday, August 15, 2011 8:18:30 PM UTC-4, Kevin Ivarsen wrote: Hi Anthony, Thanks for the quick response. I do use migrate=False already. I have not tried bytecode compiling the app, but earlier today I did a quick test: I wrapped the contents of my long db.py in an if False: block (causing it to compile, but not run, the code for each request), and compared this to an empty db.py (nothing to compile or run). It looks like compiling the code took about 7ms - about 5% of the total overhead. I don't think bytecode compiling will produce the dramatic improvement that I'm hoping to find (though I will of course try it when I get a chance.) Conditional models might help some - at the expense of additional planning and maintenance required during development. In any case, I still worry about the number of tables that need to be shared across at least two controllers, and the lower bound on performance those will impose. I was hoping to find a more global way to speed up models. Optimizing DAL creation would be an interesting area for future web2py development, IMHO. When I get some more time I might try to look at this in more detail. Cheers, Kevin On Aug 15, 3:59 pm, Anthony abas...@gmail.com wrote: First, have you set migrate to False for all tables, and have you bytecode compiled the app? That should speed things up. Also, do you need all 70 tables for any requests, or can they be broken up based on the particular controller/function called? If so, you may speed things up with conditional models. Any files in /models/controller1 will only be executed on requests for controller1, and any files in /models/controller1/function1 will only be executed on requests for controller1/function1. (We're working on more general functionality for conditional models that won't be based solely on the controller and function.) Anthony On Monday, August 15, 2011 6:30:06 PM UTC-4, Kevin Ivarsen wrote: Hello, I'm using web2py with a relatively large legacy database. We have about 70 tables, and models/db.py is close to 1000 lines long. The problem I'm facing is that all of these Field() constructors and define_table() calls take about 150-200ms to execute, and this overhead occurs each time any request is made to web2py. Compare this to a minimal web2py app, which might have a (reasonable) 10-30ms of overhead before response data starts flowing to the client. I was hoping that a simple solution would be to declare the DAL structure once in an importable module, which would be run once on web2py startup rather than at each request. I could then deepcopy it in my model file (which I think would be faster than all the calls to define_table(), Field(), etc.), and then establish a connection to the database from this copied DAL. Unfortunately, there are a few problems with this: 1. If a DAL instance is to be connected to the database, it must happen in the constructor. It doesn't seem that you can do db = DAL(None) and then establish a connection after the fact. Also, it looks like some db-specific behavior is set up in the DAL constructor based on the connection URL - this wouldn't happen in the case of DAL(None). 2. Table and Field instances have a reference to db, so it seems that define_table() needs to be called *after* the DAL connection has been established in order to set up these references. I suppose it would be possible to deepcopy a DAL(None) instance that has been established with Tables and Fields, and monkey-patch the db references thoughout the DAL structure, but chances seem good that this will create subtle bugs down the road if the internal DAL implementation ever changes. Can anyone suggest a better way to speed up DAL creation for large schemas? Thanks, Kevin