1 | from Acquisition import aq_inner |
---|
2 | from plone.app.controlpanel.form import ControlPanelView |
---|
3 | |
---|
4 | from Products.CMFCore.utils import getToolByName |
---|
5 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
6 | |
---|
7 | class SEOControlPanel( ControlPanelView ): |
---|
8 | """ |
---|
9 | """ |
---|
10 | template = ViewPageTemplateFile('templates/seo_controlpanel.pt') |
---|
11 | |
---|
12 | @property |
---|
13 | def portal_properties( self ): |
---|
14 | """ |
---|
15 | """ |
---|
16 | context = aq_inner(self.context) |
---|
17 | return getToolByName(context, 'portal_properties') |
---|
18 | |
---|
19 | @property |
---|
20 | def portal_types( self ): |
---|
21 | """ |
---|
22 | """ |
---|
23 | context = aq_inner(self.context) |
---|
24 | return getToolByName(context, 'portal_types') |
---|
25 | |
---|
26 | def hasSEOAction( self, type_info ): |
---|
27 | """ |
---|
28 | """ |
---|
29 | return filter(lambda x:x.id == 'seo_properties', type_info.listActions()) |
---|
30 | |
---|
31 | def test( self, condition, first, second ): |
---|
32 | """ |
---|
33 | """ |
---|
34 | return condition and first or second |
---|
35 | |
---|
36 | def getExposeDCMetaTags( self ): |
---|
37 | """ |
---|
38 | """ |
---|
39 | sp = self.portal_properties.site_properties |
---|
40 | return sp.getProperty('exposeDCMetaTags') |
---|
41 | |
---|
42 | def getDefaultCustomMetatags( self ): |
---|
43 | """ |
---|
44 | """ |
---|
45 | seo = self.portal_properties.seo_properties |
---|
46 | return seo.getProperty('default_custom_metatags') |
---|
47 | |
---|
48 | def getAdditionalKeywords( self ): |
---|
49 | """ |
---|
50 | """ |
---|
51 | seo = self.portal_properties.seo_properties |
---|
52 | return seo.getProperty('additional_keywords') |
---|
53 | |
---|
54 | def createMultiColumnList( self ): |
---|
55 | """ |
---|
56 | """ |
---|
57 | context = aq_inner(self.context) |
---|
58 | allTypes = self.portal_types.listContentTypes() |
---|
59 | try: |
---|
60 | return context.createMultiColumnList(allTypes, sort_on='title_or_id') |
---|
61 | except AttributeError: |
---|
62 | return [slist] |
---|
63 | |
---|
64 | def __call__( self ): |
---|
65 | """ |
---|
66 | """ |
---|
67 | context = aq_inner(self.context) |
---|
68 | request = self.request |
---|
69 | |
---|
70 | portalTypes=request.get( 'portalTypes', [] ) |
---|
71 | exposeDCMetaTags=request.get( 'exposeDCMetaTags', None ) |
---|
72 | additionalKeywords=request.get('additionalKeywords', []) |
---|
73 | default_custom_metatags=request.get('default_custom_metatags', []) |
---|
74 | |
---|
75 | site_props = getToolByName(self.portal_properties, 'site_properties') |
---|
76 | seo_props = getToolByName(self.portal_properties, 'seo_properties') |
---|
77 | |
---|
78 | form = self.request.form |
---|
79 | submitted = form.get('form.submitted', False) |
---|
80 | |
---|
81 | if submitted: |
---|
82 | site_props.manage_changeProperties(exposeDCMetaTags=exposeDCMetaTags) |
---|
83 | seo_props.manage_changeProperties(additional_keywords=additionalKeywords) |
---|
84 | seo_props.manage_changeProperties(default_custom_metatags=default_custom_metatags) |
---|
85 | |
---|
86 | for ptype in self.portal_types.objectValues(): |
---|
87 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
88 | action = acts and acts[0] or None |
---|
89 | if ptype.getId() in portalTypes: |
---|
90 | if action is None: |
---|
91 | ptype.addAction('seo_properties', |
---|
92 | 'SEO Properties', |
---|
93 | 'string:${object_url}/qseo_properties_edit_form', |
---|
94 | '', |
---|
95 | 'Modify portal content', |
---|
96 | 'object', |
---|
97 | visible=1) |
---|
98 | else: |
---|
99 | if action !=None: |
---|
100 | actions = list(ptype.listActions()) |
---|
101 | ptype.deleteActions([actions.index(a) for a in actions if a.getId()=='seo_properties']) |
---|
102 | return request.response.redirect('%s/%s'%(self.context.absolute_url(), '@@seo-controlpanel')) |
---|
103 | else: |
---|
104 | return self.template(portalTypes=portalTypes, exposeDCMetaTags=exposeDCMetaTags) |
---|
105 | |
---|
106 | def typeInfo( self, type_name ): |
---|
107 | """ |
---|
108 | """ |
---|
109 | return self.portal_types.getTypeInfo( type_name ) |
---|