Back to index

plone3  3.1.7
prepare_slots.py
Go to the documentation of this file.
00001 ## Script (Python) "prepare_slots"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=
00008 ##title=generate a mapping based on the context slots
00009 ##
00010 #prepare a structure that makes it conveient to determine
00011 #if we want to use-macro or render the path expression.
00012 #the values for the dictioanries is a list of tuples
00013 #that are path expressions and the second value is a
00014 #1 for use-macro
00015 #0 for render path expression
00016 context.plone_log("The prepare_slots script is deprecated and will be "
00017                   "removed in Plone 4.0.  If you are using this directly, "
00018                   "you are probably doing something very wrong.")
00019 
00020 from AccessControl import Unauthorized
00021 
00022 slots={ 'left':[],
00023         'right':[],
00024         'document_actions':[] }
00025 
00026 try:
00027     left_slots=getattr(context,'left_slots', [])
00028 except Unauthorized:
00029     # maybe not authorized when acquired from parent folders
00030     left_slots=[]
00031 
00032 try:
00033     right_slots=getattr(context,'right_slots', [])
00034 except Unauthorized:
00035     right_slots=[]
00036 
00037 try:
00038     document_action_slots=getattr(context,'document_action_slots', [])
00039 except Unauthorized:
00040     document_action_slots=[]
00041 
00042 #check if the *_slots attributes are callable so that they can be overridden
00043 #by methods or python scripts
00044 
00045 if callable(left_slots):
00046     left_slots=left_slots()
00047 
00048 if callable(right_slots):
00049     right_slots=right_slots()
00050 
00051 if callable(document_action_slots):
00052     document_action_slots=document_action_slots()
00053 
00054 for slot in left_slots:
00055     if not slot: continue
00056     if slot.find('/macros/')!=-1:
00057         slots['left'].append( (slot, 1) )
00058     else:
00059         slots['left'].append( (slot, 0) )
00060 
00061 for slot in right_slots:
00062     if not slot: continue
00063     if slot.find('/macros/')!=-1:
00064         slots['right'].append( (slot, 1) )
00065     else:
00066         slots['right'].append( (slot, 0) )
00067 
00068 for slot in document_action_slots:
00069     if not slot: continue
00070     if slot.find('/macros/')!=-1:
00071         slots['document_actions'].append( (slot, 1) )
00072     else:
00073         slots['document_actions'].append( (slot, 0) )
00074 
00075 return slots