[1516] | 1 | import logging |
---|
[2139] | 2 | |
---|
| 3 | from zope.component import getSiteManager |
---|
| 4 | |
---|
| 5 | from config import SUPPORT_BLAYER |
---|
[3134] | 6 | |
---|
[1515] | 7 | from Products.CMFCore.utils import getToolByName |
---|
| 8 | |
---|
[1516] | 9 | logger = logging.getLogger('quintagroup.seoptimizer') |
---|
| 10 | |
---|
[3134] | 11 | |
---|
[2139] | 12 | def removeActions(site): |
---|
[1515] | 13 | """ Remove actions. |
---|
| 14 | """ |
---|
[2139] | 15 | types_tool = getToolByName(site, 'portal_types') |
---|
| 16 | for ptype in types_tool.objectValues(): |
---|
| 17 | idxs = [idx_act[0] for idx_act in enumerate(ptype.listActions()) \ |
---|
| 18 | if idx_act[1].id == 'seo_properties'] |
---|
| 19 | if idxs: |
---|
| 20 | ptype.deleteActions(idxs) |
---|
[3134] | 21 | msg_delete = "Deleted \"SEO Properties\" action for %s type." |
---|
| 22 | logger.log(logging.INFO, msg_delete % ptype.id) |
---|
[1515] | 23 | |
---|
[3134] | 24 | |
---|
[2139] | 25 | def removeConfiglet(site): |
---|
| 26 | """ Remove configlet. |
---|
[1515] | 27 | """ |
---|
[2139] | 28 | conf_id = 'quintagroup.seoptimizer' |
---|
| 29 | controlpanel_tool = getToolByName(site, 'portal_controlpanel') |
---|
| 30 | if controlpanel_tool: |
---|
| 31 | controlpanel_tool.unregisterConfiglet(conf_id) |
---|
| 32 | logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id) |
---|
[1515] | 33 | |
---|
[3134] | 34 | |
---|
[2139] | 35 | def removeBrowserLayer(site): |
---|
| 36 | """ Remove browser layer. |
---|
[1570] | 37 | """ |
---|
[2139] | 38 | if not SUPPORT_BLAYER: |
---|
[1570] | 39 | return |
---|
| 40 | |
---|
[2139] | 41 | from plone.browserlayer.utils import unregister_layer |
---|
| 42 | from plone.browserlayer.interfaces import ILocalBrowserLayerType |
---|
[1570] | 43 | |
---|
[3134] | 44 | name = "qSEOptimizer" |
---|
[2139] | 45 | site = getSiteManager(site) |
---|
| 46 | registeredLayers = [r.name for r in site.registeredUtilities() |
---|
| 47 | if r.provided == ILocalBrowserLayerType] |
---|
| 48 | if name in registeredLayers: |
---|
| 49 | unregister_layer(name, site_manager=site) |
---|
| 50 | logger.log(logging.INFO, "Unregistered \"%s\" browser layer." % name) |
---|
| 51 | |
---|
[3134] | 52 | |
---|
[1570] | 53 | def uninstall(context): |
---|
[1515] | 54 | """ Do customized uninstallation. |
---|
| 55 | """ |
---|
| 56 | if context.readDataFile('seo_uninstall.txt') is None: |
---|
| 57 | return |
---|
| 58 | site = context.getSite() |
---|
[1570] | 59 | removeActions(site) |
---|
[2139] | 60 | removeConfiglet(site) |
---|
| 61 | removeBrowserLayer(site) |
---|