source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/content/sitemap.py @ 2404

Last change on this file since 2404 was 2404, checked in by mylan, 14 years ago

#131: use default plone.app.vocabularies.ReallyUserFriendlyTypes? vocabulary for list allowable portal tyeps. Create new portal types vocabulary sceleton for associate portal type name to it's type-interface

  • Property svn:eol-style set to native
File size: 7.9 KB
RevLine 
[1593]1"""Definition of the Sitemap content type
2"""
3
4from zope.interface import implements, directlyProvides
5
6from Products.Archetypes import atapi
7from Products.ATContentTypes.content import base
8from Products.ATContentTypes.content import schemata
9from Products.CMFCore.utils import getToolByName
10
11from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _
12from quintagroup.plonegooglesitemaps.interfaces import ISitemap
13from quintagroup.plonegooglesitemaps.config import * 
14
15SitemapSchema = 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',],
[2404]35        vocabulary_factory="plone.app.vocabularies.ReallyUserFriendlyTypes",
[1593]36        #schemata ='default',
37        widget=atapi.MultiSelectionWidget(
38            label=_(u"Define the types"),
[2404]39            description=_(u"Define the types to be included in sitemap. " \
40                "All listed types automaticall will be extended with " \
41                "additional fields, if its applicable."),
[1593]42        ),
43    ),
44    atapi.LinesField(
45        name='states',
46        storage = atapi.AnnotationStorage(),
47        required=True,
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.LinesField(
97        name='pingTransitions',
98        storage = atapi.AnnotationStorage(),
99        required=False,
100        vocabulary='getWorkflowTransitions',
101        #schemata="default",
102        widget=atapi.MultiSelectionWidget(
103            label=_(u"Pinging workflow transitions"),
104            description=_(u"Select workflow transitions for pinging google on."),
105        ),
106    ),
107
108))
109
110# Set storage on fields copied from ATContentTypeSchema, making sure
111# they work well with the python bridge properties.
112
113SitemapSchema['id'].widget.ignore_visible_ids = True
114SitemapSchema['title'].storage = atapi.AnnotationStorage()
115SitemapSchema['title'].required=False
116SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'}
117SitemapSchema['description'].storage = atapi.AnnotationStorage()
118SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'}
119
120schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False)
121SitemapSchema['relatedItems'].schemata='metadata'
122SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'}
123
124class Sitemap(base.ATCTContent):
125    """Search engine Sitemap content type"""
126    implements(ISitemap)
127
128    portal_type = "Sitemap"
129    schema = SitemapSchema
130
131    #title = atapi.ATFieldProperty('title')
132    #description = atapi.ATFieldProperty('description')
133
134    def at_post_create_script(self):
135        # Set default layout on creation
136        default_layout = SITEMAPS_VIEW_MAP[self.getSitemapType()]
137        self._setProperty('layout', default_layout)
138
[2404]139    # def setPortalTypes(self):
140    #     pt = getToolByName(self, 'portal_types')
141    #     types = pt.listContentTypes()
142    #     return atapi.DisplayList(zip(types,types))
[1593]143
144    def getWorkflowStates(self):
145        pw = getToolByName(self,'portal_workflow')
146        states = list(set([v for k,v in pw.listWFStatesByTitle()]))
147        states.sort()
148        return atapi.DisplayList(zip(states, states))
149
150    def getWorkflowTransitions(self):
151        wf_trans = []
152        pw = getToolByName(self,'portal_workflow')
153        for wf_id in pw.getWorkflowIds():
154            wf = pw.getWorkflowById(wf_id)
155            if not wf:
156                continue
157            for wf_tr in wf.transitions.values():
158                if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS:
159                    wf_trans.append(("%s#%s" % (wf_id,wf_tr.id),
160                        "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id())))
161        return atapi.DisplayList(wf_trans)
162
163    def setPingTransitions(self, value, **kw):
164        """Add 'Ping sitemap' afterscript for selected workflow transitions.
165        """
166        self.getField('pingTransitions').set(self, value)
167        if not IS_PLONE_3:
168            # Update Workflow if needed
169            pw = getToolByName(self, 'portal_workflow')
170            #ping_googlesitemap = PING_EMETHODS_MAP[self.getSitemapType()]
171            transmap = {}
172            for key in value:
173                if key.find('#')>0:
174                    ids = key.split('#')
175                    wfid = ids[0]
176                    if not wfid in transmap.keys():
177                        transmap[wfid]=[]
178                    transmap[wfid].append(ids[1])
179            for wfid in transmap.keys():
180                workflow = pw.getWorkflowById(wfid)
181                if ping_googlesitemap not in workflow.scripts.objectIds():
182                    workflow.scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod(
183                        ping_googlesitemap,
184                        'Ping sitemap',
185                        'quintagroup.plonegooglesitemaps.ping_googlesitemap',
186                        ping_googlesitemap)
187                transitions_set = transmap[wfid]
188                for transition in workflow.transitions.values():
189                    trid = transition.id
190                    tras = transition.after_script_name
191                    if (tras == '') and (trid in transitions_set):
192                        #set
193                        after_script = ping_googlesitemap
194                    elif (tras == ping_googlesitemap) and not (trid in transitions_set):
195                        #reset
196                        after_script = ''
197                    else:
198                        #avoid properties set
199                        continue
200                    transition.setProperties(title=transition.title,
201                        new_state_id=transition.new_state_id,
202                        after_script_name=after_script,
203                        actbox_name=transition.actbox_name)
204
205atapi.registerType(Sitemap, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.