Back to index

plone3  3.1.7
Functions
plone.app.customerize.registration Namespace Reference

Functions

def getViews
def interfaceName
def templateViewRegistrations
def templateViewRegistrationInfos
def templateViewRegistrationGroups
def findTemplateViewRegistration
def generateIdFromRegistration
def getViewClassFromRegistration
def getTemplateCodeFromRegistration
def getViewPermissionFromRegistration
def createTTWViewTemplate
def customizeTemplate

Function Documentation

Definition at line 135 of file registration.py.

00135 
00136 def createTTWViewTemplate(reg):
00137     attr, pt = findViewletTemplate(reg.factory)
00138     if pt:
00139         ptname = basename(pt.filename)
00140     else:
00141         ptname = None
00142     return TTWViewTemplate(
00143         id = str(generateIdFromRegistration(reg)),
00144         text = getTemplateCodeFromRegistration(reg),
00145         view = getViewClassFromRegistration(reg),
00146         permission = getViewPermissionFromRegistration(reg),
00147         name = ptname)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 148 of file registration.py.

00148 
00149 def customizeTemplate(reg):
00150     viewzpt = createTTWViewTemplate(reg)
00151     container = getUtility(IViewTemplateContainer)
00152     return container.addTemplate(viewzpt.getId(), viewzpt)
00153 

Here is the call graph for this function:

Definition at line 97 of file registration.py.

00097 
00098 def findTemplateViewRegistration(required, viewname):
00099     required = required.split(',')
00100     for reg in templateViewRegistrations():
00101         if required == [interfaceName(r) for r in reg.required]:
00102             if reg.name == viewname or reg.provided.isOrExtends(IPortletRenderer):
00103                 return reg

Here is the call graph for this function:

Definition at line 104 of file registration.py.

00104 
00105 def generateIdFromRegistration(reg):
00106     return '%s-%s' % (
00107         interfaceName(reg.required[0]).lower(),
00108         reg.name or reg.ptname
00109     )

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 123 of file registration.py.

00123 
00124 def getTemplateCodeFromRegistration(reg):
00125     attr, template = findViewletTemplate(reg.factory)
00126     # TODO: we can't do template.read() here because of a bug in
00127     # Zope 3's ZPT implementation.
00128     return open(template.filename, 'rb').read()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file registration.py.

00110 
00111 def getViewClassFromRegistration(reg):
00112     # The view class is generally auto-generated, we usually want
00113     # the first base class, though if the view only has one base
00114     # (generally object or BrowserView) we return the full class
00115     # and hope that it can be pickled
00116     if IPortletRenderer.implementedBy(reg.factory):
00117         return reg.factory
00118     klass = reg.factory
00119     base = klass.__bases__[0]
00120     if base is BrowserView or base is object:
00121         return klass
00122     return base

Here is the caller graph for this function:

Definition at line 129 of file registration.py.

00129 
00130 def getViewPermissionFromRegistration(reg):
00131     permissions = getattr(reg.factory, '__ac_permissions__', [])
00132     for permission, methods in permissions:
00133         if methods[0] in ('', '__call__'):
00134             return permission

Here is the caller graph for this function:

get all view registrations (stolen from zope.app.apidoc.presentation),
    both global and those registered for a specific layer 

Definition at line 15 of file registration.py.

00015 
00016 def getViews(type):
00017     """ get all view registrations (stolen from zope.app.apidoc.presentation),
00018         both global and those registered for a specific layer """
00019         
00020     # A zope 3 view is any multi-adapter whose second requirement is a browser request,
00021     # or derivation thereof.  We also do an explicit check for interfaces that have
00022     # been registered as plone.browserlayer browser layers, because often these
00023     # do not extend IBrowserRequest even though they should.
00024     layers = getAllUtilitiesRegisteredFor(ILocalBrowserLayerType)
00025     gsm = getGlobalSiteManager()
00026     for reg in gsm.registeredAdapters():
00027         if (len(reg.required) > 1 and
00028                 reg.required[1] is not None and
00029                (reg.required[1].isOrExtends(type) or
00030                 reg.required[1] in layers)):
00031             yield reg

Here is the caller graph for this function:

return a sensible name for the given interface 

Definition at line 32 of file registration.py.

00032 
00033 def interfaceName(iface):
00034     """ return a sensible name for the given interface """
00035     name = getattr(iface, '__name__', repr(iface))
00036     return getattr(iface, '__identifier__', name)

Here is the caller graph for this function:

Definition at line 86 of file registration.py.

00086 
00087 def templateViewRegistrationGroups(regs):
00088     ifaces = {}
00089     comp = lambda a,b: cmp(a['viewname'], b['viewname'])
00090     for reg in sorted(templateViewRegistrationInfos(regs), cmp=comp):
00091         key = reg['for']
00092         if ifaces.has_key(key):
00093             ifaces[key]['views'].append(reg)
00094         else:
00095             ifaces[key] = { 'name': key, 'views': [reg] }
00096     return sorted(ifaces.values(), cmp=lambda a,b: cmp(a['name'], b['name']))

Here is the call graph for this function:

Definition at line 59 of file registration.py.

00059 
00060 def templateViewRegistrationInfos(regs):
00061     for reg in regs:
00062         if ITTWViewTemplate.providedBy(reg.factory):
00063             zptfile = None
00064             zcmlfile = None
00065             name = reg.name or reg.factory.name
00066             customized = reg.factory.getId()    # TODO: can we get an absolute url?
00067         else:
00068             attr, pt = findViewletTemplate(reg.factory)
00069             if attr is None:        # skip, if the factory has no template...
00070                 continue
00071             zptfile = mangleAbsoluteFilename(pt.filename)
00072             zcmlfile = getattr(reg.info, 'file', None)
00073             zcmlfile = zcmlfile and mangleAbsoluteFilename(zcmlfile)
00074             name = reg.name or basename(zptfile)
00075             customized = None
00076         required = [interfaceName(r) for r in reg.required]
00077         yield {
00078             'viewname': name,
00079             'required': ','.join(required),
00080             'for': required[0],
00081             'type': required[1],
00082             'zptfile': zptfile,
00083             'zcmlfile': zcmlfile or 'n.a.',
00084             'customized': customized,
00085         }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 37 of file registration.py.

00037 
00038 def templateViewRegistrations():
00039     regs = []
00040     for reg in getViews(IBrowserRequest):
00041         factory = reg.factory
00042         while hasattr(factory, 'factory'):
00043             factory = factory.factory
00044         # TODO: this should really be dealt with using
00045         # a marker interface on the view factory
00046         name = getattr(factory, '__name__', '')
00047         if name.startswith('SimpleViewClass') or \
00048                 name.startswith('SimpleViewletClass') or \
00049                 name.endswith('Viewlet') or \
00050                 IViewlet.implementedBy(factory) or \
00051                 IPortletRenderer.implementedBy(factory):
00052             attr, pt = findViewletTemplate(factory)
00053             if pt:
00054                 reg.ptname = basename(pt.filename)
00055             else:
00056                 reg.ptname = None
00057             regs.append(reg)
00058     return regs

Here is the call graph for this function:

Here is the caller graph for this function: