source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/util.py @ 1313

Last change on this file since 1313 was 1313, checked in by liebster, 15 years ago

Added metatags order feature, which is managed by metatags_order property of of configlet

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1from Globals import InitializeClass
2from AccessControl import ClassSecurityInfo
3from Products.CMFCore.utils import getToolByName
4
5def createMultiColumnList(self,slist, numCols, sort_on='title_or_id'):
6    try:
7        mcl = self.createMultiColumnList(slist, numCols, sort_on=sort_on)
8        return mcl
9    except AttributeError:
10        return [slist]
11
12class SortedDict(dict):
13    security = ClassSecurityInfo()
14
15    security.declarePublic('items')
16    def items(self):
17        primary_metatags = self.pmt
18        lst = [(name,self[name]) for name in primary_metatags                    \
19                                                 if name in self.keys()] +       \
20              [(name, self[name]) for name in self.keys()                        \
21                                                 if name not in primary_metatags]
22        return lst
23
24
25    security.declarePublic('__init__')
26    def __init__(self, *args, **kwargs):
27        super(SortedDict,self).__init__(*args, **kwargs)
28        self.pmt = []
29
30
31    security.declarePublic('__setitem__')
32    def __setitem__(self, i, y):
33        super(SortedDict,self).__setitem__(i, y)
34        if i not in self.pmt:
35            self.pmt.append(i)
36
37try:
38    InitializeClass(SortedDict)
39except:
40    pass
41
42def removeSkin(self, layer):
43    """Remove layers"""
44    skinstool = getToolByName(self, 'portal_skins')
45    for skinName in skinstool.getSkinSelections():
46        original_path = skinstool.getSkinPath(skinName)
47        original_path = [l.strip() for l in original_path.split(',')]
48        new_path= []
49        for l in original_path:
50            if (l == layer) or (l.startswith(layer+'/')):
51                continue
52            new_path.append(l)
53        skinstool.addSkinSelection(skinName, ','.join(new_path))
54
55def removeActions(self):
56    tool = getToolByName(self, 'portal_types')
57    for ptype in tool.objectValues():
58        if ptype.getId() in ['File','Document','News Item']:
59            acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions())
60            action = acts and acts[0] or None
61            if action != None:
62                acts = list(ptype.listActions())
63                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties'])
64
65def remove_configlets( context, conf_ids ):
66    configTool = getToolByName(context, 'portal_controlpanel', None)
67    if configTool:
68        for id in conf_ids:
69            configTool.unregisterConfiglet(id)
70
71def uninstall( context ):
72    if context.readDataFile('seo_uninstall.txt') is None:
73        return
74    site = context.getSite()
75    removeSkin( site, 'quintagroup.seoptimizer' )
76    removeActions( site )
77    remove_configlets( site, ('quintagroup.seoptimizer',))
78
Note: See TracBrowser for help on using the repository browser.