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

Last change on this file since 3002 was 3002, checked in by mylan, 10 years ago

Merged revisions 3948,3950-3951,3954-3964,3978-3981,3984-3992,4016-4018,4028-4037,4039 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/blacklist

........

r3948 | mylan | 2010-10-21 16:34:22 +0300 (Thu, 21 Oct 2010) | 1 line


#228: Added IBlackoutFilterUtility interface with skeleton of id and path utilities with appropriate tests.

........

r3950 | mylan | 2010-10-22 11:58:53 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added tests for default id and path filters

........

r3951 | mylan | 2010-10-22 11:59:25 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added default id and path blackout filters

........

r3954 | mylan | 2010-10-22 14:38:20 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added TestFormDataProcessing? tests

........

r3955 | mylan | 2010-10-22 14:38:57 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added getBOFiltered method to sitemap common view

........

r3956 | mylan | 2010-10-22 15:17:40 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Simplify blacklists filter utility tests

........

r3957 | mylan | 2010-10-22 15:23:24 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Minor name updates in blackout list tests

........

r3958 | mylan | 2010-10-22 15:54:10 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added tests for relative path in path-filter

........

r3959 | mylan | 2010-10-22 15:54:50 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added relative path processing in default path-filter

........

r3960 | mylan | 2010-10-22 15:57:18 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Fixed name of the relative path filtering test

........

r3961 | mylan | 2010-10-25 13:51:32 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fix relative path filter tests and utility

........

r3962 | mylan | 2010-10-25 17:38:55 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fixed default Path filter

........

r3963 | mylan | 2010-10-25 17:49:27 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Added request to extended list of args for a filter utility.

........

r3964 | mylan | 2010-10-25 17:50:57 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fixed rewrited blackout filter utility and functionality.

........

r3978 | mylan | 2010-10-28 19:26:11 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Remake filter utility to multiadapter, fix tests

........

r3979 | mylan | 2010-10-28 19:57:24 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Fix filter naming overhead, fix tests

........

r3980 | mylan | 2010-10-28 21:10:51 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Fix overhead in parsing of filter arguments. Added test (breakage yet)

........

r3981 | mylan | 2010-10-29 12:57:34 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Add blackout_list value clean-up on editing sitemap

........

r3984 | mylan | 2010-10-29 13:53:54 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Update description of blackout list, remove preparations to filtering

........

r3985 | mylan | 2010-10-29 16:14:29 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Added doc tests bases

........

r3986 | mylan | 2010-10-29 16:53:41 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Added basic doctests of filtering

........

r3987 | mylan | 2010-10-29 16:57:40 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Minor fixes of filtering doctests.

........

r3988 | mylan | 2010-11-01 13:31:04 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Added doctests of id, path, default filters

........

r3989 | mylan | 2010-11-01 15:20:03 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Fixed default behavior filter doctests

........

r3990 | mylan | 2010-11-01 15:20:51 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Added example of new filter creation in doctests

........

r3991 | mylan | 2010-11-01 15:35:10 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Clean-up, simplify filters doctests

........

r3992 | mylan | 2010-11-01 15:39:55 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Force to show all doctests failures.

........

r4016 | mylan | 2010-11-05 14:19:46 +0200 (Fri, 05 Nov 2010) | 1 line


#228: Fix incorrect black_list field editing in tests

........

r4017 | mylan | 2010-11-05 14:21:35 +0200 (Fri, 05 Nov 2010) | 1 line


#228: minor docstring update for getBOFiltered method

........

r4018 | mylan | 2010-11-05 14:23:56 +0200 (Fri, 05 Nov 2010) | 1 line


#228: Remake filterOut method of into generator for default filters

........

r4028 | mylan | 2010-11-08 13:58:10 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Added Plone v3.0 support

........

r4029 | mylan | 2010-11-08 16:35:22 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed tests issues

........

r4030 | mylan | 2010-11-08 16:49:28 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed ran of tearing down testing layers

........

r4031 | mylan | 2010-11-08 17:04:01 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed differencies in forms for plone<=3.1 and plone>3.1

........

r4032 | mylan | 2010-11-10 13:48:47 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Switch to use collective.testcaselayer

........

r4033 | mylan | 2010-11-10 13:49:09 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Fix doctest testcase

........

r4034 | mylan | 2010-11-10 14:34:17 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Fixed list of required packages for testing

........

r4035 | mylan | 2010-11-11 12:29:06 +0200 (Thu, 11 Nov 2010) | 1 line


#228: remake filters to generators

........

r4036 | mylan | 2010-11-11 15:16:53 +0200 (Thu, 11 Nov 2010) | 1 line


#228: reviewed explanation, correct grammar for filters doctest

........

r4037 | mylan | 2010-11-11 15:19:24 +0200 (Thu, 11 Nov 2010) | 1 line


#228: updated histroy, bumped version to 1.6.0

........

r4039 | mylan | 2010-11-11 19:03:01 +0200 (Thu, 11 Nov 2010) | 1 line


#228:Fixed typo in doctests

........

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