1 | """Definition of the Sitemap content type |
---|
2 | """ |
---|
3 | |
---|
4 | import string |
---|
5 | from zope.interface import implements, directlyProvides |
---|
6 | |
---|
7 | from Products.Archetypes import atapi |
---|
8 | from Products.ATContentTypes.content import base |
---|
9 | from Products.ATContentTypes.content import schemata |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | |
---|
12 | from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ |
---|
13 | from quintagroup.plonegooglesitemaps.interfaces import ISitemap |
---|
14 | from quintagroup.plonegooglesitemaps.config import * |
---|
15 | |
---|
16 | SitemapSchema = 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. For instance, " \ |
---|
83 | u"\"s/\/index_html//\" will remove /index_html " \ |
---|
84 | u"from URLs representing default documents."), |
---|
85 | ), |
---|
86 | ), |
---|
87 | atapi.LinesField( |
---|
88 | name='urls', |
---|
89 | storage = atapi.AnnotationStorage(), |
---|
90 | required=False, |
---|
91 | #default='', |
---|
92 | #schemata ='default', |
---|
93 | widget=atapi.LinesWidget( |
---|
94 | label=_(u"Additional URLs"), |
---|
95 | description=_(u"Define additional URLs that are not objects and " \ |
---|
96 | u"that should be included in sitemap."), |
---|
97 | ), |
---|
98 | ), |
---|
99 | atapi.LinesField( |
---|
100 | name='pingTransitions', |
---|
101 | storage = atapi.AnnotationStorage(), |
---|
102 | required=False, |
---|
103 | vocabulary='getWorkflowTransitions', |
---|
104 | #schemata="default", |
---|
105 | widget=atapi.MultiSelectionWidget( |
---|
106 | label=_(u"Pinging workflow transitions"), |
---|
107 | description=_(u"Select workflow transitions for pinging google on."), |
---|
108 | ), |
---|
109 | ), |
---|
110 | |
---|
111 | )) |
---|
112 | |
---|
113 | # Set storage on fields copied from ATContentTypeSchema, making sure |
---|
114 | # they work well with the python bridge properties. |
---|
115 | |
---|
116 | SitemapSchema['id'].widget.ignore_visible_ids = True |
---|
117 | SitemapSchema['title'].storage = atapi.AnnotationStorage() |
---|
118 | SitemapSchema['title'].required=False |
---|
119 | SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
120 | SitemapSchema['description'].storage = atapi.AnnotationStorage() |
---|
121 | SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
122 | |
---|
123 | schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False) |
---|
124 | SitemapSchema['relatedItems'].schemata='metadata' |
---|
125 | SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
126 | |
---|
127 | class Sitemap(base.ATCTContent): |
---|
128 | """Search engine Sitemap content type""" |
---|
129 | implements(ISitemap) |
---|
130 | |
---|
131 | portal_type = "Sitemap" |
---|
132 | schema = SitemapSchema |
---|
133 | |
---|
134 | #title = atapi.ATFieldProperty('title') |
---|
135 | #description = atapi.ATFieldProperty('description') |
---|
136 | |
---|
137 | def at_post_create_script(self): |
---|
138 | # Set default layout on creation |
---|
139 | default_layout = SITEMAPS_VIEW_MAP[self.getSitemapType()] |
---|
140 | self._setProperty('layout', default_layout) |
---|
141 | |
---|
142 | def getWorkflowStates(self): |
---|
143 | pw = getToolByName(self,'portal_workflow') |
---|
144 | states = list(set([v for k,v in pw.listWFStatesByTitle()])) |
---|
145 | states.sort() |
---|
146 | return atapi.DisplayList(zip(states, states)) |
---|
147 | |
---|
148 | def getWorkflowTransitions(self): |
---|
149 | wf_trans = [] |
---|
150 | pw = getToolByName(self,'portal_workflow') |
---|
151 | for wf_id in pw.getWorkflowIds(): |
---|
152 | wf = pw.getWorkflowById(wf_id) |
---|
153 | if not wf: |
---|
154 | continue |
---|
155 | for wf_tr in wf.transitions.values(): |
---|
156 | if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS: |
---|
157 | wf_trans.append(("%s#%s" % (wf_id,wf_tr.id), |
---|
158 | "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id()))) |
---|
159 | return atapi.DisplayList(wf_trans) |
---|
160 | |
---|
161 | def setPingTransitions(self, value, **kw): |
---|
162 | """Add 'Ping sitemap' afterscript for selected workflow transitions. |
---|
163 | """ |
---|
164 | self.getField('pingTransitions').set(self, value) |
---|
165 | |
---|
166 | def setBlackout_list(self, value, **kw): |
---|
167 | """Clean-up whitespaces and empty lines.""" |
---|
168 | val = filter(None, map(string.strip, value)) |
---|
169 | self.getField('blackout_list').set(self, val) |
---|
170 | |
---|
171 | |
---|
172 | atapi.registerType(Sitemap, PROJECTNAME) |
---|