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

Last change on this file since 1491 was 1317, checked in by piv, 15 years ago

added pop method in SortedDict?

  • Property svn:eol-style set to native
File size: 2.8 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
37    security.declarePublic('pop')
38    def pop(self, k, *args, **kwargs):
39        super(SortedDict,self).pop(k, *args, **kwargs)
40        if k in self.pmt:
41            self.pmt.remove(k)
42
43try:
44    InitializeClass(SortedDict)
45except:
46    pass
47
48def removeSkin(self, layer):
49    """Remove layers"""
50    skinstool = getToolByName(self, 'portal_skins')
51    for skinName in skinstool.getSkinSelections():
52        original_path = skinstool.getSkinPath(skinName)
53        original_path = [l.strip() for l in original_path.split(',')]
54        new_path= []
55        for l in original_path:
56            if (l == layer) or (l.startswith(layer+'/')):
57                continue
58            new_path.append(l)
59        skinstool.addSkinSelection(skinName, ','.join(new_path))
60
61def removeActions(self):
62    tool = getToolByName(self, 'portal_types')
63    for ptype in tool.objectValues():
64        if ptype.getId() in ['File','Document','News Item']:
65            acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions())
66            action = acts and acts[0] or None
67            if action != None:
68                acts = list(ptype.listActions())
69                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties'])
70
71def remove_configlets( context, conf_ids ):
72    configTool = getToolByName(context, 'portal_controlpanel', None)
73    if configTool:
74        for id in conf_ids:
75            configTool.unregisterConfiglet(id)
76
77def uninstall( context ):
78    if context.readDataFile('seo_uninstall.txt') is None:
79        return
80    site = context.getSite()
81    removeSkin( site, 'quintagroup.seoptimizer' )
82    removeActions( site )
83    remove_configlets( site, ('quintagroup.seoptimizer',))
84
Note: See TracBrowser for help on using the repository browser.