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
RevLine 
[1593]1"""Definition of the Sitemap content type
2"""
3
[3002]4import string
[1593]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
[3152]12from quintagroup.plonegooglesitemaps \
13    import qPloneGoogleSitemapsMessageFactory as _
[1593]14from quintagroup.plonegooglesitemaps.interfaces import ISitemap
[3152]15from quintagroup.plonegooglesitemaps.config import *
[1593]16
17SitemapSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
18
19    # -*- Your Archetypes field definitions here ... -*-
20    atapi.StringField(
21        name='sitemapType',
[3152]22        storage=atapi.AnnotationStorage(),
[1593]23        required=True,
24        default='content',
25        vocabulary=SITEMAPS_VIEW_MAP.keys(),
26        widget=atapi.SelectionWidget(
27            label=_(u"Sitemap type"),
[3152]28            visible={'edit': 'invisible', 'view': 'invisible'},
[1593]29            description=_(u"Select Type of the sitemap."),
30        ),
31    ),
32    atapi.LinesField(
33        name='portalTypes',
[3152]34        storage=atapi.AnnotationStorage(),
[1593]35        required=True,
[3152]36        default=['Document', ],
[2404]37        vocabulary_factory="plone.app.vocabularies.ReallyUserFriendlyTypes",
[1593]38        #schemata ='default',
39        widget=atapi.MultiSelectionWidget(
40            label=_(u"Define the types"),
[2406]41            description=_(u"Define the types to be included in sitemap."),
[1593]42        ),
43    ),
44    atapi.LinesField(
45        name='states',
[3152]46        storage=atapi.AnnotationStorage(),
[1593]47        required=True,
[3152]48        default=['published', ],
[1593]49        vocabulary="getWorkflowStates",
50        #schemata ='default',
51        widget=atapi.MultiSelectionWidget(
52            label=_(u"Review status"),
[3152]53            description=_(u"You may include items in sitemap depend of " \
54                          u"their review state."),
[1593]55        ),
56    ),
57    atapi.LinesField(
58        name='blackout_list',
[3152]59        storage=atapi.AnnotationStorage(),
[1593]60        required=False,
61        #default='',
62        #schemata ='default',
63        widget=atapi.LinesWidget(
64            label=_(u"Blackout entries"),
[3002]65            description=_(
[3152]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."),
[1593]73        ),
74    ),
75    atapi.LinesField(
76        name='reg_exp',
[3152]77        storage=atapi.AnnotationStorage(),
[1593]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 " \
[3066]85                          u"including them into Sitemap. Example 1: " \
[1593]86                          u"\"s/\/index_html//\" will remove /index_html " \
[3066]87                          u"from URLs representing default documents. " \
[3152]88                          u"Example 2: " \
89                          u"\"s/[you_site\/internal\/path]/[domain]/\" will " \
[3066]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. "),
[1593]93        ),
94    ),
[3066]95
[1593]96    atapi.LinesField(
97        name='urls',
[3152]98        storage=atapi.AnnotationStorage(),
[1593]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',
[3152]110        storage=atapi.AnnotationStorage(),
[1593]111        required=False,
112        vocabulary='getWorkflowTransitions',
113        #schemata="default",
114        widget=atapi.MultiSelectionWidget(
115            label=_(u"Pinging workflow transitions"),
[3152]116            description=_(u"Select workflow transitions for pinging " \
117                          u"google on."),
[1593]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()
[3152]128SitemapSchema['title'].required = False
129SitemapSchema['title'].widget.visible = {'edit': 'invisible',
130                                         'view': 'invisible'}
[1593]131SitemapSchema['description'].storage = atapi.AnnotationStorage()
[3152]132SitemapSchema['description'].widget.visible = {'edit': 'invisible',
133                                               'view': 'invisible'}
[1593]134
135schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False)
[3152]136SitemapSchema['relatedItems'].schemata = 'metadata'
137SitemapSchema['relatedItems'].widget.visible = {'edit': 'invisible',
138                                                'view': 'invisible'}
[1593]139
[3152]140
[1593]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):
[3152]157        pw = getToolByName(self, 'portal_workflow')
158        states = list(set([v for k, v in pw.listWFStatesByTitle()]))
[1593]159        states.sort()
160        return atapi.DisplayList(zip(states, states))
161
162    def getWorkflowTransitions(self):
163        wf_trans = []
[3152]164        pw = getToolByName(self, 'portal_workflow')
[1593]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:
[3152]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())))
[1593]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
[3002]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
[3152]186
[1593]187atapi.registerType(Sitemap, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.