source: products/quintagroup.plonegooglesitemaps/branches/sitemap_date/quintagroup/plonegooglesitemaps/content/sitemap.py @ 3506

Last change on this file since 3506 was 3506, checked in by potar, 7 years ago

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