Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Properties | Private Member Functions | Private Attributes
kupu.plone.plonedrawers.ResourceType Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def get_portal_types
def getQuery

Public Attributes

 name
 subObject
 klass

Properties

 portal_types = property(get_portal_types)
 allow_browse = property(_allow_browse)
 startup_directory = property(_startup_directory)

Private Member Functions

def _instanceFromRequest
def _allow_browse
def _startup_directory

Private Attributes

 _tool
 _portal_types
 _field
 _widget
 _instance

Detailed Description

Resource types are wrapped into a class so we can easily
access attributes which may, or may not be present.

Definition at line 58 of file plonedrawers.py.


Constructor & Destructor Documentation

def kupu.plone.plonedrawers.ResourceType.__init__ (   self,
  tool,
  name 
)

Definition at line 62 of file plonedrawers.py.

00062 
00063     def __init__(self, tool, name):
00064         self.name = name
00065         self._tool = tool
00066         parts = name.split('.', 1)
00067         self.subObject = None
00068 
00069         if len(parts)==1:
00070             self._portal_types = tool.queryPortalTypesForResourceType(name, ())
00071             self._field = self._widget = None
00072         else:
00073             # Must be portal_type.fieldname
00074             typename, fieldname = parts
00075             # Topic criteria have typename and fieldname embedded in
00076             # the criteria name.
00077             if fieldname.startswith('crit__'):
00078                 self.subObject = '_'.join(fieldname.split('_')[:-1])
00079                 typename, fieldname = fieldname.split('_')[-2:]
00080 
00081             __traceback_info__ = (parts, typename, fieldname)
00082             archetype_tool = getToolByName(tool, 'archetype_tool', None)
00083             types = archetype_tool.listRegisteredTypes()
00084             typeinfo = [t for t in types if t['portal_type']==typename]
00085 
00086             if len(typeinfo)==0:
00087                 raise KupuError("Unrecognised portal type for resource %s" % name)
00088 
00089             schema = typeinfo[0]['schema']
00090             self.klass = typeinfo[0]['klass']
00091             try:
00092                 self._field = schema[fieldname]
00093             except KeyError:
00094                 raise KupuError("Unrecognised fieldname for resource %s" % name)
00095                 
00096             self._widget = self._field.widget


Member Function Documentation

Definition at line 97 of file plonedrawers.py.

00097 
00098     def __repr__(self):
00099         return "<ResourceType %s %s %s %s %s" % (
00100             self.name,
00101             self.portal_types, self.getQuery(), self.allow_browse, self.startup_directory
00102             )

Here is the call graph for this function:

Definition at line 164 of file plonedrawers.py.

00164 
00165     def _allow_browse(self):
        return getattr(self._widget, 'allow_browse', True)
Get instance object from UID in request.
Throws an error if there isn't a UID.

Definition at line 144 of file plonedrawers.py.

00144 
00145     def _instanceFromRequest(self):
00146         """Get instance object from UID in request.
00147         Throws an error if there isn't a UID.
00148         """
00149         if not hasattr(self, '_instance'):
00150             # XXX TODO: this needs to handle the case where the object is
00151             # being created through portal_factory and hasn't yet been
00152             # saved. The UID won't be in the catalog so we need to create
00153             # a dummy object instead.
00154             tool = self._tool
00155             UID = tool.REQUEST.get('instance', None)
00156             if UID is None:
00157                 return None
00158             reference_tool = getToolByName(tool, 'reference_catalog')
00159             self._instance = reference_tool.lookupObject(UID)
00160         if self.subObject:
00161             return self._instance[self.subObject]
00162 
00163         return self._instance

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 168 of file plonedrawers.py.

00168 
00169     def _startup_directory(self):
        return getattr(self._widget, 'startup_directory', '')

Definition at line 103 of file plonedrawers.py.

00103 
00104     def get_portal_types(self):
00105         if not hasattr(self, '_portal_types'):
00106             field = self._field
00107             allowed_types = getattr(field, 'allowed_types', ())
00108 
00109             if allowed_types == ():
00110                 dr = self._tool.getDefaultResource()
00111                 allowed_types = self._tool.getResourceType(dr).portal_types
00112 
00113             allow_method = getattr(field, 'allowed_types_method', None)
00114             if allow_method is not None:
00115                 instance = self._instanceFromRequest()
00116                 if instance:
00117                     meth = getattr(instance, allow_method)
00118                     allowed_types = meth()
00119             self._portal_types = allowed_types
00120 
        return self._portal_types

Here is the call graph for this function:

Definition at line 123 of file plonedrawers.py.

00123 
00124     def getQuery(self):
00125         query = {'portal_type': self.portal_types }
00126         
00127         if self._field is not None:
00128             field = self._field
00129             widget = field.widget
00130             base_query = getattr(widget, 'base_query', None)
00131             if base_query and isinstance(base_query, basestring):
00132                 # We need the actual object containing the field to be
00133                 # able to call a dynamic base_query
00134                 instance = self._instanceFromRequest()
00135                 if instance:
00136                     base_query = getattr(instance, base_query, None)
00137                     if base_query:
00138                        base_query = base_query()
00139                        
00140             if base_query:
00141                 query.update(base_query)
00142 
00143         return query

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 70 of file plonedrawers.py.

Definition at line 158 of file plonedrawers.py.

Definition at line 69 of file plonedrawers.py.

Definition at line 64 of file plonedrawers.py.

Definition at line 70 of file plonedrawers.py.

Definition at line 89 of file plonedrawers.py.

Definition at line 63 of file plonedrawers.py.

Definition at line 66 of file plonedrawers.py.


Property Documentation

Definition at line 166 of file plonedrawers.py.

Definition at line 121 of file plonedrawers.py.

Definition at line 170 of file plonedrawers.py.


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