Back to index

plone3  3.1.7
browser.py
Go to the documentation of this file.
00001 from Products.Five.browser import BrowserView
00002 from zope.publisher.interfaces.browser import IBrowserRequest
00003 from zope.component import getSiteManager, getAllUtilitiesRegisteredFor
00004 from plone.browserlayer.interfaces import ILocalBrowserLayerType
00005 from Acquisition import aq_inner
00006 
00007 from plone.app.customerize import registration
00008 from five.customerize.interfaces import ITTWViewTemplate
00009 
00010 
00011 class RegistrationsView(BrowserView):
00012 
00013     def getTemplateViewRegistrations(self):
00014         """ get all global view registrations and cycle through the local
00015             ones to see which views have already been customized ttw """
00016         regs = []
00017         local = {}
00018         for reg in self.getLocalRegistrations():
00019             local[(reg.required, str(reg.name), str(reg.factory.name))] = reg
00020         for reg in registration.templateViewRegistrations():
00021             lreg = local.get((reg.required, str(reg.name), str(reg.ptname)), None)
00022             if lreg is not None:
00023                 regs.append(lreg)
00024             else:
00025                 regs.append(reg)
00026         return registration.templateViewRegistrationGroups(regs)  
00027 
00028     def getTemplateCodeFromRegistration(self):
00029         reg = self.getRegistrationFromRequest()
00030         return registration.getTemplateCodeFromRegistration(reg)
00031 
00032     def getTemplateViewRegistrationInfo(self):
00033         reg = self.getRegistrationFromRequest()
00034         return list(registration.templateViewRegistrationInfos([reg]))[0]
00035 
00036     def getRegistrationFromRequest(self):
00037         form = self.context.request.form
00038         return registration.findTemplateViewRegistration(form['required'],
00039             form['view_name'])
00040 
00041     def registerTTWView(self, viewzpt, reg):
00042         sm = getSiteManager(self.context)
00043         sm.registerAdapter(viewzpt, required = reg.required,
00044                            provided = reg.provided, name = reg.name)
00045 
00046     def customizeTemplate(self):
00047         reg = self.getRegistrationFromRequest()
00048         viewzpt = registration.customizeTemplate(reg)
00049         self.registerTTWView(viewzpt, reg)
00050         path = aq_inner(viewzpt).getPhysicalPath()
00051         url = self.request.physicalPathToURL(path) + "/manage_workspace"
00052         self.request.response.redirect(url)
00053 
00054     def getLocalRegistrations(self):
00055         layers = getAllUtilitiesRegisteredFor(ILocalBrowserLayerType)
00056         components = getSiteManager(self.context)
00057         for reg in components.registeredAdapters():
00058             if (len(reg.required) in (2, 4, 5) and
00059                    (reg.required[1].isOrExtends(IBrowserRequest) or
00060                     reg.required[1] in layers) and
00061                     ITTWViewTemplate.providedBy(reg.factory)):
00062                 yield reg
00063