1 | import re |
---|
2 | from DateTime import DateTime |
---|
3 | from zope.component import getMultiAdapter |
---|
4 | from plone.memoize.view import memoize |
---|
5 | from quintagroup.plonegooglesitemaps.browser.commonview \ |
---|
6 | import CommonSitemapView, implements, ISitemapView |
---|
7 | |
---|
8 | reTrailingParenthtical = re.compile("\s*\(.*\)\s*", re.S) |
---|
9 | |
---|
10 | formatDate = lambda d: DateTime(d).strftime("%Y-%m-%d") |
---|
11 | |
---|
12 | |
---|
13 | class NewsSitemapView(CommonSitemapView): |
---|
14 | """ |
---|
15 | News Sitemap browser view |
---|
16 | """ |
---|
17 | implements(ISitemapView) |
---|
18 | |
---|
19 | @property |
---|
20 | def additional_maps(self): |
---|
21 | |
---|
22 | return ( |
---|
23 | ('publication_date', lambda x: x.Date and \ |
---|
24 | formatDate(x.Date) or ""), |
---|
25 | ('keywords', lambda x: x.Subject and ', '.join(x.Subject) or ""), |
---|
26 | ('title', lambda x: x.Title or x.getId or x.id), |
---|
27 | ('name', lambda x: x.Title and \ |
---|
28 | reTrailingParenthtical.sub("", x.Title) or ""), |
---|
29 | ('language', lambda x: x.Language or self.default_language()), |
---|
30 | ('access', lambda x: x.gsm_access or ""), |
---|
31 | ('genres', lambda x: x.gsm_genres and \ |
---|
32 | ", ".join(x.gsm_genres) or ""), |
---|
33 | ('stock', lambda x: x.gsm_stock or ""), |
---|
34 | ) |
---|
35 | |
---|
36 | @memoize |
---|
37 | def default_language(self): |
---|
38 | pps = getMultiAdapter((self.context, self.request), |
---|
39 | name="plone_portal_state") |
---|
40 | return pps.default_language |
---|
41 | |
---|
42 | def getFilteredObjects(self): |
---|
43 | min_date = DateTime() - 3 |
---|
44 | return self.portal_catalog( |
---|
45 | path=self.search_path, |
---|
46 | portal_type=self.context.getPortalTypes(), |
---|
47 | review_state=self.context.getStates(), |
---|
48 | effective={"query": min_date, |
---|
49 | "range": "min"} |
---|
50 | ) |
---|