source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/content/sitemap.py @ 3066

Last change on this file since 3066 was 3066, checked in by olha, 13 years ago

descrtion to 'URL processing...' field extended

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1"""Definition of the Sitemap content type
2"""
3
4import string
5from zope.interface import implements, directlyProvides
6
7from Products.Archetypes import atapi
8from Products.ATContentTypes.content import base
9from Products.ATContentTypes.content import schemata
10from Products.CMFCore.utils import getToolByName
11
12from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _
13from quintagroup.plonegooglesitemaps.interfaces import ISitemap
14from quintagroup.plonegooglesitemaps.config import * 
15
16SitemapSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
17
18    # -*- Your Archetypes field definitions here ... -*-
19    atapi.StringField(
20        name='sitemapType',
21        storage = atapi.AnnotationStorage(),
22        required=True,
23        default='content',
24        vocabulary=SITEMAPS_VIEW_MAP.keys(),
25        widget=atapi.SelectionWidget(
26            label=_(u"Sitemap type"),
27            visible = {'edit':'invisible', 'view':'invisible'},
28            description=_(u"Select Type of the sitemap."),
29        ),
30    ),
31    atapi.LinesField(
32        name='portalTypes',
33        storage = atapi.AnnotationStorage(),
34        required=True,
35        default=['Document',],
36        vocabulary_factory="plone.app.vocabularies.ReallyUserFriendlyTypes",
37        #schemata ='default',
38        widget=atapi.MultiSelectionWidget(
39            label=_(u"Define the types"),
40            description=_(u"Define the types to be included in sitemap."),
41        ),
42    ),
43    atapi.LinesField(
44        name='states',
45        storage = atapi.AnnotationStorage(),
46        required=True,
47        default=['published',],
48        vocabulary="getWorkflowStates",
49        #schemata ='default',
50        widget=atapi.MultiSelectionWidget(
51            label=_(u"Review status"),
52            description=_(u"You may include items in sitemap depend of their " \
53                          u"review state."),
54        ),
55    ),
56    atapi.LinesField(
57        name='blackout_list',
58        storage = atapi.AnnotationStorage(),
59        required=False,
60        #default='',
61        #schemata ='default',
62        widget=atapi.LinesWidget(
63            label=_(u"Blackout entries"),
64            description=_(
65              u"Objects which match filter condition will be excluded from the sitemap." \
66              u"Every record should follow the spec: [<filter name>:]<filter arguments>."\
67              u" By default there are \"id\" and \"path\" filters (\"id\" used if filter"\
68              u" name not specified). There is possibility to add new filters. "\
69              u"Look into README.txt of the quintagroup.plonegooglesitemaps package."),
70        ),
71    ),
72    atapi.LinesField(
73        name='reg_exp',
74        storage = atapi.AnnotationStorage(),
75        required=False,
76        #default='',
77        #schemata ='default',
78        widget=atapi.LinesWidget(
79            label=_(u"URL processing Regular Expressions"),
80            description=_(u"Provide regular expressions (in Perl syntax), " \
81                          u"one per line to be applied to URLs before " \
82                          u"including them into Sitemap. Example 1: " \
83                          u"\"s/\/index_html//\" will remove /index_html " \
84                          u"from URLs representing default documents. " \
85                          u"Example 2: \"s/[you_site\/internal\/path]/[domain]/\" will " \
86                          u"fix URLs in the sitemap in case they are " \
87                          u"generated on the basis of your site internal" \
88                          u"path rather than your site domain URL. "),
89        ),
90    ),
91
92    atapi.LinesField(
93        name='urls',
94        storage = atapi.AnnotationStorage(),
95        required=False,
96        #default='',
97        #schemata ='default',
98        widget=atapi.LinesWidget(
99            label=_(u"Additional URLs"),
100            description=_(u"Define additional URLs that are not objects and " \
101                          u"that should be included in sitemap."),
102        ),
103    ),
104    atapi.LinesField(
105        name='pingTransitions',
106        storage = atapi.AnnotationStorage(),
107        required=False,
108        vocabulary='getWorkflowTransitions',
109        #schemata="default",
110        widget=atapi.MultiSelectionWidget(
111            label=_(u"Pinging workflow transitions"),
112            description=_(u"Select workflow transitions for pinging google on."),
113        ),
114    ),
115
116))
117
118# Set storage on fields copied from ATContentTypeSchema, making sure
119# they work well with the python bridge properties.
120
121SitemapSchema['id'].widget.ignore_visible_ids = True
122SitemapSchema['title'].storage = atapi.AnnotationStorage()
123SitemapSchema['title'].required=False
124SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'}
125SitemapSchema['description'].storage = atapi.AnnotationStorage()
126SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'}
127
128schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False)
129SitemapSchema['relatedItems'].schemata='metadata'
130SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'}
131
132class Sitemap(base.ATCTContent):
133    """Search engine Sitemap content type"""
134    implements(ISitemap)
135
136    portal_type = "Sitemap"
137    schema = SitemapSchema
138
139    #title = atapi.ATFieldProperty('title')
140    #description = atapi.ATFieldProperty('description')
141
142    def at_post_create_script(self):
143        # Set default layout on creation
144        default_layout = SITEMAPS_VIEW_MAP[self.getSitemapType()]
145        self._setProperty('layout', default_layout)
146
147    def getWorkflowStates(self):
148        pw = getToolByName(self,'portal_workflow')
149        states = list(set([v for k,v in pw.listWFStatesByTitle()]))
150        states.sort()
151        return atapi.DisplayList(zip(states, states))
152
153    def getWorkflowTransitions(self):
154        wf_trans = []
155        pw = getToolByName(self,'portal_workflow')
156        for wf_id in pw.getWorkflowIds():
157            wf = pw.getWorkflowById(wf_id)
158            if not wf:
159                continue
160            for wf_tr in wf.transitions.values():
161                if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS:
162                    wf_trans.append(("%s#%s" % (wf_id,wf_tr.id),
163                        "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id())))
164        return atapi.DisplayList(wf_trans)
165
166    def setPingTransitions(self, value, **kw):
167        """Add 'Ping sitemap' afterscript for selected workflow transitions.
168        """
169        self.getField('pingTransitions').set(self, value)
170
171    def setBlackout_list(self, value, **kw):
172        """Clean-up whitespaces and empty lines."""
173        val = filter(None, map(string.strip, value))
174        self.getField('blackout_list').set(self, val)
175       
176
177atapi.registerType(Sitemap, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.