source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/utils.py @ 2401

Last change on this file since 2401 was 2401, checked in by mylan, 11 years ago

#131: Added utilities for register/unregister SchemaExtender? adapter for an interface in Local SiteManager?

  • Property svn:eol-style set to native
File size: 1.2 KB
RevLine 
[1593]1from urllib2 import urlopen
2from urllib  import quote as urlquote
3
[2401]4from zope.component import getSiteManager
5
[1593]6from Globals import DevelopmentMode
7from OFS.ObjectManager import BadRequestException
8
[2246]9from quintagroup.plonegooglesitemaps import config
[2401]10from quintagroup.plonegooglesitemaps.content.newsextender import NewsExtender
[1593]11
12def ping_google(url, sitemap_id):
13    """Ping sitemap to Google"""
[1622]14
15    resurl = url + "/" + sitemap_id
16
[2246]17    if DevelopmentMode or config.testing:
[1622]18        #prevent pinging in debug or testing mode
19        print "Pinged %s sitemap to Google" % resurl
[1593]20        return 0
21
22    sitemap_url = urlquote(resurl)
[1622]23
[1623]24    g = urlopen('http://www.google.com/webmasters/tools/ping?sitemap='+sitemap_url)
[1593]25    result = g.read()
26    g.close()
[1622]27
[1593]28    return 0
[2401]29
30def addLocalSchemaExtenderAdapter(context, iface):
31    """Register SchemaExtender adapter in
32       Local SiteManager for specified interface.
33    """
34    sm = getSiteManager(context)
35    sm.registerAdapter(factory=NewsExtender, required=(iface,))
36
37def removeLocalSchemaExtenderAdapter(context, iface):
38    """Unregister SchemaExtender adapter in
39       Local SiteManager for specified interface.
40    """
41    sm = getSiteManager(context)
42    sm.unregisterAdapter(factory=NewsExtender, required=(iface,))
Note: See TracBrowser for help on using the repository browser.