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