Massimo, {{=BEAUTIFY(response._vars.values()[0])}} is still preferred
in case the controller returns something like {'': ['a', 'b', {'foo':
'bar'}]}

By the way, here is another proposal. Since you agree on at least "let
me think", please also consider change the generic.html into this.

  <!-- A more generic generic.html -->
  {{extend 'layout.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}}

The point here is such pattern suits a typical controller action like
this:
  def index():
      form = SQLFORM(...)
      if form.accepts(...):
          blah_blah
      return { '' : form }

therefore I do NOT need to write many boring views file again and
again like this:
    {{extend 'layout.html'}}
    {{=form}}

I used such generic.html in all my apps for more than one year. It did
save my numerous time.

Regards,
Iceberg

On Jun22, 3:34am, mdipierro <[email protected]> wrote:
> 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}}
>

Reply via email to