source: products/quintagroup.plonegooglesitemaps/branches/1.7.1/quintagroup/plonegooglesitemaps/handlers.py

Last change on this file was 3163, checked in by zidane, 10 years ago

fixes pyflakes and pylint

  • Property svn:eol-style set to native
File size: 1.0 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 quintagroup.plonegooglesitemaps.utils import ping_google
6
7
8@adapter(IAfterTransitionEvent)
9def pingGoogle(event):
10    tr_id = getattr(event.transition, 'id', '')
11    if not tr_id:
12        # object under creation
13        return 0
14
15    object = event.object
16    catalog = getToolByName(object, 'portal_catalog')
17
18    sitemaps = [b.getObject() for b in catalog(portal_type='Sitemap')]
19    if sitemaps:
20        url = getToolByName(object, 'portal_url')
21        plone_home = url.getPortalObject().absolute_url()
22        wftrans_name = "%s#%s" % (event.workflow.id, tr_id)
23        obj_ptype = object.portal_type
24        for sm in sitemaps:
25            if wftrans_name in sm.getPingTransitions() \
26               and obj_ptype in sm.getPortalTypes():
27                ping_google(plone_home, sm.id)
28    return 0
Note: See TracBrowser for help on using the repository browser.