source: products/qPloneGoogleSitemaps/branches/contenttype/content/sitemap.py @ 414

Last change on this file since 414 was 414, checked in by chervol, 18 years ago

move the branch into trunk

  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
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 Products.qPloneGoogleSitemaps import qPloneGoogleSitemapsMessageFactory as _
12from Products.qPloneGoogleSitemaps.interfaces import ISitemap
13from Products.qPloneGoogleSitemaps.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_LIST,
24        widget=atapi.SelectionWidget(
25            label=_(u"Sitemap type"),
26            description=_(u"Select Type of the sitemap."),
27        ),
28    ),
29    atapi.LinesField(
30        name='portalTypes',
31        storage = atapi.AnnotationStorage(),
32        required=True,
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(),
44        required=True,
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    ),
104    atapi.LinesField(
105        name='pingTransitions',
106        storage = atapi.AnnotationStorage(),
107        required=False,
108        default='content',
109        vocabulary='getWorkflowTransitions',
110        schemata="pinging",
111        widget=atapi.MultiSelectionWidget(
112            label=_(u"Pinging workflow transitions"),
113            description=_(u"Select workflow transitions for pinging google on."),
114        ),
115    ),
116
117))
118
119# Set storage on fields copied from ATContentTypeSchema, making sure
120# they work well with the python bridge properties.
121
122SitemapSchema['id'].widget.ignore_visible_ids = True
123SitemapSchema['title'].storage = atapi.AnnotationStorage()
124SitemapSchema['title'].required=False
125SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'}
126SitemapSchema['description'].storage = atapi.AnnotationStorage()
127SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'}
128
129schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False)
130SitemapSchema['relatedItems'].schemata='metadata'
131SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'}
132
133class Sitemap(base.ATCTContent):
134    """Search engine Sitemap content type"""
135    implements(ISitemap)
136
137    portal_type = "Sitemap"
138    schema = SitemapSchema
139
140    #title = atapi.ATFieldProperty('title')
141    #description = atapi.ATFieldProperty('description')
142
143    def availablePortalTypes(self):
144        pt = getToolByName(self, 'portal_types')
145        types = pt.listContentTypes()
146        return atapi.DisplayList(zip(types,types))
147
148    def getWorkflowStates(self):
149        pw = getToolByName(self,'portal_workflow')
150        states = list(set([v for k,v in pw.listWFStatesByTitle()]))
151        states.sort()
152        return atapi.DisplayList(zip(states, states))
153
154    def getWorkflowTransitions(self):
155        wf_trans = []
156        pw = getToolByName(self,'portal_workflow')
157        for wf_id in pw.getWorkflowIds():
158            wf = pw.getWorkflowById(wf_id)
159            if not wf:
160                continue
161            for wf_tr in wf.transitions.values():
162                if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS:
163                    wf_trans.append(("%s#%s" % (wf_id,wf_tr.id),
164                        "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id())))
165        return atapi.DisplayList(wf_trans)
166
167    def setPingTransitions(self, value, **kw):
168        """Add 'Ping sitemap' afterscript for selected workflow transitions.
169        """
170        self.getField('pingTransitions').set(self, value)
171        if not IS_PLONE_3:
172            # Update Workflow if needed
173            pw = getToolByName(self, 'portal_workflow')
174            #ping_googlesitemap = PING_EMETHODS_MAP[self.getSitemapType()]
175            transmap = {}
176            for key in value:
177                if key.find('#')>0:
178                    ids = key.split('#')
179                    wfid = ids[0]
180                    if not wfid in transmap.keys():
181                        transmap[wfid]=[]
182                    transmap[wfid].append(ids[1])
183            for wfid in transmap.keys():
184                workflow = pw.getWorkflowById(wfid)
185                if ping_googlesitemap not in workflow.scripts.objectIds():
186                    workflow.scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod(
187                        ping_googlesitemap,
188                        'Ping sitemap',
189                        'qPloneGoogleSitemaps.ping_googlesitemap',
190                        ping_googlesitemap)
191                transitions_set = transmap[wfid]
192                for transition in workflow.transitions.values():
193                    trid = transition.id
194                    tras = transition.after_script_name
195                    if (tras == '') and (trid in transitions_set):
196                        #set
197                        after_script = ping_googlesitemap
198                    elif (tras == ping_googlesitemap) and not (trid in transitions_set):
199                        #reset
200                        after_script = ''
201                    else:
202                        #avoid properties set
203                        continue
204                    transition.setProperties(title=transition.title,
205                        new_state_id=transition.new_state_id,
206                        after_script_name=after_script,
207                        actbox_name=transition.actbox_name)
208
209atapi.registerType(Sitemap, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.