[Erp5-dev] Categories by example cheat-sheet creator script

Łukasz K. Nowak lukasz.nowak at ventis.com.pl
Thu May 17 11:04:50 CEST 2007


Hello,

For some time I'm playing a lot with portal_categories. As I wasn't able
to find reference card for functions based on categories I've created
little cheat-sheet which could be used as a reference card or training
material.

Category definition:
[{'relpath':'Title'},]

[
  {'example' : 'Example'},
  {'example/colour' : 'Colour'},
  {'example/colour/blue' : 'Blue'},
  {'example/colour/green' : 'Green'},
  {'example/colour/red' : 'Red'},
  {'example/size' : 'Size'},
  {'example/size/large' : 'Large'},
  {'example/size/large/l' : 'L'},
  {'example/size/large/xl' : 'XL'},
  {'example/size/large/xxl' : 'XXL'},
  {'example/size/medium' : 'Medium'},
  {'example/size/medium/m' : 'M'},
  {'example/size/small' : 'Small'},
  {'example/size/small/s' : 'S'},
  {'example/size/small/xs' : 'XS'},
  {'example/size/small/xxs': 'XXS'},
]

Proposed TODOs are in attached file.

Luke

-- 
Łukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''

-------------- next part --------------
## Script (Python) "BaseCategory_accessorsByExample"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
"""
Author: Łukasz K. Nowak <lukasz.nowak at ventis.com.pl>

Cheat-sheet script

TODO:
 - automagic creationg of categories
 - implementation of filling Localizer, to show difference of *Translated* functions
 - extending/reimplementation of dicts passed to functions
 - some filtering
 - more automagic, eg. fetch all get functions, guess cartesian-matrix of dict (dunno if it is possible from ZOSB python script)
 - extend for from-object-category-accessors, http://www.erp5.org/Discussion/CategoryAccessor
"""

example_category = context.portal_categories.example

# function_list is list of tuples of name and list of dicts passed to function
function_list = [
  ( 'getLogicalPath', [{},{'item_method':'getId'}] ),
  ( 'getTranslatedLogicalPath', [{},] ),
  ( 'getIndentedTitle', [{},] ),
  ( 'getCategoryRelativeUrl', [{},] ),
  ( 'getRelativeUrl', [{},] ),
  ( 'getCategoryMemberValueList', [{},] ),
  ( 'getBreadcrumbList', [{},] ),
  ( 'getBaseCategoryId', [{},] ),
  ( 'getBaseCategoryUid', [{},] ),
  ( 'getBaseCategoryValue', [{},] ),
  ( 'getCategoryChildValueList', [{},{'recursive':'0'},{'include_if_child':'0'},{'is_self_excluded':1}] ),
  ( 'getCategoryChildRelativeUrlList', [{},] ),
  ( 'getCategoryChildTitleItemList', [{},] ),
  ( 'getCategoryChildTranslatedTitleItemList', [{},] ),
  ( 'getCategoryChildTitleOrIdItemList', [{},] ),
  ( 'getCategoryChildTitleAndIdItemList', [{},] ),
  ( 'getCategoryChildLogicalPathItemList', [{},] ),
  ( 'getCategoryChildTranslatedLogicalPathItemList', [{},] ),
  ( 'getCategoryChildIndentedTitleItemList', [{},] ),
  ( 'getCategoryChildIdItemList', [{},] ),
  ( 'getCategoryChildItemList', [{},] ),
  ( 'getCategoryMemberItemList', [{},] ),
  ( 'getCategoryMemberTitleItemList', [{},] ),
  ( 'getCategoryChildValueList', [{},] ),
]

for category in example_category.getCategoryMemberValueList():
  print '%s::'%(category.getRelativeUrl(),)
  for (function,invocation_list) in function_list:
    print '\t%s:'%(function,)
    for invocation_dict in invocation_list:
      print '\t\t%s:'%(invocation_dict,)
      print '\t\t\t%s'%(getattr(category,function)(**invocation_dict),)
return printed


More information about the Erp5-dev mailing list