source: products/qSEOptimizer/trunk/skins/qSEOptimizer/qseo_properties_edit.cpy @ 1459

Last change on this file since 1459 was 1459, checked in by mylan, 12 years ago

plone-issue-#3: force change modification date on changing SEO properties for object

File size: 2.5 KB
Line 
1## Controller Python Script "qseo_properties_edit"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind state=state
7##bind subpath=traverse_subpath
8##title=Update SEO Properties
9##parameters=title=None,description=None,keywords=None,html_comment=None,robots=None,distribution=None,canonical=None,title_override=0,description_override=0,keywords_override=0,html_comment_override=0,robots_override=0,distribution_override=0,custommetatags=[]
10
11def setProperty(context, property, value, type='string'):
12    if context.hasProperty(property):
13        context.manage_changeProperties({property: value})
14    else:
15        context.manage_addProperty(property, value, type)
16
17delete_list = []
18
19# update custom meta tags
20property_prefix = 'qSEO_custom_'
21custom_existing = []
22for property, value in context.propertyItems():
23    if property.find(property_prefix) == 0 and len(property) > len(property_prefix):
24        custom_existing.append(property)
25
26custom_updated = []
27for tag in custommetatags:
28    meta_name, meta_content = tag['meta_name'], tag['meta_content']
29    if meta_name and meta_content:
30        setProperty(context, '%s%s' % (property_prefix, meta_name), meta_content)
31        custom_updated.append('%s%s' % (property_prefix, meta_name))
32
33#add not updated custom metatags to delete list
34for tag in custom_existing:
35    if tag not in custom_updated:
36        delete_list.append(tag)
37
38setProperty(context, 'qSEO_title', title)
39setProperty(context, 'qSEO_description', description)
40setProperty(context, 'qSEO_keywords', keywords, 'lines')
41setProperty(context, 'qSEO_html_comment', html_comment)
42setProperty(context, 'qSEO_robots', robots)
43setProperty(context, 'qSEO_distribution', distribution)
44setProperty(context, 'qSEO_canonical', canonical)
45
46if not title_override:        delete_list.append('qSEO_title')
47if not description_override:  delete_list.append('qSEO_description')
48if not keywords_override:     delete_list.append('qSEO_keywords')
49if not html_comment_override: delete_list.append('qSEO_html_comment')
50if not robots_override:       delete_list.append('qSEO_robots')
51if not distribution_override: delete_list.append('qSEO_distribution')
52
53if delete_list: context.manage_delProperties(delete_list)
54
55from DateTime import DateTime
56kwargs = {'modification_date' : DateTime()}
57context.plone_utils.contentEdit(context, **kwargs)
58
59msg ='Content SEO properties have been saved.'
60try:
61    context.plone_utils.addPortalMessage(msg)
62    return state
63except AttributeError:
64    return state.set(context=context, portal_status_message=msg)
Note: See TracBrowser for help on using the repository browser.