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

Last change on this file since 447 was 442, checked in by fenix, 18 years ago

creating branches directory for product

  • Property svn:eol-style set to native
File size: 8.0 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_VIEW_MAP.keys(),
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        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    ),
115
116))
117
118# Set storage on fields copied from ATContentTypeSchema, making sure
119# they work well with the python bridge properties.
120
121SitemapSchema['id'].widget.ignore_visible_ids = True
122SitemapSchema['title'].storage = atapi.AnnotationStorage()
123SitemapSchema['title'].required=False
124SitemapSchema['title'].widget.visible = {'edit':'invisible', 'view':'invisible'}
125SitemapSchema['description'].storage = atapi.AnnotationStorage()
126SitemapSchema['description'].widget.visible = {'edit':'invisible', 'view':'invisible'}
127
128schemata.finalizeATCTSchema(SitemapSchema, moveDiscussion=False)
129SitemapSchema['relatedItems'].schemata='metadata'
130SitemapSchema['relatedItems'].widget.visible = {'edit':'invisible', 'view':'invisible'}
131
132class 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')
141
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
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
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():
166                if wf_tr.after_script_name in AVAILABLE_WF_SCRIPTS:
167                    wf_trans.append(("%s#%s" % (wf_id,wf_tr.id),
168                        "%s : %s (%s)" % (wf_id,wf_tr.id,wf_tr.title_or_id())))
169        return atapi.DisplayList(wf_trans)
170
171    def setPingTransitions(self, value, **kw):
172        """Add 'Ping sitemap' afterscript for selected workflow transitions.
173        """
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)
212
213atapi.registerType(Sitemap, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.