I like the idea. Let me think a little bit about the implementation
until the end of this week.
Why {{=BEAUTIFY(response._vars.values()[0])}} and not
{{=response._vars.values()[0]}}On Jun 21, 1:09 pm, Iceberg <[email protected]> wrote: > Hi Massimo, thanks for your sharing another undocumented magic of > web2py, the response.headers['web2py-component-flash'], in this > post,http://groups.google.com/group/web2py/msg/6049af89fbfa2bfc > > That makes me think that is just another example to justify my > proposal, this time it is refined to automatically convert > reponse.flash into response.headers['web2py-component-flash'] when > needed. > > Check this out. It is self-documented. > > {{ ''' > With this generic.load file, you can use same action to serve two > purposes. > > Example modified fromhttp://www.web2py.com/AlterEgo/default/show/252: > > def index(): > return { > 'part1':'hello world', > 'part2': LOAD( > url=URL(r=request,f='auxiliary.load'), # Notice the > ".load" extention > ajax=True), > } > > def auxiliary(): > form=SQLFORM.factory(Field('name')) > if form.accepts(request.vars): > response.flash = 'ok' # No need for this anymore: > response.headers['web2py-component-flash'] = 'ok' > return {'': "Hello %s" % form.vars.name} > return {'':form} # No need for "return form" anymore! > > From now on, single auxiliary() can serve two > purposes:http://.../auxiliary.load serves as a raw component LOADed by other > actionhttp://.../auxiliary serves as a normal html page as usual > > # PS: Please keep all above explanation for people to know when and > how to use it. > # License: Public Domain > # Author: Iceberg at 21cn dot com > ''' > > }} > > {{ # Does NOT extend layout.html, purposely.}} > {{response.headers['Content-Type']='text/html'}} > {{if response.flash: response.headers['web2py-component-flash'] = > response.flash}} > {{if len(response._vars)==1 and not response._vars.keys()[0]:}} > {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly > colon }} > {{else:}} > {{=BEAUTIFY(response._vars)}} > {{pass}} > > On Jun3日, 10:21pm, mdipierro <[email protected]> wrote: > > > I am not convinced this is general enought but I like the idea. Let me > > think about it. > > > On Jun 3, 7:17 am, Iceberg <[email protected]> wrote: > > > > Hi Massimo, > > > > I just came up with a handy myapp/views/generic.load, and I wonder > > > whether you will like to accept it as part of web2py scaffold. It is > > > already self-documented. > > > > <!-- Start of the generic.load --> > > > > {{ ''' > > > With this generic.load file, you can use same action to serve two > > > purposes. > > > > Example modified fromhttp://www.web2py.com/AlterEgo/default/show/252: > > > > def index(): > > > return { > > > 'part1':'hello world', > > > 'part2': LOAD( > > > url=URL(r=request,f='auxiliary.load'), # Notice the > > > ".load" extention > > > ajax=True), > > > } > > > > def auxiliary(): > > > form=SQLFORM.factory(Field('name')) > > > if form.accepts(request.vars): > > > return {'': "Hello %s" % form.vars.name} > > > return {'':form} # Need NOT to write it as "return form" any more! > > > > From now on, single auxiliary() can serve two > > > purposes:http://.../auxiliary.load serves as a raw component LOADed by > > > other > > > actionhttp://.../auxiliary serves as a normal html page as usual > > > > # PS: Please keep all above explanation for people to know when and > > > how to use it. > > > # License: Public Domain > > > # Author: Iceberg at 21cn dot com > > > ''' > > > > }} > > > > {{ # Does NOT extend layout.html, purposely.}} > > > {{response.headers['Content-Type']='text/html'}} > > > {{if len(response._vars)==1 and not response._vars.keys()[0]:}} > > > {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly > > > colon }} > > > {{else:}} > > > {{=BEAUTIFY(response._vars)}} > > > {{pass}}

