No reaction to including a four line big productivity booster into
web2py!

If not an enhanced BEAUTIFY class why not another BEAUTIFY class such
as BEAUTIFY2?

Surely at least an answer is merited, even if the answer is no!

Below is a copy of http://www.web2pyslices.com/main/slices/take_slice/58

Title: BEAUTIFY enhanced

Notes: How to break the alphabetic ordering dependence of BEAUTIFY and
use multiple word keys with the dict method
The problem

A view page such as

{{extend 'layout.html'}}
<br />
{{=BEAUTIFY(response._vars)}}

will produce a nice recursively traversed presentation showing keys
and values of the response._vars dictionary in a table. If a key value
points to an inner dictionary, list ot tuple then the value is
recursed and shown as a table within a table. Very convenient.

There are two problems

   1. The order of presentation of keys at a particular dictionary
recursion level is alphabetical.
   2. Using the dict method is common in web2py to construct a
dictionary. However with this method keys cannot have spaces in them
and so the key will not appear as words when displayed in a view

The solution

The last four lines of the six lines below are an addition to class
BEAUTIFY in file gluon\html.py and provides a solution.


if type(value) == types.LambdaType:
  continue
if isinstance(key, str):  # a key must be a string type
  if key[1]=='_':         # 'a_bcde_fghi' means 'bcde_fghi' is the key
to be shown
  key=key[2:]             # remove 'a_' from 'a_bcde_fghi'
  key=' '.join([x.capitalize() for x in key.split('_')])  # Converts
remaining 'bcde_fghi' to 'Bcde Fghi'

The code examines the second character of the key. If this character
is '_' it removes the first two characters. This means the single
characters A-Z, a-z and 0-9 are available to arbitrarily and
conveniently reorder presentation independent of alphabetic order, as
the first letter and the underscore following will be removed.

If the second character is '_', then the last line the of code
replaces remaining underscores with a space and capitalizes the
result.
Examples using view above


  return dict(cde_fgh='world', ijk_lmn='hello')
  cde_fgh: world
  ijk_lmn: hello

  return dict(b_cde_fgh='world', a_ijk_lmn='hello')
  Ijk Lmn: hello
  Cde Fgh: world

You can see an example of this technique in action at
http://www.zgus.com/zgus/products/category_item/1

The view page is the three line view page above.

The last statement of the category_item function is


  return stripped_dict(dict(
    a_product_category=item.title,
    b_custom=item.custom,
    d_products= _product_list,
    e_category_documentation=_document_list,
    f_video=_video_list,
    g_about=item.about,
    ))

As for the quality of the linked videos in the page, I received a
polite complaint from a senior executive of a well known corporation
about their poor quality! Their main purpose is to demonstrate I work
on further developing real product which is not yet ready to be
marketed!

John Heenan


On Feb 16, 12:52 pm, John Heenan <johnmhee...@gmail.com> wrote:
> I have just put up a new web2slice that includes a manual patch for
> the BEAUTIFY class. The entry is 
> athttp://www.web2pyslices.com/main/slices/take_slice/58
>
> I would like to propose that the patch or an equivalent one makes it
> way into the web2py trunk. If it does then I can change the web2py
> slice to be an effective and practical example of the use of the
> enhancement.
>
> Thanks
>
> John Heenan

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to