[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 | |
---|
[2751] | 9 | formatDate = lambda d:DateTime(d).strftime("%Y-%m-%d") |
---|
| 10 | |
---|
[1593] | 11 | class NewsSitemapView(CommonSitemapView): |
---|
| 12 | """ |
---|
[2396] | 13 | News Sitemap browser view |
---|
[1593] | 14 | """ |
---|
| 15 | implements(ISitemapView) |
---|
| 16 | |
---|
[2415] | 17 | @property |
---|
| 18 | def additional_maps(self): |
---|
[2751] | 19 | |
---|
[2415] | 20 | return ( |
---|
[2751] | 21 | ('publication_date', lambda x:x.Date and formatDate(x.Date) or ""), |
---|
| 22 | ('keywords', lambda x:x.Subject and ', '.join(x.Subject) or ""), |
---|
[2415] | 23 | ('title', lambda x:x.Title or x.getId or x.id), |
---|
[2751] | 24 | ('name', lambda x:x.Title and reTrailingParenthtical.sub("",x.Title) or ""), |
---|
[2415] | 25 | ('language', lambda x:x.Language or self.default_language()), |
---|
| 26 | ('access', lambda x:x.gsm_access or ""), |
---|
[2751] | 27 | ('genres', lambda x:x.gsm_genres and ", ".join(x.gsm_genres) or ""), |
---|
[2420] | 28 | ('stock', lambda x:x.gsm_stock or ""), |
---|
[2415] | 29 | ) |
---|
[1593] | 30 | |
---|
[2415] | 31 | @memoize |
---|
| 32 | def default_language(self): |
---|
| 33 | pps = getMultiAdapter((self.context, self.request), name="plone_portal_state") |
---|
| 34 | return pps.default_language |
---|
| 35 | |
---|
[1593] | 36 | def getFilteredObjects(self): |
---|
| 37 | min_date = DateTime() - 3 |
---|
[2742] | 38 | return self.portal_catalog( |
---|
| 39 | path = self.search_path, |
---|
| 40 | portal_type = self.context.getPortalTypes(), |
---|
| 41 | review_state = self.context.getStates(), |
---|
| 42 | effective = {"query": min_date, |
---|
| 43 | "range": "min" } |
---|
| 44 | ) |
---|