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

Last change on this file since 3152 was 3152, checked in by zidane, 13 years ago

fixes pep8

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