Back to index

plone3  3.1.7
mimetype_utils.py
Go to the documentation of this file.
00001 from Products.CMFCore.utils import getToolByName
00002 
00003 #
00004 # default- and allowable content type handling
00005 #
00006 
00007 def getDefaultContentType(context):
00008     portal_properties = getToolByName(context, 'portal_properties', None)
00009     site_properties = getattr(portal_properties, 'site_properties', None)
00010     return site_properties.getProperty('default_contenttype')
00011 
00012 def setDefaultContentType(context, value):
00013     portal_properties = getToolByName(context, 'portal_properties', None)
00014     site_properties = getattr(portal_properties, 'site_properties', None)
00015     site_properties.manage_changeProperties(default_contenttype=value)
00016         
00017 def getAllowedContentTypes(context):
00018     """ computes the list of allowed content types by subtracting the site property blacklist 
00019         from the list of installed types.
00020     """
00021     allowable_types = getAllowableContentTypes(context)
00022     forbidden_types = getForbiddenContentTypes(context)
00023     allowed_types = [type for type in allowable_types if type not in forbidden_types]
00024     return allowed_types
00025     
00026 def getAllowableContentTypes(context):
00027     """ retrieves the list of installed content types by querying portal transforms. """
00028     portal_transforms = getToolByName(context, 'portal_transforms')
00029     return portal_transforms.listAvailableTextInputs()
00030 
00031 def setForbiddenContentTypes(context, forbidden_contenttypes=[]):
00032     """ Convenience method for settng the site property 'forbidden_contenttypes'."""
00033     portal_properties = getToolByName(context, 'portal_properties', None)
00034     site_properties = getattr(portal_properties, 'site_properties', None)
00035     site_properties.manage_changeProperties(forbidden_contenttypes=tuple(forbidden_contenttypes))
00036 
00037 def getForbiddenContentTypes(context):
00038     """ Convenence method for retrevng the site property 'forbidden_contenttypes'."""
00039     portal_properties = getToolByName(context, 'portal_properties', None)
00040     site_properties = getattr(portal_properties, 'site_properties', None)
00041     if site_properties.hasProperty('forbidden_contenttypes'):
00042         return list(site_properties.getProperty('forbidden_contenttypes'))
00043     else:
00044         return []