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