source: products/qPloneGoogleSitemaps/branches/contenttype/handlers.py @ 447

Last change on this file since 447 was 443, checked in by crchemist, 13 years ago

Make captcha more cleaner.

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1from urllib2 import urlopen
2from urllib  import quote as urlquote
3
4from zope.component import adapter
5from Products.CMFCore.utils import getToolByName
6from Products.qPloneGoogleSitemaps.events import AfterTransitionEvent
7from Products.qPloneGoogleSitemaps.interfaces import IAfterTransitionEvent
8from Products.qPloneGoogleSitemaps.utils import ping_google
9
10def pingByType(event, smtype):
11    object = event.object
12    portal = getToolByName(object, 'portal_url').getPortalObject()
13    pp = getToolByName(object, 'portal_properties')
14    props = getattr(pp, 'googlesitemap_properties', None)
15
16    pname = "%s_default" % smtype
17    csm_path = props and props.getProperty(pname, '') or ''
18    if csm_path:
19        csm = portal.unrestrictedTraverse(csm_path, default=None)
20        wftrans_name = "%s#%s" % (event.workflow.id, event.transition.id)
21        if csm and wftrans_name in csm.getPingTransitions():
22            plone_home = getToolByName(object, 'portal_url').getPortalObject().absolute_url()
23            ping_google(plone_home, csm.id)
24            print "Pinged %s sitemap to google" % smtype
25
26
27@adapter(IAfterTransitionEvent)
28def pingGoogle(event):
29    for smtype in ['content', 'mobile', 'news']:
30        pingByType(event, smtype)
31    return 0
Note: See TracBrowser for help on using the repository browser.