Back to index

plone3  3.1.7
storage.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 
00003 from persistent import Persistent
00004 from persistent.dict import PersistentDict
00005 
00006 from plone.app.viewletmanager.interfaces import IViewletSettingsStorage
00007 
00008 class ViewletSettingsStorage(Persistent):
00009     implements(IViewletSettingsStorage)
00010 
00011     def __init__(self):
00012         self._order = PersistentDict()
00013         self._hidden = PersistentDict()
00014         self._defaults = PersistentDict()
00015 
00016     def getOrder(self, name, skinname):
00017         skin = self._order.get(skinname, {})
00018         order = skin.get(name, ())
00019         if not order:
00020             skinname = self.getDefault(name)
00021             if skinname is not None:
00022                 skin = self._order.get(skinname, {})
00023                 order = skin.get(name, ())
00024         return order
00025 
00026     def setOrder(self, name, skinname, order):
00027         skin = self._order.setdefault(skinname, PersistentDict())
00028         skin[name] = tuple(order)
00029         if self.getDefault(name) is None:
00030             self.setDefault(name, skinname)
00031 
00032     def getHidden(self, name, skinname):
00033         skin = self._hidden.get(skinname, {})
00034         hidden = skin.get(name, ())
00035         if not hidden:
00036             skinname = self.getDefault(name)
00037             if skinname is not None:
00038                 skin = self._hidden.get(skinname, {})
00039                 hidden = skin.get(name, ())
00040         return hidden
00041 
00042     def setHidden(self, name, skinname, hidden):
00043         skin = self._hidden.setdefault(skinname, PersistentDict())
00044         skin[name] = tuple(hidden)
00045 
00046     def getDefault(self, name):
00047         try:
00048             return self._defaults.get(name)
00049         except AttributeError:  # Backward compatibility
00050             self._defaults = PersistentDict()
00051             self.setDefault(name, 'Plone Default')
00052             return self.getDefault(name)
00053 
00054     def setDefault(self, name, skinname):
00055         try:
00056             self._defaults[name] = skinname
00057         except AttributeError:  # Backward compatibility
00058             self._defaults = PersistentDict()
00059             self.setDefault(name, skinname)