source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/skins/qPloneGoogleSitemaps/gsm_edit_settings.cpy @ 1593

Last change on this file since 1593 was 1593, checked in by mylan, 10 years ago

Add content from qPloneGoogleSitemaps. Fix all imports

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1## Script (Python) "gsm_edit_settings"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##bind state=state
8##parameters=
9##title=Configure Plone Google Sitemap
10##
11
12from Products.CMFCore.utils import getToolByName
13from quintagroup.plonegooglesitemaps.utils import ping_google
14
15portal_url = getToolByName(context,'portal_url')
16portalURL = portal_url()
17portal = portal_url.getPortalObject()
18req = context.REQUEST
19message = ""
20
21def addSMByType(parent, sm_type, sm_id):
22    new_id = portal.invokeFactory(id=sm_id, type_name="Sitemap", sitemapType=sm_type)
23    sm = getattr(portal, new_id)
24    if sm:
25        sm.markCreationFlag()
26        return new_id
27    return None
28
29if req.get('form.button.AddContent', False):
30    new_id = addSMByType(portal, 'content', 'sitemap.xml')
31    if new_id:
32        return req.RESPONSE.redirect("%s/%s/edit" % (portalURL, new_id))
33    else:
34        message = "Can't create content sitemap"
35elif req.get('form.button.AddMobile', False):
36    new_id = addSMByType(portal, 'mobile', 'mobile-sitemap.xml')
37    if new_id:
38        return req.RESPONSE.redirect("%s/%s/edit" % (portalURL, new_id))
39    else:
40        message = "Can't create mobile sitemap"
41elif req.get('form.button.AddNews', False):
42    new_id = addSMByType(portal, 'news', 'news-sitemap.xml')
43    if new_id:
44        return req.RESPONSE.redirect("%s/%s/edit" % (portalURL, new_id))
45    else:
46        message = "Can't create news sitemap"
47else:
48    smselected = req.get('smselected', [])
49
50    if req.get('form.button.Delete', False):
51        portal.manage_delObjects(ids=smselected[:])
52        message = "Succesfully deleted: %s" % smselected
53
54    elif req.get('form.button.Ping', False):
55        pinged = []
56        message = "Google pinged. It will review your sitemap as soon as it will be able to. Processed: %s"
57        for sm_id in smselected:
58            try:
59                ping_google(portalURL, sm_id)
60            except:
61                message = "Cannot contact Google. Try again in a while. But pinged for: %s"
62                break
63            else:
64                pinged.append(sm_id)
65        message = message % pinged
66
67return state.set(next_action='traverse_to:string:prefs_gsm_settings',
68                 portal_status_message = message)
Note: See TracBrowser for help on using the repository browser.