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
Line 
1from urllib2 import urlopen
2from urllib  import quote as urlquote
3
4from zope.component import getSiteManager
5
6from Globals import DevelopmentMode
7from OFS.ObjectManager import BadRequestException
8
9from quintagroup.plonegooglesitemaps import config
10from quintagroup.plonegooglesitemaps.content.newsextender import NewsExtender
11
12def ping_google(url, sitemap_id):
13    """Ping sitemap to Google"""
14
15    resurl = url + "/" + sitemap_id
16
17    if DevelopmentMode or config.testing:
18        #prevent pinging in debug or testing mode
19        print "Pinged %s sitemap to Google" % resurl
20        return 0
21
22    sitemap_url = urlquote(resurl)
23
24    g = urlopen('http://www.google.com/webmasters/tools/ping?sitemap='+sitemap_url)
25    result = g.read()
26    g.close()
27
28    return 0
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.