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