[1593] | 1 | """Definition of the Sitemap content type |
---|
| 2 | """ |
---|
| 3 | |
---|
[3002] | 4 | import string |
---|
[3163] | 5 | from zope.interface import implements |
---|
[1593] | 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 | |
---|
[3152] | 12 | from quintagroup.plonegooglesitemaps \ |
---|
| 13 | import qPloneGoogleSitemapsMessageFactory as _ |
---|
[1593] | 14 | from quintagroup.plonegooglesitemaps.interfaces import ISitemap |
---|
[3163] | 15 | from quintagroup.plonegooglesitemaps.config import SITEMAPS_VIEW_MAP, \ |
---|
| 16 | PROJECTNAME, AVAILABLE_WF_SCRIPTS |
---|
[1593] | 17 | |
---|
| 18 | SitemapSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema(( |
---|
| 19 | |
---|
| 20 | # -*- Your Archetypes field definitions here ... -*- |
---|
| 21 | atapi.StringField( |
---|
| 22 | name='sitemapType', |
---|
[3152] | 23 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 24 | required=True, |
---|
| 25 | default='content', |
---|
| 26 | vocabulary=SITEMAPS_VIEW_MAP.keys(), |
---|
| 27 | widget=atapi.SelectionWidget( |
---|
| 28 | label=_(u"Sitemap type"), |
---|
[3152] | 29 | visible={'edit': 'invisible', 'view': 'invisible'}, |
---|
[1593] | 30 | description=_(u"Select Type of the sitemap."), |
---|
| 31 | ), |
---|
| 32 | ), |
---|
| 33 | atapi.LinesField( |
---|
| 34 | name='portalTypes', |
---|
[3152] | 35 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 36 | required=True, |
---|
[3152] | 37 | default=['Document', ], |
---|
[2404] | 38 | vocabulary_factory="plone.app.vocabularies.ReallyUserFriendlyTypes", |
---|
[1593] | 39 | #schemata ='default', |
---|
| 40 | widget=atapi.MultiSelectionWidget( |
---|
| 41 | label=_(u"Define the types"), |
---|
[2406] | 42 | description=_(u"Define the types to be included in sitemap."), |
---|
[1593] | 43 | ), |
---|
| 44 | ), |
---|
| 45 | atapi.LinesField( |
---|
| 46 | name='states', |
---|
[3152] | 47 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 48 | required=True, |
---|
[3152] | 49 | default=['published', ], |
---|
[1593] | 50 | vocabulary="getWorkflowStates", |
---|
| 51 | #schemata ='default', |
---|
| 52 | widget=atapi.MultiSelectionWidget( |
---|
| 53 | label=_(u"Review status"), |
---|
[3510] | 54 | description=_(u"You may include items in sitemap depend of " |
---|
[3152] | 55 | u"their review state."), |
---|
[1593] | 56 | ), |
---|
| 57 | ), |
---|
| 58 | atapi.LinesField( |
---|
| 59 | name='blackout_list', |
---|
[3152] | 60 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 61 | required=False, |
---|
| 62 | #default='', |
---|
| 63 | #schemata ='default', |
---|
| 64 | widget=atapi.LinesWidget( |
---|
| 65 | label=_(u"Blackout entries"), |
---|
[3002] | 66 | description=_( |
---|
[3510] | 67 | u"Objects which match filter condition will be excluded " |
---|
| 68 | u"from the sitemap.Every record should follow the spec: " |
---|
| 69 | u"[<filter name>:]<filter arguments>. By default there are " |
---|
| 70 | u"\"id\" and \"path\" filters (\"id\" used if filter name " |
---|
| 71 | u"not specified). There is possibility to add new filters. " |
---|
| 72 | u"Look into README.txt of the " |
---|
[3152] | 73 | u"quintagroup.plonegooglesitemaps package."), |
---|
[1593] | 74 | ), |
---|
| 75 | ), |
---|
| 76 | atapi.LinesField( |
---|
| 77 | name='reg_exp', |
---|
[3152] | 78 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 79 | required=False, |
---|
| 80 | #default='', |
---|
| 81 | #schemata ='default', |
---|
| 82 | widget=atapi.LinesWidget( |
---|
| 83 | label=_(u"URL processing Regular Expressions"), |
---|
[3510] | 84 | description=_(u"Provide regular expressions (in Perl syntax), " |
---|
| 85 | u"one per line to be applied to URLs before " |
---|
| 86 | u"including them into Sitemap. Example 1: " |
---|
| 87 | u"\"s/\/index_html//\" will remove /index_html " |
---|
| 88 | u"from URLs representing default documents. " |
---|
| 89 | u"Example 2: " |
---|
| 90 | u"\"s/[you_site\/internal\/path]/[domain]/\" will " |
---|
| 91 | u"fix URLs in the sitemap in case they are " |
---|
| 92 | u"generated on the basis of your site internal" |
---|
[3066] | 93 | u"path rather than your site domain URL. "), |
---|
[1593] | 94 | ), |
---|
| 95 | ), |
---|
[3066] | 96 | |
---|
[1593] | 97 | atapi.LinesField( |
---|
| 98 | name='urls', |
---|
[3152] | 99 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 100 | required=False, |
---|
| 101 | #default='', |
---|
| 102 | #schemata ='default', |
---|
| 103 | widget=atapi.LinesWidget( |
---|
| 104 | label=_(u"Additional URLs"), |
---|
[3510] | 105 | description=_(u"Define additional URLs that are not objects and " |
---|
[1593] | 106 | u"that should be included in sitemap."), |
---|
| 107 | ), |
---|
| 108 | ), |
---|
| 109 | atapi.LinesField( |
---|
| 110 | name='pingTransitions', |
---|
[3152] | 111 | storage=atapi.AnnotationStorage(), |
---|
[1593] | 112 | required=False, |
---|
| 113 | vocabulary='getWorkflowTransitions', |
---|
| 114 | #schemata="default", |
---|
| 115 | widget=atapi.MultiSelectionWidget( |
---|
| 116 | label=_(u"Pinging workflow transitions"), |
---|
[3510] | 117 | description=_(u"Select workflow transitions for pinging " |
---|
[3152] | 118 | u"google on."), |
---|
[1593] | 119 | ), |
---|
| 120 | ), |
---|
| 121 | |
---|
| 122 | )) |
---|
| 123 | |
---|
| 124 | # Set storage on fields copied from ATContentTypeSchema, making sure |
---|
| 125 | # they work well with the python bridge properties. |
---|
| 126 | |
---|
| 127 | SitemapSchema['id'].widget.ignore_visible_ids = True |
---|
| 128 | SitemapSchema['title'].storage = atapi.AnnotationStorage() |
---|
[3152] | 129 | SitemapSchema['title'].required = False |
---|
| 130 | SitemapSchema['title'].widget.visible = {'edit': 'invisible', |
---|
| 131 | 'view': 'invisible'} |
---|
[1593] | 132 | SitemapSchema['description'].storage = atapi.AnnotationStorage() |
---|
[3152] | 133 | SitemapSchema['description'].widget.visible = {'edit': 'invisible', |
---|
| 134 | 'view': 'invisible'} |
---|
[1593] | 135 | |
---|
| 136 | schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False) |
---|
[3152] | 137 | SitemapSchema['relatedItems'].schemata = 'metadata' |
---|
| 138 | SitemapSchema['relatedItems'].widget.visible = {'edit': 'invisible', |
---|
| 139 | 'view': 'invisible'} |
---|
[1593] | 140 | |
---|
[3152] | 141 | |
---|
[1593] | 142 | class Sitemap(base.ATCTContent): |
---|
| 143 | """Search engine Sitemap content type""" |
---|
| 144 | implements(ISitemap) |
---|
| 145 | |
---|
| 146 | portal_type = "Sitemap" |
---|
| 147 | schema = SitemapSchema |
---|
| 148 | |
---|
| 149 | #title = atapi.ATFieldProperty('title') |
---|
| 150 | #description = atapi.ATFieldProperty('description') |
---|
| 151 | |
---|
| 152 | def at_post_create_script(self): |
---|
| 153 | # Set default layout on creation |
---|
| 154 | default_layout = SITEMAPS_VIEW_MAP[self.getSitemapType()] |
---|
| 155 | self._setProperty('layout', default_layout) |
---|
| 156 | |
---|
| 157 | def getWorkflowStates(self): |
---|
[3152] | 158 | pw = getToolByName(self, 'portal_workflow') |
---|
| 159 | states = list(set([v for k, v in pw.listWFStatesByTitle()])) |
---|
[1593] | 160 | states.sort() |
---|
| 161 | return atapi.DisplayList(zip(states, states)) |
---|
| 162 | |
---|
| 163 | def getWorkflowTransitions(self): |
---|
| 164 | wf_trans = [] |
---|
[3152] | 165 | pw = getToolByName(self, 'portal_workflow') |
---|
[1593] | 166 | for wf_id in pw.getWorkflowIds(): |
---|
| 167 | wf = pw.getWorkflowById(wf_id) |
---|
| 168 | if not wf: |
---|
| 169 | continue |
---|
| 170 | for wf_tr in wf.transitions.values(): |
---|
| 171 | if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS: |
---|
[3510] | 172 | wf_trans.append( |
---|
| 173 | ("%s#%s" % (wf_id, wf_tr.id), |
---|
| 174 | "%s : %s (%s)" % (wf_id, wf_tr.id, |
---|
| 175 | wf_tr.title_or_id()))) |
---|
[1593] | 176 | return atapi.DisplayList(wf_trans) |
---|
| 177 | |
---|
| 178 | def setPingTransitions(self, value, **kw): |
---|
| 179 | """Add 'Ping sitemap' afterscript for selected workflow transitions. |
---|
| 180 | """ |
---|
| 181 | self.getField('pingTransitions').set(self, value) |
---|
| 182 | |
---|
[3002] | 183 | def setBlackout_list(self, value, **kw): |
---|
| 184 | """Clean-up whitespaces and empty lines.""" |
---|
| 185 | val = filter(None, map(string.strip, value)) |
---|
| 186 | self.getField('blackout_list').set(self, val) |
---|
| 187 | |
---|
[3152] | 188 | |
---|
[1593] | 189 | atapi.registerType(Sitemap, PROJECTNAME) |
---|