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

Last change on this file since 2538 was 2538, checked in by mylan, 14 years ago

Merged revisions 3566-3575 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/test_refactoring

........

r3566 | mylan | 2010-06-14 12:24:52 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Split single testqPloneGoogleSitemaps module into several specific one

........

r3567 | mylan | 2010-06-14 16:14:34 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - remove useless BBB code from interfaces.

........

r3568 | mylan | 2010-06-14 20:24:25 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - added test for MobileSitemap?, MobileSitemapView?.

........

r3569 | mylan | 2010-06-14 22:39:39 +0300 (Mon, 14 Jun 2010) | 1 line


#206: reorganize sitemap tests

........

r3570 | mylan | 2010-06-14 22:40:12 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Added configlet tests

........

r3571 | mylan | 2010-06-14 23:05:19 +0300 (Mon, 14 Jun 2010) | 1 line


#206: remove BBB code for plone<3.0

........

r3572 | mylan | 2010-06-14 23:12:00 +0300 (Mon, 14 Jun 2010) | 1 line


#206: added workflow vocabularies tests for SitemapTypes?

........

r3573 | mylan | 2010-06-15 21:36:40 +0300 (Tue, 15 Jun 2010) | 1 line


#206: some cleanup, simplify tests

........

r3574 | mylan | 2010-06-16 16:35:31 +0300 (Wed, 16 Jun 2010) | 1 line


#206: move mobile sitemap code preparation into base module

........

r3575 | mylan | 2010-06-16 16:37:14 +0300 (Wed, 16 Jun 2010) | 1 line


#206: Added security tests

........

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