[389] | 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 Products.qPloneGoogleSitemaps import qPloneGoogleSitemapsMessageFactory as _ |
---|
| 12 | from Products.qPloneGoogleSitemaps.interfaces import ISitemap |
---|
[414] | 13 | from Products.qPloneGoogleSitemaps.config import * |
---|
[389] | 14 | |
---|
| 15 | SitemapSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema(( |
---|
| 16 | |
---|
| 17 | # -*- Your Archetypes field definitions here ... -*- |
---|
[390] | 18 | atapi.StringField( |
---|
| 19 | name='sitemapType', |
---|
| 20 | storage = atapi.AnnotationStorage(), |
---|
| 21 | required=True, |
---|
| 22 | default='content', |
---|
[421] | 23 | vocabulary=SITEMAPS_VIEW_MAP.keys(), |
---|
[390] | 24 | widget=atapi.SelectionWidget( |
---|
| 25 | label=_(u"Sitemap type"), |
---|
| 26 | description=_(u"Select Type of the sitemap."), |
---|
| 27 | ), |
---|
| 28 | ), |
---|
[389] | 29 | atapi.LinesField( |
---|
| 30 | name='portalTypes', |
---|
| 31 | storage = atapi.AnnotationStorage(), |
---|
[390] | 32 | required=True, |
---|
[389] | 33 | default=['Document',], |
---|
| 34 | vocabulary="availablePortalTypes", |
---|
| 35 | #schemata ='default', |
---|
| 36 | widget=atapi.MultiSelectionWidget( |
---|
| 37 | label=_(u"Define the types"), |
---|
| 38 | description=_(u"Define the types to be included in sitemap."), |
---|
| 39 | ), |
---|
| 40 | ), |
---|
| 41 | atapi.LinesField( |
---|
| 42 | name='states', |
---|
| 43 | storage = atapi.AnnotationStorage(), |
---|
[390] | 44 | required=True, |
---|
[389] | 45 | default=['published',], |
---|
| 46 | vocabulary="getWorkflowStates", |
---|
| 47 | #schemata ='default', |
---|
| 48 | widget=atapi.MultiSelectionWidget( |
---|
| 49 | label=_(u"Review status"), |
---|
| 50 | description=_(u"You may include items in sitemap depend of their " \ |
---|
| 51 | u"review state."), |
---|
| 52 | ), |
---|
| 53 | ), |
---|
| 54 | atapi.LinesField( |
---|
| 55 | name='blackout_list', |
---|
| 56 | storage = atapi.AnnotationStorage(), |
---|
| 57 | required=False, |
---|
| 58 | #default='', |
---|
| 59 | #schemata ='default', |
---|
| 60 | widget=atapi.LinesWidget( |
---|
| 61 | label=_(u"Blackout entries"), |
---|
| 62 | description=_(u"The objects with the given ids will not be " \ |
---|
| 63 | u"included in sitemap."), |
---|
| 64 | ), |
---|
| 65 | ), |
---|
| 66 | atapi.LinesField( |
---|
| 67 | name='reg_exp', |
---|
| 68 | storage = atapi.AnnotationStorage(), |
---|
| 69 | required=False, |
---|
| 70 | #default='', |
---|
| 71 | #schemata ='default', |
---|
| 72 | widget=atapi.LinesWidget( |
---|
| 73 | label=_(u"URL processing Regular Expressions"), |
---|
| 74 | description=_(u"Provide regular expressions (in Perl syntax), " \ |
---|
| 75 | u"one per line to be applied to URLs before " \ |
---|
| 76 | u"including them into Sitemap. For instance, " \ |
---|
| 77 | u"\"s/\/index_html//\" will remove /index_html " \ |
---|
| 78 | u"from URLs representing default documents."), |
---|
| 79 | ), |
---|
| 80 | ), |
---|
| 81 | atapi.LinesField( |
---|
| 82 | name='urls', |
---|
| 83 | storage = atapi.AnnotationStorage(), |
---|
| 84 | required=False, |
---|
| 85 | #default='', |
---|
| 86 | #schemata ='default', |
---|
| 87 | widget=atapi.LinesWidget( |
---|
| 88 | label=_(u"Additional URLs"), |
---|
| 89 | description=_(u"Define additional URLs that are not objects and " \ |
---|
| 90 | u"that should be included in sitemap."), |
---|
| 91 | ), |
---|
| 92 | ), |
---|
| 93 | atapi.StringField( |
---|
| 94 | name='verificationFilename', |
---|
| 95 | storage = atapi.AnnotationStorage(), |
---|
| 96 | required=False, |
---|
| 97 | #default='', |
---|
| 98 | #schemata ='default', |
---|
| 99 | widget=atapi.StringWidget( |
---|
| 100 | label=_(u"Provide verification file name"), |
---|
| 101 | description=_(u"Default verification file name for this sitemaps"), |
---|
| 102 | ), |
---|
| 103 | ), |
---|
[409] | 104 | atapi.LinesField( |
---|
| 105 | name='pingTransitions', |
---|
| 106 | storage = atapi.AnnotationStorage(), |
---|
| 107 | required=False, |
---|
| 108 | vocabulary='getWorkflowTransitions', |
---|
| 109 | schemata="pinging", |
---|
| 110 | widget=atapi.MultiSelectionWidget( |
---|
| 111 | label=_(u"Pinging workflow transitions"), |
---|
| 112 | description=_(u"Select workflow transitions for pinging google on."), |
---|
| 113 | ), |
---|
| 114 | ), |
---|
[389] | 115 | |
---|
| 116 | )) |
---|
| 117 | |
---|
| 118 | # Set storage on fields copied from ATContentTypeSchema, making sure |
---|
| 119 | # they work well with the python bridge properties. |
---|
| 120 | |
---|
[412] | 121 | SitemapSchema['id'].widget.ignore_visible_ids = True |
---|
[389] | 122 | SitemapSchema['title'].storage = atapi.AnnotationStorage() |
---|
[414] | 123 | SitemapSchema['title'].required=False |
---|
[411] | 124 | SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
[389] | 125 | SitemapSchema['description'].storage = atapi.AnnotationStorage() |
---|
[411] | 126 | SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
[389] | 127 | |
---|
| 128 | schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False) |
---|
| 129 | SitemapSchema['relatedItems'].schemata='metadata' |
---|
| 130 | SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'} |
---|
| 131 | |
---|
| 132 | class Sitemap(base.ATCTContent): |
---|
| 133 | """Search engine Sitemap content type""" |
---|
| 134 | implements(ISitemap) |
---|
| 135 | |
---|
| 136 | portal_type = "Sitemap" |
---|
| 137 | schema = SitemapSchema |
---|
| 138 | |
---|
| 139 | #title = atapi.ATFieldProperty('title') |
---|
| 140 | #description = atapi.ATFieldProperty('description') |
---|
[409] | 141 | |
---|
[421] | 142 | def at_post_create_script(self): |
---|
| 143 | # Set default layout on creation |
---|
| 144 | default_layout = SITEMAPS_VIEW_MAP[self.getSitemapType()] |
---|
| 145 | self._setProperty('layout', default_layout) |
---|
| 146 | |
---|
[389] | 147 | def availablePortalTypes(self): |
---|
| 148 | pt = getToolByName(self, 'portal_types') |
---|
| 149 | types = pt.listContentTypes() |
---|
| 150 | return atapi.DisplayList(zip(types,types)) |
---|
| 151 | |
---|
| 152 | def getWorkflowStates(self): |
---|
| 153 | pw = getToolByName(self,'portal_workflow') |
---|
| 154 | states = list(set([v for k,v in pw.listWFStatesByTitle()])) |
---|
| 155 | states.sort() |
---|
| 156 | return atapi.DisplayList(zip(states, states)) |
---|
| 157 | |
---|
[409] | 158 | def getWorkflowTransitions(self): |
---|
| 159 | wf_trans = [] |
---|
| 160 | pw = getToolByName(self,'portal_workflow') |
---|
| 161 | for wf_id in pw.getWorkflowIds(): |
---|
| 162 | wf = pw.getWorkflowById(wf_id) |
---|
| 163 | if not wf: |
---|
| 164 | continue |
---|
| 165 | for wf_tr in wf.transitions.values(): |
---|
[414] | 166 | if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS: |
---|
[409] | 167 | wf_trans.append(("%s#%s" % (wf_id,wf_tr.id), |
---|
[410] | 168 | "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id()))) |
---|
[409] | 169 | return atapi.DisplayList(wf_trans) |
---|
[389] | 170 | |
---|
[409] | 171 | def setPingTransitions(self, value, **kw): |
---|
| 172 | """Add 'Ping sitemap' afterscript for selected workflow transitions. |
---|
| 173 | """ |
---|
[414] | 174 | self.getField('pingTransitions').set(self, value) |
---|
| 175 | if not IS_PLONE_3: |
---|
| 176 | # Update Workflow if needed |
---|
| 177 | pw = getToolByName(self, 'portal_workflow') |
---|
| 178 | #ping_googlesitemap = PING_EMETHODS_MAP[self.getSitemapType()] |
---|
| 179 | transmap = {} |
---|
| 180 | for key in value: |
---|
| 181 | if key.find('#')>0: |
---|
| 182 | ids = key.split('#') |
---|
| 183 | wfid = ids[0] |
---|
| 184 | if not wfid in transmap.keys(): |
---|
| 185 | transmap[wfid]=[] |
---|
| 186 | transmap[wfid].append(ids[1]) |
---|
| 187 | for wfid in transmap.keys(): |
---|
| 188 | workflow = pw.getWorkflowById(wfid) |
---|
| 189 | if ping_googlesitemap not in workflow.scripts.objectIds(): |
---|
| 190 | workflow.scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod( |
---|
| 191 | ping_googlesitemap, |
---|
| 192 | 'Ping sitemap', |
---|
| 193 | 'qPloneGoogleSitemaps.ping_googlesitemap', |
---|
| 194 | ping_googlesitemap) |
---|
| 195 | transitions_set = transmap[wfid] |
---|
| 196 | for transition in workflow.transitions.values(): |
---|
| 197 | trid = transition.id |
---|
| 198 | tras = transition.after_script_name |
---|
| 199 | if (tras == '') and (trid in transitions_set): |
---|
| 200 | #set |
---|
| 201 | after_script = ping_googlesitemap |
---|
| 202 | elif (tras == ping_googlesitemap) and not (trid in transitions_set): |
---|
| 203 | #reset |
---|
| 204 | after_script = '' |
---|
| 205 | else: |
---|
| 206 | #avoid properties set |
---|
| 207 | continue |
---|
| 208 | transition.setProperties(title=transition.title, |
---|
| 209 | new_state_id=transition.new_state_id, |
---|
| 210 | after_script_name=after_script, |
---|
| 211 | actbox_name=transition.actbox_name) |
---|
[409] | 212 | |
---|
[389] | 213 | atapi.registerType(Sitemap, PROJECTNAME) |
---|