1 | """Definition of the Sitemap content type |
---|
2 | """ |
---|
3 | |
---|
4 | from zope.interface import implements, directlyProvides |
---|
5 | |
---|
6 | from Products.Archetypes import atapi |
---|
7 | from Products.ATContentTypes.content import base |
---|
8 | from Products.ATContentTypes.content import schemata |
---|
9 | from Products.CMFCore.utils import getToolByName |
---|
10 | |
---|
11 | from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ |
---|
12 | from quintagroup.plonegooglesitemaps.interfaces import ISitemap |
---|
13 | from quintagroup.plonegooglesitemaps.config import * |
---|
14 | |
---|
15 | SitemapSchema = 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 | |
---|
111 | SitemapSchema['id'].widget.ignore_visible_ids = True |
---|
112 | SitemapSchema['title'].storage = atapi.AnnotationStorage() |
---|
113 | SitemapSchema['title'].required=False |
---|
114 | SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
115 | SitemapSchema['description'].storage = atapi.AnnotationStorage() |
---|
116 | SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
117 | |
---|
118 | schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False) |
---|
119 | SitemapSchema['relatedItems'].schemata='metadata' |
---|
120 | SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
121 | |
---|
122 | class 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 | |
---|
161 | atapi.registerType(Sitemap, PROJECTNAME) |
---|