Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes
ATContentTypes.lib.constraintypes.ConstrainTypesMixin Class Reference

List of all members.

Public Member Functions

def validate_preferredTypes
def getLocallyAllowedTypes
def getImmediatelyAddableTypes
def allowedContentTypes
def invokeFactory
def getDefaultAddableTypes
def canSetConstrainTypes

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Member Functions

def _ct_vocabularyPossibleTypes
def _ct_defaultAddableTypeIds
def _ct_defaultConstrainTypesMode

Static Private Attributes

tuple __implements__ = (ZopeTwoISelectableConstrainTypes, )

Detailed Description

Gives the user with given rights the possibility to
    constrain the addable types on a per-folder basis.

Definition at line 154 of file constraintypes.py.


Member Function Documentation

Get a list of types which are addable in the ordinary case w/o the
constraint machinery.

Definition at line 337 of file constraintypes.py.

00337 
00338     def _ct_defaultAddableTypeIds(self):
00339         """Get a list of types which are addable in the ordinary case w/o the
00340         constraint machinery.
00341         """
00342         return [fti.getId() for fti in self.getDefaultAddableTypes()]

Here is the call graph for this function:

Configure constrainTypeMode depending on the parent

ACQUIRE if parent support ISelectableConstrainTypes
DISABLE if not

Definition at line 343 of file constraintypes.py.

00343 
00344     def _ct_defaultConstrainTypesMode(self):
00345        """Configure constrainTypeMode depending on the parent
00346 
00347        ACQUIRE if parent support ISelectableConstrainTypes
00348        DISABLE if not
00349        """
00350        portal_factory = getToolByName(self, 'portal_factory', None)
00351        if portal_factory is not None and portal_factory.isTemporary(self):
00352            # created by portal_factory
00353            parent = aq_parent(aq_parent(aq_parent(aq_inner(self))))
00354        else:
00355            parent = aq_parent(aq_inner(self))
00356 
00357        if ISelectableConstrainTypes.providedBy(parent) and parentPortalTypeEqual(self):
00358            return ACQUIRE
00359        else:
00360            return DISABLED
00361 
00362 InitializeClass(ConstrainTypesMixin)

Here is the call graph for this function:

Get a DisplayList of types which may be added (id -> title)

Definition at line 327 of file constraintypes.py.

00327 
00328     def _ct_vocabularyPossibleTypes(self):
00329         """Get a DisplayList of types which may be added (id -> title)
00330         """
00331         typelist = [(fti.title_or_id(), fti.getId())
00332                      for fti in self.getDefaultAddableTypes()]
00333         typelist.sort()
00334         return DisplayList([(id, title) for title, id in typelist])

Here is the call graph for this function:

returns constrained allowed types as list of fti's

Definition at line 243 of file constraintypes.py.

00243 
00244     def allowedContentTypes(self, context=None):
00245         """returns constrained allowed types as list of fti's
00246         """
00247         if context is None:
00248             context=self
00249         mode = self.getConstrainTypesMode()
00250 
00251         # Short circuit if we are disabled or acquiring from non-compatible
00252         # parent
00253 
00254         #if mode == DISABLED or \
00255         #        (parent and parent.portal_types != self.portal_types):
00256         if mode == DISABLED or \
00257                 (mode == ACQUIRE and not parentPortalTypeEqual(self) ):
00258             return PortalFolder.allowedContentTypes(self)
00259 
00260         globalTypes = self.getDefaultAddableTypes(context)
00261         allowed = list(self.getLocallyAllowedTypes())
00262         ftis = [ fti for fti in globalTypes if fti.getId() in allowed ]
00263 
00264         return ftis
00265 

Here is the call graph for this function:

Here is the caller graph for this function:

Find out if the current user is allowed to set the allowable types

Definition at line 314 of file constraintypes.py.

00314 
00315     def canSetConstrainTypes(self):
00316         """Find out if the current user is allowed to set the allowable types
00317         """
00318         mtool = getToolByName(self, 'portal_membership')
00319         member = mtool.getAuthenticatedMember()
00320         return member.has_permission(ATCTPermissions.ModifyConstrainTypes, self)

Here is the call graph for this function:

returns a list of normally allowed objects as ftis.
Exactly like PortalFolder.allowedContentTypes except this
will check in a specific context.

Definition at line 292 of file constraintypes.py.

00292 
00293     def getDefaultAddableTypes(self, context=None):
00294         """returns a list of normally allowed objects as ftis.
00295         Exactly like PortalFolder.allowedContentTypes except this
00296         will check in a specific context.
00297         """
00298         if context is None:
00299             context = self
00300 
00301         result = []
00302         portal_types = getToolByName(self, 'portal_types')
00303         myType = portal_types.getTypeInfo(self)
00304         if myType is not None:
00305             for contentType in portal_types.listTypeInfo(context):
00306                 if myType.allowType( contentType.getId() ):
00307                     result.append( contentType )
00308         else:
00309             result = portal_types.listTypeInfo()
00310 
00311         return [ t for t in result if t.isConstructionAllowed(context) ]
00312 

Here is the call graph for this function:

Here is the caller graph for this function:

Get the list of type ids which should be immediately addable.
If enableTypeRestrictions is ENABLE, return the list set; if it is
ACQUIRE, use the value from the parent; if it is DISABLE, return
all type ids allowable on the item.

Definition at line 216 of file constraintypes.py.

00216 
00217     def getImmediatelyAddableTypes(self, context=None):
00218         """Get the list of type ids which should be immediately addable.
00219         If enableTypeRestrictions is ENABLE, return the list set; if it is
00220         ACQUIRE, use the value from the parent; if it is DISABLE, return
00221         all type ids allowable on the item.
00222         """
00223         if context is None:
00224             context=self
00225         mode = self.getConstrainTypesMode()
00226 
00227         if mode == DISABLED:
00228             return [fti.getId() for fti in \
00229                         self.getDefaultAddableTypes(context)]
00230         elif mode == ENABLED:
00231             return self.getField('immediatelyAddableTypes').get(self)
00232         elif mode == ACQUIRE:
00233             #if not parent or parent.portal_type != self.portal_type:
00234             if not parentPortalTypeEqual(self):
00235                 return [fti.getId() for fti in \
00236                         PortalFolder.allowedContentTypes(self)]
00237             else:
00238                 parent = aq_parent(aq_inner(self))
00239                 return parent.getImmediatelyAddableTypes(context)
00240         else:
00241             raise ValueError, "Invalid value for enableAddRestriction"

Here is the call graph for this function:

If enableTypeRestrictions is ENABLE, return the list of types
set. If it is ACQUIRE, get the types set on the parent so long
as the parent is of the same type - if not, use the same behaviuor as
DISABLE: return the types allowable in the item.

Definition at line 187 of file constraintypes.py.

00187 
00188     def getLocallyAllowedTypes(self, context=None):
00189         """If enableTypeRestrictions is ENABLE, return the list of types
00190         set. If it is ACQUIRE, get the types set on the parent so long
00191         as the parent is of the same type - if not, use the same behaviuor as
00192         DISABLE: return the types allowable in the item.
00193         """
00194         if context is None:
00195             context=self
00196         mode = self.getConstrainTypesMode()
00197 
00198         if mode == DISABLED:
00199             return [fti.getId() for fti in self.getDefaultAddableTypes(context)]
00200         elif mode == ENABLED:
00201             return self.getField('locallyAllowedTypes').get(self)
00202         elif mode == ACQUIRE:
00203             #if not parent or parent.portal_type != self.portal_type:
00204             if not parentPortalTypeEqual(self):
00205                 return [fti.getId() for fti in self.getDefaultAddableTypes(context)]
00206             else:
00207                 parent = aq_parent(aq_inner(self))
00208                 if ISelectableConstrainTypes.providedBy(parent):
00209                     return parent.getLocallyAllowedTypes(context)
00210                 else:
00211                     return parent.getLocallyAllowedTypes()
00212         else:
00213             raise ValueError, "Invalid value for enableAddRestriction"
00214 

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.lib.constraintypes.ConstrainTypesMixin.invokeFactory (   self,
  type_name,
  id,
  RESPONSE = None,
  args,
  kw 
)
Invokes the portal_types tool

Definition at line 268 of file constraintypes.py.

00268 
00269     def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
00270         """Invokes the portal_types tool
00271         """
00272         mode = self.getConstrainTypesMode()
00273 
00274         # Short circuit if we are disabled or acquiring from non-compatible
00275         # parent
00276 
00277         #if mode == DISABLED or \
00278         #        (parent and parent.portal_types != self.portal_types):
00279         if mode == DISABLED or \
00280                  (mode == ACQUIRE and not parentPortalTypeEqual(self) ):
00281             return PortalFolder.invokeFactory(self, type_name, id,
00282                                                 RESPONSE=None, *args, **kw)
00283 
00284         if not type_name in [fti.getId() for fti in self.allowedContentTypes()]:
00285             raise Unauthorized('Disallowed subobject type: %s' % type_name)
00286 
00287         pt = getToolByName( self, 'portal_types' )
00288         args = (type_name, self, id, RESPONSE) + args
00289         return pt.constructContent(*args, **kw)
00290 

Here is the call graph for this function:

Here is the caller graph for this function:

Ensure that the preferred types is a subset of the allowed types.

Definition at line 167 of file constraintypes.py.

00167 
00168     def validate_preferredTypes(self, value):
00169         """Ensure that the preferred types is a subset of the allowed types.
00170         """
00171         allowed = self.getField('locallyAllowedTypes').get(self)
00172         preferred = value.split('\n')
00173 
00174         disallowed = []
00175         for p in preferred:
00176             if not p in allowed:
00177                 disallowed.append(p)
00178 
00179         if disallowed:
00180             return "The following types are not permitted: %s" % \
00181                         ','.join(disallowed)

Here is the call graph for this function:


Member Data Documentation

tuple ATContentTypes.lib.constraintypes.ConstrainTypesMixin.__implements__ = (ZopeTwoISelectableConstrainTypes, ) [static, private]

Definition at line 159 of file constraintypes.py.

Definition at line 161 of file constraintypes.py.


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