1 | from sets import Set |
---|
2 | from DateTime import DateTime |
---|
3 | from Acquisition import aq_inner |
---|
4 | from zope.component import queryAdapter |
---|
5 | from plone.app.controlpanel.form import ControlPanelView |
---|
6 | |
---|
7 | from Products.Five.browser import BrowserView |
---|
8 | from Products.CMFCore.utils import getToolByName |
---|
9 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
10 | from Products.CMFPlone import PloneMessageFactory as pmf |
---|
11 | |
---|
12 | from quintagroup.seoptimizer import SeoptimizerMessageFactory as _ |
---|
13 | |
---|
14 | SEPERATOR = '|' |
---|
15 | HAS_CANONICAL_PATH = True |
---|
16 | SEO_PREFIX = 'seo_' |
---|
17 | PROP_PREFIX = 'qSEO_' |
---|
18 | SUFFIX = '_override' |
---|
19 | PROP_CUSTOM_PREFIX = 'qSEO_custom_' |
---|
20 | |
---|
21 | try: |
---|
22 | from quintagroup.canonicalpath.interfaces import ICanonicalPath |
---|
23 | except ImportError: |
---|
24 | HAS_CANONICAL_PATH = False |
---|
25 | |
---|
26 | class SEOContext( BrowserView ): |
---|
27 | """ This class contains methods that allows to edit html header meta tags. |
---|
28 | """ |
---|
29 | def getSEOProperty( self, property_name, accessor='' ): |
---|
30 | """ Get value from seo property by property name. |
---|
31 | """ |
---|
32 | context = aq_inner(self.context) |
---|
33 | |
---|
34 | if context.hasProperty(property_name): |
---|
35 | return context.getProperty(property_name) |
---|
36 | |
---|
37 | if accessor: |
---|
38 | method = getattr(context, accessor, None) |
---|
39 | if not callable(method): |
---|
40 | return None |
---|
41 | |
---|
42 | # Catch AttributeErrors raised by some AT applications |
---|
43 | try: |
---|
44 | value = method() |
---|
45 | except AttributeError: |
---|
46 | value = None |
---|
47 | |
---|
48 | return value |
---|
49 | |
---|
50 | def seo_title( self ): |
---|
51 | """ Generate SEO Title from SEO properties. |
---|
52 | """ |
---|
53 | return self.getSEOProperty( 'qSEO_title', accessor='Title' ) |
---|
54 | |
---|
55 | def seo_robots( self ): |
---|
56 | """ Generate SEO Robots from SEO properties. |
---|
57 | """ |
---|
58 | robots = self.getSEOProperty( 'qSEO_robots' ) |
---|
59 | return robots and robots or 'ALL' |
---|
60 | |
---|
61 | def seo_description( self ): |
---|
62 | """ Generate Description from SEO properties. |
---|
63 | """ |
---|
64 | |
---|
65 | return self.getSEOProperty( 'qSEO_description', accessor = 'Description') |
---|
66 | |
---|
67 | def seo_distribution( self ): |
---|
68 | """ Generate Distribution from SEO properties. |
---|
69 | """ |
---|
70 | dist = self.getSEOProperty( 'qSEO_distribution' ) |
---|
71 | |
---|
72 | return dist and dist or 'Global' |
---|
73 | |
---|
74 | def seo_customMetaTags( self ): |
---|
75 | """ Returned seo custom metatags from default_custom_metatags property in seo_properties |
---|
76 | (global seo custom metatags) with update from seo custom metatags properties in context (local seo custom metatags). |
---|
77 | """ |
---|
78 | tags = self.seo_globalCustomMetaTags() |
---|
79 | loc = self.seo_localCustomMetaTags() |
---|
80 | names = [i['meta_name'] for i in tags] |
---|
81 | add_tags = [] |
---|
82 | for i in loc: |
---|
83 | if i['meta_name'] in names: |
---|
84 | for t in tags: |
---|
85 | if t['meta_name'] == i['meta_name']: |
---|
86 | t['meta_content'] = i['meta_content'] |
---|
87 | else: |
---|
88 | add_tags.append(i) |
---|
89 | tags.extend(add_tags) |
---|
90 | return tags |
---|
91 | |
---|
92 | def seo_globalWithoutLocalCustomMetaTags( self ): |
---|
93 | """ Returned seo custom metatags from default_custom_metatags property in seo_properties |
---|
94 | (global seo custom metatags) without seo custom metatags from properties in context (local seo custom metatags). |
---|
95 | """ |
---|
96 | glob = self.seo_globalCustomMetaTags() |
---|
97 | loc = self.seo_localCustomMetaTags() |
---|
98 | names = [i['meta_name'] for i in loc] |
---|
99 | tags = [] |
---|
100 | for i in glob: |
---|
101 | if i['meta_name'] not in names: |
---|
102 | tags.append(i) |
---|
103 | return tags |
---|
104 | |
---|
105 | def seo_localCustomMetaTags( self ): |
---|
106 | """ Returned seo custom metatags from properties in context (local seo custom metatags). |
---|
107 | """ |
---|
108 | result = [] |
---|
109 | property_prefix = 'qSEO_custom_' |
---|
110 | context = aq_inner(self.context) |
---|
111 | for property, value in context.propertyItems(): |
---|
112 | if property.startswith(property_prefix) and property[len(property_prefix):]: |
---|
113 | result.append({'meta_name' : property[len(property_prefix):], |
---|
114 | 'meta_content' : value}) |
---|
115 | return result |
---|
116 | |
---|
117 | def seo_globalCustomMetaTags( self ): |
---|
118 | """ Returned seo custom metatags from default_custom_metatags property in seo_properties. |
---|
119 | """ |
---|
120 | result = [] |
---|
121 | context = aq_inner(self.context) |
---|
122 | site_properties = getToolByName(context, 'portal_properties') |
---|
123 | if hasattr(site_properties, 'seo_properties'): |
---|
124 | custom_meta_tags = getattr(site_properties.seo_properties, 'default_custom_metatags', []) |
---|
125 | for tag in custom_meta_tags: |
---|
126 | name_value = tag.split(SEPERATOR) |
---|
127 | if name_value[0]: |
---|
128 | result.append({'meta_name' : name_value[0], |
---|
129 | 'meta_content' : len(name_value) == 2 and name_value[1] or ''}) |
---|
130 | return result |
---|
131 | |
---|
132 | def seo_nonEmptylocalMetaTags( self ): |
---|
133 | """ |
---|
134 | """ |
---|
135 | return bool(self.seo_localCustomMetaTags()) |
---|
136 | |
---|
137 | def seo_html_comment( self ): |
---|
138 | """ Generate HTML Comments from SEO properties. |
---|
139 | """ |
---|
140 | html_comment = self.getSEOProperty( 'qSEO_html_comment' ) |
---|
141 | return html_comment and html_comment or '' |
---|
142 | |
---|
143 | def meta_keywords( self ): |
---|
144 | """ Generate Meta Keywords from SEO properties (global and local) with Subject, |
---|
145 | depending on the options in configlet. |
---|
146 | """ |
---|
147 | prop_name = 'qSEO_keywords' |
---|
148 | accessor = 'Subject' |
---|
149 | context = aq_inner(self.context) |
---|
150 | keywords = Set([]) |
---|
151 | pprops = getToolByName(context, 'portal_properties') |
---|
152 | sheet = getattr(pprops, 'seo_properties', None) |
---|
153 | method = getattr(context, accessor, None) |
---|
154 | if not callable(method): |
---|
155 | return None |
---|
156 | |
---|
157 | # Catch AttributeErrors raised by some AT applications |
---|
158 | try: |
---|
159 | subject = Set(method()) |
---|
160 | except AttributeError: |
---|
161 | subject = keywords |
---|
162 | |
---|
163 | if sheet: |
---|
164 | settings_use_keywords_sg = sheet.getProperty('settings_use_keywords_sg') |
---|
165 | settings_use_keywords_lg = sheet.getProperty('settings_use_keywords_lg') |
---|
166 | global_keywords = Set(sheet.getProperty('additional_keywords', None)) |
---|
167 | local_keywords = Set(context.getProperty(prop_name, None)) |
---|
168 | # Subject overrides global seo keywords and global overrides local seo keywords |
---|
169 | if [settings_use_keywords_sg, settings_use_keywords_lg] == [1, 1]: |
---|
170 | keywords = subject |
---|
171 | # Subject overrides global seo keywords and merge global and local seo keywords |
---|
172 | elif [settings_use_keywords_sg, settings_use_keywords_lg] == [1, 2]: |
---|
173 | keywords = subject | local_keywords |
---|
174 | # Global seo keywords overrides Subject and global overrides local seo keywords |
---|
175 | elif [settings_use_keywords_sg, settings_use_keywords_lg] == [2, 1]: |
---|
176 | keywords = global_keywords |
---|
177 | # Global seo keywords overrides Subject and merge global and local seo keywords |
---|
178 | elif [settings_use_keywords_sg, settings_use_keywords_lg] == [2, 2]: |
---|
179 | keywords = global_keywords | local_keywords |
---|
180 | # Merge Subject and global seo keywords and global overrides local seo keywords |
---|
181 | elif [settings_use_keywords_sg, settings_use_keywords_lg] == [3, 1]: |
---|
182 | keywords = subject | global_keywords |
---|
183 | # Merge Subject and global seo keywords and merge global and local seo keywords |
---|
184 | elif [settings_use_keywords_sg, settings_use_keywords_lg] == [3, 2]: |
---|
185 | keywords = subject | global_keywords | local_keywords |
---|
186 | else: |
---|
187 | keywords = subject |
---|
188 | else: |
---|
189 | keywords = subject |
---|
190 | |
---|
191 | return tuple(keywords) |
---|
192 | |
---|
193 | def seo_keywords( self ): |
---|
194 | """ Generate SEO Keywords from SEO properties (global merde local). |
---|
195 | """ |
---|
196 | prop_name = 'qSEO_keywords' |
---|
197 | context = aq_inner(self.context) |
---|
198 | keywords = Set([]) |
---|
199 | pprops = getToolByName(context, 'portal_properties') |
---|
200 | sheet = getattr(pprops, 'seo_properties', None) |
---|
201 | |
---|
202 | if sheet: |
---|
203 | settings_use_keywords_sg = sheet.getProperty('settings_use_keywords_sg') |
---|
204 | settings_use_keywords_lg = sheet.getProperty('settings_use_keywords_lg') |
---|
205 | global_keywords = Set(sheet.getProperty('additional_keywords', None)) |
---|
206 | local_keywords = Set(context.getProperty(prop_name, None)) |
---|
207 | keywords = global_keywords | local_keywords |
---|
208 | else: |
---|
209 | keywords = '' |
---|
210 | return tuple(keywords) |
---|
211 | |
---|
212 | def seo_canonical( self ): |
---|
213 | """ Generate canonical URL from SEO properties. |
---|
214 | """ |
---|
215 | canonical = self.getSEOProperty( 'qSEO_canonical' ) |
---|
216 | |
---|
217 | if not canonical and HAS_CANONICAL_PATH: |
---|
218 | canpath = queryAdapter(self.context, ICanonicalPath) |
---|
219 | if canpath: |
---|
220 | purl = getToolByName(self.context, 'portal_url')() |
---|
221 | cpath = canpath.canonical_path() |
---|
222 | canonical = purl + cpath |
---|
223 | |
---|
224 | return canonical and canonical or self.context.absolute_url() |
---|
225 | |
---|
226 | |
---|
227 | class SEOControlPanel( ControlPanelView ): |
---|
228 | """ The class with methods configuration Search Engine Optimizer in configlet. |
---|
229 | """ |
---|
230 | template = ViewPageTemplateFile('templates/seo_controlpanel.pt') |
---|
231 | |
---|
232 | @property |
---|
233 | def portal_properties( self ): |
---|
234 | """ |
---|
235 | """ |
---|
236 | context = aq_inner(self.context) |
---|
237 | return getToolByName(context, 'portal_properties') |
---|
238 | |
---|
239 | @property |
---|
240 | def portal_types( self ): |
---|
241 | """ Returned a list of portal types. |
---|
242 | """ |
---|
243 | context = aq_inner(self.context) |
---|
244 | return getToolByName(context, 'portal_types') |
---|
245 | |
---|
246 | def hasSEOAction( self, type_info ): |
---|
247 | """ |
---|
248 | """ |
---|
249 | return filter(lambda x:x.id == 'seo_properties', type_info.listActions()) |
---|
250 | |
---|
251 | def test( self, condition, first, second ): |
---|
252 | """ |
---|
253 | """ |
---|
254 | return condition and first or second |
---|
255 | |
---|
256 | def getExposeDCMetaTags( self ): |
---|
257 | """ Get value from exposeDCMetaTags property in seo_properties. |
---|
258 | """ |
---|
259 | sp = self.portal_properties.site_properties |
---|
260 | return sp.getProperty('exposeDCMetaTags') |
---|
261 | |
---|
262 | def getDefaultCustomMetatags( self ): |
---|
263 | """ Get values from default_custom_metatags property in seo_properties. |
---|
264 | """ |
---|
265 | seo = self.portal_properties.seo_properties |
---|
266 | return seo.getProperty('default_custom_metatags') |
---|
267 | |
---|
268 | def getMetaTagsOrder( self ): |
---|
269 | """ Get values from metatags_order property in seo_properties. |
---|
270 | """ |
---|
271 | seo = self.portal_properties.seo_properties |
---|
272 | return seo.getProperty('metatags_order') |
---|
273 | |
---|
274 | def getAdditionalKeywords( self ): |
---|
275 | """ Get values from additional_keywords property in seo_properties. |
---|
276 | """ |
---|
277 | seo = self.portal_properties.seo_properties |
---|
278 | return seo.getProperty('additional_keywords') |
---|
279 | |
---|
280 | def getUsageKeywordsInMetatags( self ): |
---|
281 | """ Get values from usage_keywords_in_metatags property in seo_properties. |
---|
282 | """ |
---|
283 | seo = self.portal_properties.seo_properties |
---|
284 | return seo.getProperty('usage_keywords_in_metatags') |
---|
285 | |
---|
286 | def createMultiColumnList( self ): |
---|
287 | """ |
---|
288 | """ |
---|
289 | context = aq_inner(self.context) |
---|
290 | allTypes = self.portal_types.listContentTypes() |
---|
291 | try: |
---|
292 | return context.createMultiColumnList(allTypes, sort_on='title_or_id') |
---|
293 | except AttributeError: |
---|
294 | return [slist] |
---|
295 | |
---|
296 | def __call__( self ): |
---|
297 | """ Perform the update and redirect if necessary, or render the page. |
---|
298 | """ |
---|
299 | context = aq_inner(self.context) |
---|
300 | request = self.request |
---|
301 | |
---|
302 | content_types_seoprops_enabled = request.get( 'contentTypes', [] ) |
---|
303 | exposeDCMetaTags = request.get( 'exposeDCMetaTags', None ) |
---|
304 | additionalKeywords = request.get('additionalKeywords', []) |
---|
305 | default_custom_metatags = request.get('default_custom_metatags', []) |
---|
306 | metatags_order = request.get('metatags_order', []) |
---|
307 | usageKeywordsInMetatags = request.get('usageKeywordsInMetatags', None) |
---|
308 | settingsUseKeywordsSG = int(request.get('settingsUseKeywordsSG', 1)) |
---|
309 | settingsUseKeywordsLG = int(request.get('settingsUseKeywordsLG', 1)) |
---|
310 | |
---|
311 | site_props = getToolByName(self.portal_properties, 'site_properties') |
---|
312 | seo_props = getToolByName(self.portal_properties, 'seo_properties') |
---|
313 | |
---|
314 | form = self.request.form |
---|
315 | submitted = form.get('form.submitted', False) |
---|
316 | |
---|
317 | if submitted: |
---|
318 | site_props.manage_changeProperties(exposeDCMetaTags=exposeDCMetaTags) |
---|
319 | seo_props.manage_changeProperties(additional_keywords=additionalKeywords) |
---|
320 | seo_props.manage_changeProperties(default_custom_metatags=default_custom_metatags) |
---|
321 | seo_props.manage_changeProperties(metatags_order=metatags_order) |
---|
322 | seo_props.manage_changeProperties(content_types_seoprops_enabled=content_types_seoprops_enabled) |
---|
323 | seo_props.manage_changeProperties(usage_keywords_in_metatags=usageKeywordsInMetatags) |
---|
324 | seo_props.manage_changeProperties(settings_use_keywords_sg=settingsUseKeywordsSG) |
---|
325 | seo_props.manage_changeProperties(settings_use_keywords_lg=settingsUseKeywordsLG) |
---|
326 | |
---|
327 | for ptype in self.portal_types.objectValues(): |
---|
328 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
329 | action = acts and acts[0] or None |
---|
330 | if ptype.getId() in content_types_seoprops_enabled: |
---|
331 | if action is None: |
---|
332 | ptype.addAction('seo_properties', |
---|
333 | 'SEO Properties', |
---|
334 | 'string:${object_url}/@@seo-context-properties', |
---|
335 | "python:exists('portal/@@seo-context-properties')", |
---|
336 | 'Modify portal content', |
---|
337 | 'object', |
---|
338 | visible=1) |
---|
339 | else: |
---|
340 | if action !=None: |
---|
341 | actions = list(ptype.listActions()) |
---|
342 | ptype.deleteActions([actions.index(a) for a in actions if a.getId()=='seo_properties']) |
---|
343 | context.plone_utils.addPortalMessage(pmf(u'Changes saved.')) |
---|
344 | return request.response.redirect('%s/%s'%(self.context.absolute_url(), 'plone_control_panel')) |
---|
345 | else: |
---|
346 | return self.template(contentTypes=content_types_seoprops_enabled, exposeDCMetaTags=exposeDCMetaTags) |
---|
347 | |
---|
348 | def typeInfo( self, type_name ): |
---|
349 | """ Get info type by type name. |
---|
350 | """ |
---|
351 | return self.portal_types.getTypeInfo( type_name ) |
---|
352 | |
---|
353 | def select_settings_use_keywords_sg(self): |
---|
354 | context = aq_inner(self.context) |
---|
355 | site_properties = getToolByName(context, 'portal_properties') |
---|
356 | if hasattr(site_properties, 'seo_properties'): |
---|
357 | settings_use_keywords_sg = getattr(site_properties.seo_properties, 'settings_use_keywords_sg', 0) |
---|
358 | return settings_use_keywords_sg |
---|
359 | |
---|
360 | def select_settings_use_keywords_lg(self): |
---|
361 | context = aq_inner(self.context) |
---|
362 | site_properties = getToolByName(context, 'portal_properties') |
---|
363 | if hasattr(site_properties, 'seo_properties'): |
---|
364 | settings_use_keywords_lg = getattr(site_properties.seo_properties, 'settings_use_keywords_lg', 0) |
---|
365 | return settings_use_keywords_lg |
---|
366 | |
---|
367 | |
---|
368 | class SEOContextPropertiesView( BrowserView ): |
---|
369 | """ This class contains methods that allows to manage seo properties. |
---|
370 | """ |
---|
371 | template = ViewPageTemplateFile('templates/seo_context_properties.pt') |
---|
372 | |
---|
373 | def test( self, condition, first, second ): |
---|
374 | """ |
---|
375 | """ |
---|
376 | return condition and first or second |
---|
377 | |
---|
378 | def getMainDomain(self, url): |
---|
379 | """ Get a main domain. |
---|
380 | """ |
---|
381 | url = url.split('//')[-1] |
---|
382 | dompath = url.split(':')[0] |
---|
383 | dom = dompath.split('/')[0] |
---|
384 | return '.'.join(dom.split('.')[-2:]) |
---|
385 | |
---|
386 | def validateSEOProperty(self, property, value): |
---|
387 | """ Validate a seo property. |
---|
388 | """ |
---|
389 | purl = getToolByName(self.context, 'portal_url')() |
---|
390 | state = '' |
---|
391 | if property == PROP_PREFIX+'canonical': |
---|
392 | # validate seo canonical url property |
---|
393 | pdomain = self.getMainDomain(purl) |
---|
394 | if not pdomain == self.getMainDomain(value): |
---|
395 | state = _('canonical_msg', default=u'Canonical URL mast be in ${pdomain} domain.', mapping={'pdomain': pdomain}) |
---|
396 | return state |
---|
397 | |
---|
398 | def setProperty(self, property, value, type='string'): |
---|
399 | """ Add a new property. |
---|
400 | |
---|
401 | Sets a new property with the given id, value and type or changes it. |
---|
402 | """ |
---|
403 | context = aq_inner(self.context) |
---|
404 | state = self.validateSEOProperty(property, value) |
---|
405 | if not state: |
---|
406 | if context.hasProperty(property): |
---|
407 | context.manage_changeProperties({property: value}) |
---|
408 | else: |
---|
409 | context.manage_addProperty(property, value, type) |
---|
410 | return state |
---|
411 | |
---|
412 | def manageSEOProps(self, **kw): |
---|
413 | """ Manage seo properties. |
---|
414 | """ |
---|
415 | context = aq_inner(self.context) |
---|
416 | state = '' |
---|
417 | delete_list, seo_overrides_keys, seo_keys = [], [], [] |
---|
418 | seo_items = dict([(k[len(SEO_PREFIX):],v) for k,v in kw.items() if k.startswith(SEO_PREFIX)]) |
---|
419 | for key in seo_items.keys(): |
---|
420 | if key.endswith(SUFFIX): |
---|
421 | seo_overrides_keys.append(key[:-len(SUFFIX)]) |
---|
422 | else: |
---|
423 | seo_keys.append(key) |
---|
424 | for seo_key in seo_keys: |
---|
425 | if seo_key == 'custommetatags': |
---|
426 | self.manageSEOCustomMetaTagsProperties(**kw) |
---|
427 | else: |
---|
428 | if seo_key in seo_overrides_keys and seo_items.get(seo_key+SUFFIX): |
---|
429 | seo_value = seo_items[seo_key] |
---|
430 | t_value = 'string' |
---|
431 | if type(seo_value)==type([]) or type(seo_value)==type(()): t_value = 'lines' |
---|
432 | state = self.setProperty(PROP_PREFIX+seo_key, seo_value, type=t_value) |
---|
433 | if state: |
---|
434 | return state |
---|
435 | elif context.hasProperty(PROP_PREFIX+seo_key): |
---|
436 | delete_list.append(PROP_PREFIX+seo_key) |
---|
437 | if delete_list: |
---|
438 | context.manage_delProperties(delete_list) |
---|
439 | return state |
---|
440 | |
---|
441 | def setSEOCustomMetaTags(self, custommetatags): |
---|
442 | """ Set seo custom metatags properties. |
---|
443 | """ |
---|
444 | context = aq_inner(self.context) |
---|
445 | for tag in custommetatags: |
---|
446 | self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, tag['meta_name']), tag['meta_content']) |
---|
447 | |
---|
448 | def delAllSEOCustomMetaTagsProperties(self): |
---|
449 | """ Delete all seo custom metatags properties. |
---|
450 | """ |
---|
451 | context = aq_inner(self.context) |
---|
452 | delete_list = [] |
---|
453 | for property, value in context.propertyItems(): |
---|
454 | if property.startswith(PROP_CUSTOM_PREFIX) and not property == PROP_CUSTOM_PREFIX: |
---|
455 | delete_list.append(property) |
---|
456 | if delete_list: |
---|
457 | context.manage_delProperties(delete_list) |
---|
458 | |
---|
459 | def updateSEOCustomMetaTagsProperties(self, custommetatags): |
---|
460 | """ Update seo custom metatags properties. |
---|
461 | """ |
---|
462 | context = aq_inner(self.context) |
---|
463 | site_properties = getToolByName(context, 'portal_properties') |
---|
464 | globalCustomMetaTags = [] |
---|
465 | if hasattr(site_properties, 'seo_properties'): |
---|
466 | custom_meta_tags = getattr(site_properties.seo_properties, 'default_custom_metatags', []) |
---|
467 | for tag in custom_meta_tags: |
---|
468 | name_value = tag.split(SEPERATOR) |
---|
469 | if name_value[0]: |
---|
470 | globalCustomMetaTags.append({'meta_name' : name_value[0], |
---|
471 | 'meta_content' : len(name_value) == 1 and '' or name_value[1]}) |
---|
472 | for tag in custommetatags: |
---|
473 | meta_name, meta_content = tag['meta_name'], tag['meta_content'] |
---|
474 | if meta_name: |
---|
475 | if not [gmt for gmt in globalCustomMetaTags if (gmt['meta_name']==meta_name and gmt['meta_content']==meta_content)]: |
---|
476 | self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, meta_name), meta_content) |
---|
477 | |
---|
478 | def manageSEOCustomMetaTagsProperties(self, **kw): |
---|
479 | """ Update seo custom metatags properties, if enabled checkbox override or delete properties. |
---|
480 | |
---|
481 | Change object properties by passing either a mapping object |
---|
482 | of name:value pairs {'foo':6} or passing name=value parameters. |
---|
483 | """ |
---|
484 | context = aq_inner(self.context) |
---|
485 | self.delAllSEOCustomMetaTagsProperties() |
---|
486 | if kw.get('seo_custommetatags_override'): |
---|
487 | custommetatags = kw.get('seo_custommetatags', {}) |
---|
488 | self.updateSEOCustomMetaTagsProperties(custommetatags) |
---|
489 | |
---|
490 | def __call__( self ): |
---|
491 | """ Perform the update seo properties and redirect if necessary, or render the page Call method. |
---|
492 | """ |
---|
493 | context = aq_inner(self.context) |
---|
494 | request = self.request |
---|
495 | form = self.request.form |
---|
496 | submitted = form.get('form.submitted', False) |
---|
497 | if submitted: |
---|
498 | state = self.manageSEOProps(**form) |
---|
499 | if not state: |
---|
500 | state = _('seoproperties_saved', default=u'Content SEO properties have been saved.') |
---|
501 | context.plone_utils.addPortalMessage(state) |
---|
502 | kwargs = {'modification_date' : DateTime()} |
---|
503 | context.plone_utils.contentEdit(context, **kwargs) |
---|
504 | return request.response.redirect(self.context.absolute_url()) |
---|
505 | context.plone_utils.addPortalMessage(state, 'error') |
---|
506 | return self.template() |
---|