source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/handlers.py

Last change on this file was 3568, checked in by potar, 8 years ago

fixed url for sitemap which is not in a site root; set absolute path for sitemap instead of id

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[1593]1from zope.component import adapter
2from Products.CMFCore.utils import getToolByName
3#from quintagroup.plonegooglesitemaps.events import AfterTransitionEvent
[3163]4from Products.DCWorkflow.interfaces import IAfterTransitionEvent
[3510]5from Acquisition import aq_parent
[1593]6
[3510]7from quintagroup.plonegooglesitemaps.utils import ping_google, isDefaultPage
[3152]8
[3510]9
[1593]10@adapter(IAfterTransitionEvent)
11def pingGoogle(event):
[3152]12    tr_id = getattr(event.transition, 'id', '')
[1593]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:
[3152]22        url = getToolByName(object, 'portal_url')
23        plone_home = url.getPortalObject().absolute_url()
[1593]24        wftrans_name = "%s#%s" % (event.workflow.id, tr_id)
25        obj_ptype = object.portal_type
26        for sm in sitemaps:
[3510]27            if wftrans_name in sm.getPingTransitions() and \
28                    obj_ptype in sm.getPortalTypes():
[3568]29                ping_google(plone_home, url.getRelativeUrl(sm))
[1593]30    return 0
[3510]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.