Back to index

plone3  3.1.7
ArchTTWTool.py
Go to the documentation of this file.
00001 import os
00002 
00003 from AccessControl import ClassSecurityInfo
00004 from Globals import InitializeClass
00005 from OFS.Folder import Folder
00006 from Products.CMFCore.utils import UniqueObject
00007 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00008 
00009 _www = os.path.join(os.path.dirname(__file__), 'www')
00010 
00011 class ArchTTWTool(UniqueObject, Folder):
00012     """ Archetypes TTW Tool """
00013 
00014     id = 'archetypes_ttw_tool'
00015     meta_type = 'Archetypes TTW Tool'
00016 
00017     security = ClassSecurityInfo()
00018     meta_types = all_meta_types = (())
00019 
00020     manage_options=(
00021         (Folder.manage_options[0],) +
00022         (
00023         { 'label'  : 'Introspect',
00024           'action' : 'manage_debugForm',
00025           },
00026 
00027         )
00028         + Folder.manage_options[1:]
00029         )
00030 
00031     fields_template = PageTemplateFile('fields_xml', _www)
00032     widgets_template = PageTemplateFile('widgets_xml', _www)
00033     storages_template = PageTemplateFile('storages_xml', _www)
00034     validators_template = PageTemplateFile('validators_xml', _www)
00035     types_template = PageTemplateFile('types_xml', _www)
00036     type_template = PageTemplateFile('type_xml', _www)
00037     registry_template = PageTemplateFile('registry_xml', _www)
00038 
00039     def fields(self):
00040         from Registry import availableFields
00041         fields = [v for k, v in availableFields()]
00042         return fields
00043 
00044     security.declarePublic('fields_xml')
00045     def fields_xml(self):
00046         """ Return XML representation of the field registry """
00047         fields = self.fields()
00048         return self.fields_template(fields=fields)
00049 
00050     def widgets(self):
00051         from Registry import availableWidgets
00052         widgets = [v for k, v in availableWidgets()]
00053         return widgets
00054 
00055     security.declarePublic('widgets_xml')
00056     def widgets_xml(self):
00057         """ Return XML representation of the widget registry """
00058         widgets = self.widgets()
00059         return self.widgets_template(widgets=widgets)
00060 
00061     def storages(self):
00062         from Registry import availableStorages
00063         storages = [v for k, v in availableStorages()]
00064         return storages
00065 
00066     security.declarePublic('storages_xml')
00067     def storages_xml(self):
00068         """ Return XML representation of the storage registry """
00069         storages = self.storages()
00070         return self.storages_template(storages=storages)
00071 
00072     def validators(self):
00073         from Registry import availableValidators
00074         validators = [v for k, v in availableValidators()]
00075         return validators
00076 
00077     security.declarePublic('validators_xml')
00078     def validators_xml(self):
00079         """ Return XML representation of the validators registry """
00080         validators = self.validators()
00081         return self.validators_template(validators=validators)
00082 
00083     def types(self):
00084         from Registry import availableTypes
00085         types = [v for k, v in availableTypes()]
00086         return types
00087 
00088     security.declarePublic('types_xml')
00089     def types_xml(self):
00090         """ Return XML representation of the types registry """
00091         types = self.types()
00092         return self.types_template(types=types)
00093 
00094     security.declarePublic('registry_xml')
00095     def registry_xml(self):
00096         """ Return XML representation of the wholeregistry """
00097         options = {}
00098         options['fields'] = self.fields()
00099         options['widgets'] = self.widgets()
00100         options['storages'] = self.storages()
00101         options['validators'] = self.validators()
00102         options['types'] = self.types()
00103         return self.registry_template(**options)
00104 
00105     security.declarePublic('type_xml')
00106     def type_xml(self):
00107         """ Return XML representation of one type from the registry """
00108         type = self.REQUEST.get('type', '')
00109         if not type:
00110             raise ValueError, 'Type is not valid'
00111         from Products.Archetypes.Registry import typeDescriptionRegistry
00112         type = typeDescriptionRegistry[type]
00113         return self.type_template(type=type)
00114 
00115 
00116 InitializeClass(ArchTTWTool)