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

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

rewrote code (compatibility with Plone3.0)

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1from zope.component import adapter
2from Products.CMFCore.utils import getToolByName
3#from quintagroup.plonegooglesitemaps.events import AfterTransitionEvent
4from Products.DCWorkflow.interfaces import IAfterTransitionEvent
5from Acquisition import aq_parent
6
7from quintagroup.plonegooglesitemaps.utils import ping_google, isDefaultPage
8
9
10@adapter(IAfterTransitionEvent)
11def pingGoogle(event):
12    tr_id = getattr(event.transition, 'id', '')
13    if not tr_id:
14        # object under creation
15        return 0
16
17    object = event.object
18    catalog = getToolByName(object, 'portal_catalog')
19
20    sitemaps = [b.getObject() for b in catalog(portal_type='Sitemap')]
21    if sitemaps:
22        url = getToolByName(object, 'portal_url')
23        plone_home = url.getPortalObject().absolute_url()
24        wftrans_name = "%s#%s" % (event.workflow.id, tr_id)
25        obj_ptype = object.portal_type
26        for sm in sitemaps:
27            if wftrans_name in sm.getPingTransitions() and \
28                    obj_ptype in sm.getPortalTypes():
29                ping_google(plone_home, sm.id)
30    return 0
31
32
33def reindexParentObjects(obj, event):
34    """   Method reindexes folderish objects according
35        to modification date from default object
36    """
37    def reindex(obj):
38        container = aq_parent(obj)
39        if isDefaultPage(obj):
40            container.reindexObject(['sitemap_date'])
41            reindex(container)
42
43    reindex(obj)
Note: See TracBrowser for help on using the repository browser.