# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # $Id: common.py 282 2007-10-16 15:11:59Z ayly $ # # Copyright (c) 2007, Vahur Rebas, HTK, TLU # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Configuration object """ __version__ = "$Revision:33$"[11:-2] import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Explicit from AccessControl import ClassSecurityInfo from OFS.SimpleItem import SimpleItem from zope.interface import implements from config import CONF from interfaces import IConfig class Configuration(SimpleItem, Persistent, Explicit): """ """ security = ClassSecurityInfo() security.declareObjectPublic() implements(IConfig) manage_options = SimpleItem.manage_options id = 'configuration' meta_type = 'Configuration' def __init__(self): self._types_data = {} def manage_afterAdd(self, item, container): """ pull data in from config """ self.reload() def reload(self): """ reload """ c = CONF r = self._types_data for k in c.keys(): if k not in r: enabled = True else: enabled = self._types_data.get(k).get('enabled') d = {} for v in ('name', 'view', 'edit', 'factor', 'helptext', 'pos'): d[v] = c.get(k).get(v) d['enabled'] = enabled r[k] = d self._types_data = r return self._types_data def getView(self, meta_type): return self._types_data.get(meta_type).get('view') def getEdit(self, meta_type): return self._types_data.get(meta_type).get('edit') def getName(self, meta_type): return self._types_data.get(meta_type).get('name') def getEnabled(self, meta_type): return self._types_data.get(meta_type).get('enabled') def getFactor(self, meta_type): type = self._types_data.get(meta_type) if type is not None: return type.get('factor') return None def getHelptext(self, meta_type): t = self._types_data.get(meta_type) if t is not None: return t.get('helptext') def getTypesList(self, all=0): res = [] for x in self._types_data.keys(): if not self._types_data.get(x).get('enabled') and not all: continue res.append([self._types_data.get(x).get('pos'), x]) res.sort() return [ x[1] for x in res ] security.declareProtected('Manage', 'modifyTypes') def modifyTypes(self, REQUEST): """ modify types """ for x in self._types_data.keys(): d = REQUEST.get(x, None) if not d: self._types_data[x]['enabled'] = False else: self._types_data[x]['enabled'] = True self._p_changed = True return REQUEST.RESPONSE.redirect(self.portal_url()+'/management.html') Globals.InitializeClass(Configuration) #EOF