source: products/quintagroup.plonegooglesitemaps/branches/sitemap_date/quintagroup/plonegooglesitemaps/indexers.py @ 3565

Last change on this file since 3565 was 3508, checked in by potar, 7 years ago

fixed pyflakes

File size: 1.7 KB
Line 
1from zope.interface import Interface
2
3from quintagroup.plonegooglesitemaps.utils import dateTime, getDefaultPage
4
5#BBB: for compatibility with older plone versions
6# (Plone 3.0, Plone 3.1, Plone3.2)
7try:
8    import plone.indexer
9    indexer = plone.indexer.indexer
10    IS_NEW = True
11except ImportError:
12    IS_NEW = False
13
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
28@indexer(Interface)
29def sitemap_date(obj, **kwargs):
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
40        if folderish_date > child_mdate:
41            last_date = folderish_date
42        else:
43            last_date = child_mdate
44
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()
59
60#BBB: for compatibility with older plone versions
61# (Plone 3.0, Plone 3.1, Plone3.2)
62if not IS_NEW:
63    from Products.CMFPlone.CatalogTool import registerIndexableAttribute
64    registerIndexableAttribute('sitemap_date', sitemap_date)
Note: See TracBrowser for help on using the repository browser.