[3486] | 1 | from zope.interface import Interface |
---|
| 2 | |
---|
[3508] | 3 | from quintagroup.plonegooglesitemaps.utils import dateTime, getDefaultPage |
---|
[3486] | 4 | |
---|
[3504] | 5 | #BBB: for compatibility with older plone versions |
---|
| 6 | # (Plone 3.0, Plone 3.1, Plone3.2) |
---|
| 7 | try: |
---|
[3508] | 8 | import plone.indexer |
---|
| 9 | indexer = plone.indexer.indexer |
---|
[3504] | 10 | IS_NEW = True |
---|
| 11 | except ImportError: |
---|
| 12 | IS_NEW = False |
---|
[3486] | 13 | |
---|
[3504] | 14 | class IDummyInterface: |
---|
| 15 | pass |
---|
| 16 | |
---|
| 17 | class indexer: |
---|
| 18 | |
---|
| 19 | def __init__(self, *interfaces): |
---|
| 20 | self.interfaces = IDummyInterface, |
---|
| 21 | |
---|
| 22 | def __call__(self, callable): |
---|
| 23 | callable.__component_adapts__ = self.interfaces |
---|
| 24 | callable.__implemented__ = Interface |
---|
| 25 | return callable |
---|
| 26 | |
---|
| 27 | |
---|
[3486] | 28 | @indexer(Interface) |
---|
[3504] | 29 | def sitemap_date(obj, **kwargs): |
---|
[3486] | 30 | """ Method gets date for sitemap """ |
---|
| 31 | |
---|
| 32 | def lastModificationDate(folderish_date, default_page): |
---|
| 33 | """ Method compares date (folderish object) |
---|
| 34 | with another date (default_page) and returns the last |
---|
| 35 | """ |
---|
| 36 | |
---|
| 37 | # get modification date |
---|
| 38 | child_mdate = dateTime(default_page) |
---|
| 39 | |
---|
[3495] | 40 | if folderish_date > child_mdate: |
---|
[3504] | 41 | last_date = folderish_date |
---|
[3495] | 42 | else: |
---|
| 43 | last_date = child_mdate |
---|
| 44 | |
---|
[3486] | 45 | child = getDefaultPage(default_page) |
---|
| 46 | if not child: |
---|
| 47 | return last_date |
---|
| 48 | |
---|
| 49 | return lastModificationDate(last_date, |
---|
| 50 | default_page[child]) |
---|
| 51 | |
---|
| 52 | default_page = getDefaultPage(obj) |
---|
| 53 | # get modification date |
---|
| 54 | date = dateTime(obj) |
---|
| 55 | if default_page: |
---|
| 56 | date = lastModificationDate(date, getattr(obj, default_page)) |
---|
| 57 | |
---|
| 58 | return date.HTML4() |
---|
[3504] | 59 | |
---|
| 60 | #BBB: for compatibility with older plone versions |
---|
| 61 | # (Plone 3.0, Plone 3.1, Plone3.2) |
---|
| 62 | if not IS_NEW: |
---|
| 63 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
| 64 | registerIndexableAttribute('sitemap_date', sitemap_date) |
---|