Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
CMFDynamicViewFTI.fti.DynamicViewTypeInformation Class Reference
Inheritance diagram for CMFDynamicViewFTI.fti.DynamicViewTypeInformation:
Inheritance graph
[legend]
Collaboration diagram for CMFDynamicViewFTI.fti.DynamicViewTypeInformation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def manage_changeProperties
def getDefaultViewMethod
def getAvailableViewMethods
def getViewMethod
def getDefaultPage
def defaultView
def queryMethodID

Public Attributes

 default_view
 view_methods

Static Public Attributes

 meta_type = fti_meta_type
tuple security = ClassSecurityInfo()
string default_view = ''
tuple view_methods = ()
 default_view_fallback = False

Static Private Attributes

tuple __implements__ = (ZopeTwoIDynamicViewTypeInformation,)
tuple _properties

Detailed Description

FTI with dynamic views

A value of (dynamic view) as alias is replaced by the output of defaultView()

Definition at line 64 of file fti.py.


Member Function Documentation

Get the current view to use for an object. If a default page is  set,
use that, else use the currently selected view method/layout.

Definition at line 180 of file fti.py.

00180 
00181     def defaultView(self, context):
00182         """Get the current view to use for an object. If a default page is  set,
00183         use that, else use the currently selected view method/layout.
00184         """
00185 
00186         # Delegate to PloneTool's version if we have it else, use own rules
00187         plone_utils = getToolByName(self, 'plone_utils', None)
00188         if plone_utils is not None:
00189             obj, path = plone_utils.browserDefault(context)
00190             return path[-1]
00191         else:
00192             default_page = self.getDefaultPage(context, check_exists=True)
00193             if default_page is not None:
00194                 return default_page
00195             fallback = self.default_view_fallback
00196             return self.getViewMethod(context, check_exists=fallback)

Here is the call graph for this function:

Here is the caller graph for this function:

Get a list of registered view methods

Definition at line 114 of file fti.py.

00114 
00115     def getAvailableViewMethods(self, context):
00116         """Get a list of registered view methods
00117         """
00118         methods = self.view_methods
00119         if isinstance(methods, basestring):
00120             methods = (methods,)
00121         return tuple(methods)

Here is the caller graph for this function:

def CMFDynamicViewFTI.fti.DynamicViewTypeInformation.getDefaultPage (   self,
  context,
  check_exists = False 
)
Get the default page from a folderish object

Non folderish objects don't have a default view.

If check_exists is enabled the method makes sure the object with the default
page id exists.

Return -- None for no default page or a string

Definition at line 149 of file fti.py.

00149 
00150     def getDefaultPage(self, context, check_exists=False):
00151         """Get the default page from a folderish object
00152 
00153         Non folderish objects don't have a default view.
00154 
00155         If check_exists is enabled the method makes sure the object with the default
00156         page id exists.
00157 
00158         Return -- None for no default page or a string
00159         """
00160         if not getattr(aq_base(context), 'isPrincipiaFolderish', False):
00161             return None # non folderish objects don't have a default page per se
00162 
00163         default_page = getattr(aq_base(context), 'default_page', None)
00164 
00165         if safe_callable(default_page):
00166             default_page = default_page()
00167         if not default_page:
00168             return None
00169         if isinstance(default_page, (tuple, list)):
00170             default_page = default_page[0]
00171         if not isinstance(default_page, str):
00172             raise TypeError, ("default_page must be a string, got %s(%s):" %
00173                               (default_page, type(default_page)))
00174 
00175         if check_exists and not om_has_key(context, default_page):
00176             return None
00177 
00178         return default_page

Here is the call graph for this function:

Here is the caller graph for this function:

Get the default view method from the FTI

Definition at line 108 of file fti.py.

00108 
00109     def getDefaultViewMethod(self, context):
00110         """Get the default view method from the FTI
00111         """
00112         return str(self.default_view)

Here is the caller graph for this function:

def CMFDynamicViewFTI.fti.DynamicViewTypeInformation.getViewMethod (   self,
  context,
  enforce_available = False,
  check_exists = False 
)
Get view method (aka layout) name from context

Return -- view method from context or default view name

Definition at line 123 of file fti.py.

00123 
00124     def getViewMethod(self, context, enforce_available=False, check_exists=False):
00125         """Get view method (aka layout) name from context
00126 
00127         Return -- view method from context or default view name
00128         """
00129         default = self.getDefaultViewMethod(context)
00130         layout = getattr(aq_base(context), 'layout', None)
00131 
00132         if safe_callable(layout):
00133             layout = layout()
00134         if not layout:
00135             return default
00136         if not isinstance(layout, basestring):
00137             raise TypeError, "layout of %s must be a string, got %s" % (
00138                               repr(context), type(layout))
00139         if enforce_available:
00140             available = self.getAvailableViewMethods(context)
00141             if layout not in available:
00142                 return default
00143         if check_exists:
00144             method = getattr(context, layout, None)
00145             if method is None:
00146                 return default
00147         return layout

Here is the call graph for this function:

Here is the caller graph for this function:

Overwrite change properties to verify that default_view is in the method
list

Definition at line 92 of file fti.py.

00092 
00093     def manage_changeProperties(self, **kw):
00094         """Overwrite change properties to verify that default_view is in the method
00095         list
00096         """
00097         FactoryTypeInformation.manage_changeProperties(self, **kw)
00098         default_view = self.default_view
00099         view_methods = self.view_methods
00100         if not default_view:
00101             # TODO: use view action
00102             self.default_view = default_view = self.immediate_view
00103         if not view_methods:
00104             self.view_methods = view_methods = (default_view,)
00105         if default_view and default_view not in view_methods:
00106             raise ValueError, "%s not in %s" % (default_view, view_methods)

Here is the caller graph for this function:

def CMFDynamicViewFTI.fti.DynamicViewTypeInformation.queryMethodID (   self,
  alias,
  default = None,
  context = None 
)
Query method ID by alias.

Use "(dynamic view)" as the alias target to look up as per defaultView()
Use "(selected layout)" as the alias target to look up as per
    getViewMethod()

Definition at line 198 of file fti.py.

00198 
00199     def queryMethodID(self, alias, default=None, context=None):
00200         """ Query method ID by alias.
00201 
00202         Use "(dynamic view)" as the alias target to look up as per defaultView()
00203         Use "(selected layout)" as the alias target to look up as per
00204             getViewMethod()
00205         """
00206         methodTarget = FactoryTypeInformation.queryMethodID(self, alias,
00207                                                          default=default,
00208                                                          context=context)
00209         if not isinstance(methodTarget, basestring):
00210             # nothing to do, method_id is probably None
00211             return methodTarget
00212 
00213         if context is None or default == '':
00214             # the edit zpts like typesAliases don't apply a context and set the
00215             # default to ''. We do not want to resolve (dynamic view) for these
00216             # methods.
00217             return methodTarget
00218 
00219         # Our two special targets:
00220 
00221         if methodTarget.lower() == "(dynamic view)":
00222             methodTarget = self.defaultView(context)
00223 
00224         if methodTarget.lower() == "(selected layout)":
00225             fallback = self.default_view_fallback
00226             methodTarget = self.getViewMethod(context, check_exists=fallback)
00227 
00228         return methodTarget
00229 
00230 InitializeClass(DynamicViewTypeInformation)
00231 
00232 
00233 #def manage_addFactoryDynamivViewTIForm(self, REQUEST):
00234 #    """ Get the add form for factory-based type infos.
00235 #    """
00236 #    addTIForm = DTMLFile('addTypeInfo', _dtmldir).__of__(self)
00237 #    ttool = getToolByName(self, 'portal_types')
00238 #    return addTIForm( self, REQUEST,
00239 #                      add_meta_type=DynamicViewTypeInformation.meta_type,
00240 #                      types=ttool.listDefaultTypeInformation() )
00241 
00242 
00243 # BBB: the following lines are required to register the new FTI in CMF 1.5 and may
00244 # be removed after switching to CMF 1.6
try:

Here is the call graph for this function:


Member Data Documentation

tuple CMFDynamicViewFTI.fti.DynamicViewTypeInformation.__implements__ = (ZopeTwoIDynamicViewTypeInformation,) [static, private]

Definition at line 71 of file fti.py.

Initial value:
FactoryTypeInformation._properties+(
        { 'id': 'default_view', 'type': 'string', 'mode': 'w',
          'label': 'Default view method'
        },
        { 'id': 'view_methods', 'type': 'lines', 'mode': 'w',
          'label': 'Available view methods'
        },
        { 'id': 'default_view_fallback', 'type': 'boolean', 'mode': 'w',
          'label': 'Fall back to default view?'
        },
    )

Definition at line 76 of file fti.py.

Definition at line 88 of file fti.py.

Definition at line 101 of file fti.py.

Definition at line 90 of file fti.py.

Definition at line 73 of file fti.py.

tuple CMFDynamicViewFTI.fti.DynamicViewTypeInformation.security = ClassSecurityInfo() [static]

Definition at line 74 of file fti.py.

Definition at line 89 of file fti.py.

Definition at line 103 of file fti.py.


The documentation for this class was generated from the following file: