/
browser.py
63 lines (52 loc) · 2.62 KB
/
browser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from Products.Five.browser import BrowserView
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.component import getSiteManager, getAllUtilitiesRegisteredFor
from plone.browserlayer.interfaces import ILocalBrowserLayerType
from Acquisition import aq_inner
from plone.app.customerize import registration
from five.customerize.interfaces import ITTWViewTemplate
class RegistrationsView(BrowserView):
def getTemplateViewRegistrations(self, mangle=True):
""" get all global view registrations and cycle through the local
ones to see which views have already been customized ttw """
regs = []
local = {}
for reg in self.getLocalRegistrations():
local[(reg.required, str(reg.name), str(reg.factory.name))] = reg
for reg in registration.templateViewRegistrations():
lreg = local.get((reg.required, str(reg.name), str(reg.ptname)), None)
if lreg is not None:
regs.append(lreg)
else:
regs.append(reg)
return registration.templateViewRegistrationGroups(regs, mangle=mangle)
def getTemplateCodeFromRegistration(self):
reg = self.getRegistrationFromRequest()
return registration.getTemplateCodeFromRegistration(reg)
def getTemplateViewRegistrationInfo(self):
reg = self.getRegistrationFromRequest()
return list(registration.templateViewRegistrationInfos([reg]))[0]
def getRegistrationFromRequest(self):
form = self.request.form
return registration.findTemplateViewRegistration(form['required'],
form['view_name'])
def registerTTWView(self, viewzpt, reg):
sm = getSiteManager(self.context)
sm.registerAdapter(viewzpt, required = reg.required,
provided = reg.provided, name = reg.name)
def customizeTemplate(self):
reg = self.getRegistrationFromRequest()
viewzpt = registration.customizeTemplate(reg)
self.registerTTWView(viewzpt, reg)
path = aq_inner(viewzpt).getPhysicalPath()
url = self.request.physicalPathToURL(path) + "/manage_workspace"
self.request.response.redirect(url)
def getLocalRegistrations(self):
layers = getAllUtilitiesRegisteredFor(ILocalBrowserLayerType)
components = getSiteManager(self.context)
for reg in components.registeredAdapters():
if (len(reg.required) in (2, 4, 5) and
(reg.required[1].isOrExtends(IBrowserRequest) or
reg.required[1] in layers) and
ITTWViewTemplate.providedBy(reg.factory)):
yield reg