def IsTypeAllowed(self, type, user=None): """ Check if *type* is allowed to be created in this container based on configuration.subtypes.:: type = the type to be checked user = the currently active user returns True/False *type* can be passed as - type id string - configuration object - type object instance """ if type is None: return False subtypes = self.configuration.subtypes if subtypes == AllTypesAllowed: return True if not subtypes: return False if isinstance(type, basestring): if type in subtypes: return True # dotted python to obj configuration type = self.app.GetObjectConf(type) if type is None: return False # create type from configuration type = self._GetVirtualObj(type) if type is None: return False if isinstance(type, baseConf): if type.id in subtypes: return True # create type from configuration type = self._GetVirtualObj(type) if type is None: return False if not IObject.providedBy(type) and not IConf.providedBy(type): return False # loop subtypes for iface in subtypes: if isinstance(iface, basestring): iface = ResolveName(iface, raiseExcp=False) if not iface: continue try: # may not be interface class if iface.providedBy(type): return True except: pass return False
def GetApps(self, interface=None): """ Returns registered components and apps as list. """ if isinstance(interface, basestring): interface = ResolveName(interface) apps=[] for name in self.components: a = getattr(self, name) if interface: if not interface.providedBy(a): continue apps.append(a) return apps
def GetApps(self, interface=None): """ Returns registered components and apps as list. """ if isinstance(interface, basestring): interface = ResolveName(interface) apps = [] for name in self.components: a = getattr(self, name) if interface: if not interface.providedBy(a): continue apps.append(a) return apps
def Register(self, comp, name=None): """ Register an application or component. This is usually done in the pyramid app file. The registered component is automatically loaded and set up to work with url traversal. *comp* can be one of the following cases - AppConf object - AppConf string as python dotted name - python object. Requires *name* parameter or *comp.id* attribute *name* is used as the url path name to lookup the component. """ log = logging.getLogger("portal") iface, conf = ResolveConfiguration(comp) if not conf and isinstance(comp, basestring): raise ConfigurationError, "Portal registration failure. No name given (%s)" % (str(comp)) if isinstance(comp, basestring) or isinstance(comp, baseConf): # factory methods if IAppConf.providedBy(conf): comp = ClassFactory(conf)(conf) elif IModuleConf.providedBy(conf): comp = ClassFactory(conf)(conf) elif iface and iface.providedBy(comp): comp = ResolveName(conf.context)(conf) elif isinstance(comp, basestring): comp = ResolveName(conf.context)(conf) try: name = name or conf.id except AttributeError: pass if not name: raise ConfigurationError, "Portal registration failure. No name given (%s)" % (str(comp)) log.debug("Portal.Register: %s %s", name, repr(conf)) self.__dict__[name] = comp comp.__parent__ = self comp.__name__ = name self.components.append(name)
def QueryConf(self, queryFor, context=None): """ Returns a list of configurations or empty list """ if isinstance(queryFor, basestring): queryFor = ResolveName(queryFor, raiseExcp=False) if not queryFor: return () if context: return self.registry.getAdapters((context, ), queryFor) return self.registry.getAllUtilitiesRegisteredFor(queryFor)
def GetInteractiveFunctions(self): """ Returns a list of interactive callables. returns callables """ fncs = [] for f in self.execute: f = ResolveName(f) if hasattr(f, "interactive"): fncs.append(f) return fncs
def QueryConfByName(self, queryFor, name, context=None): """ Returns configuration or None """ if isinstance(queryFor, basestring): queryFor = ResolveName(queryFor, raiseExcp=False) if not queryFor: return None if context: v = self.registry.queryAdapter(context, queryFor, name=name) if v: return v[0] return None return self.registry.queryUtility(queryFor, name=name)
def GetAllowedTypes(self, user=None, visible=1): """ List types allowed to be created in this container based on configuration.subtypes. :: user = the currently active user visible = will skip all hidden object types returns list of configurations """ subtypes = self.configuration.subtypes if not subtypes: return False all = self.app.GetAllObjectConfs(visibleOnly=visible) if subtypes == AllTypesAllowed: return all # check types by interface allowed = [] for conf in all: # create type from configuration type = self._GetVirtualObj(conf) if not type: continue # loop subtypes for iface in subtypes: if isinstance(iface, basestring): iface = ResolveName(iface, raiseExcp=False) if not iface: continue try: # may not be interface class if iface.providedBy(type): allowed.append(conf) except: pass return allowed
def designview(self): """ Tries to load the editor view class. If none is registered the function will simply return None. Otherwise the editor view class instance with context and request set. """ if hasattr(self, "_c_design"): return self._c_design module = self.context.app.QueryConfByName(IViewModuleConf, "design") if not module: return None cls = ResolveName(module.view) design = cls(self.context, self.request) self._c_design = design return design
def Allow(self, context, user): """ Checks if the transition can be executed in the current context. parameters :: context: the context object user: the current user returns True/False """ # condition if self.conditions: for c in self.conditions: if isinstance(c, basestring): c = ResolveName(c) if not c(transition=self, context=context, user=user, values=self.values): return False # roles if self.roles == WfAllRoles: return True if user: # call registered authentication policy groups = effective_principals() if groups == None: # no pyramid authentication policy activated # use custom user lookup groups = user.GetGroups(context) if context and ILocalGroups.providedBy(context): local = context.GetLocalGroups(unicode(user)) groups = list(groups) + list(local) else: groups = (u"system.Everyone", ) for r in groups: if r in self.process.adminGroups: return True if r in self.roles: return True return False
def Execute(self, context, user, values=None): """ Execute all functions for this transition. parameters :: context: the context object user: the current user values: custom values passed to the callable. if none transition.configuration.values is used. """ if not self.execute: return True # execute function for c in self.execute: func = ResolveName(c) func(context=context, transition=self, user=user, values=values or self.configuration.values) return True
def editorview(self): """ Tries to load the editor view class. If none is registered the function will simply return None. Otherwise the editor view class instance with context and request set. """ if hasattr(self, "_c_editor"): return self._c_editor # restrict editor to roots with ICMSRoot Interface. Otherwise the editor views # will not be found root = self.context.root() if not ICMSRoot.providedBy(root): return None module = self.context.app.QueryConfByName(IViewModuleConf, "editor") if not module: return None cls = ResolveName(module.view) editor = cls(self.context, self.request) self._c_editor = editor return editor
def SchemaFactory(form, fields, actions, force=False): """ converts the fields to colander schema nodes including widget. If fielddef has node set and force is false node is used as widget. To overwrite set force = True. SchemaNode(...) """ nodes = [] for field in fields: # use field configuration node: node must be a valid # SchemaNode if field.get("node") and not force: nodes.append(field.node) continue # Default node setup # Basic values for all fields and widgets kw = { "name": field.id, "title": field.name, "description": field.description, "configuration": field } kwWidget = { "form": form, "configuration": field } if field.settings and isinstance(field.settings, dict): kwWidget.update(field.settings) # ---------------------------------------------------------- # bw 0.9.12 -> moved from `field.settings` to `field` # to be removed in future. use field.widget and field.validator instead. if field.settings and field.settings.get("validator"): kw["validator"] = field.settings["validator"] if field.settings and field.settings.get("widget"): kw["widget"] = field.settings["widget"] # ---------------------------------------------------------- # custom validator if field.get("validator"): kw["validator"] = field.validator # custom widget if field.get("widget"): kw["widget"] = field.widget # setup custom widgets if "widget" in kw and kw["widget"]: widget = kw["widget"] if isinstance(widget, basestring): widget = ResolveName(widget) kw["widget"] = widget(**kwWidget) elif callable(widget): kw["widget"] = widget(**kwWidget) else: widget.form = form widget.configuration = field kw["widget"] = widget # setup custom validator if "validator" in kw and kw["validator"]: validator = kw["validator"] if isinstance(validator, basestring): validator = ResolveName(validator) kw["validator"] = validator # setup missing and default value if not field.required: kw["missing"] = null # or "" ? if field.default is not None: kw["default"] = field.default if field.get("schema"): n = SchemaNode(field.get("schema"), **kw) elif field.hidden: n = hidden_node(field, kw, kwWidget, form) else: n = apply(nodeMapping[field.datatype], (field, kw, kwWidget, form)) # add node to form if not n: continue nodes.append(n) # add buttons buttons = [] for action in actions: if action.get("hidden"): continue buttons.append(Button(name=u"%s%s"%(action.get("id"), form.actionPostfix), title=action.get("name"), action=action, cls=action.get("cls", "btn submit"))) # returns the prepared nodes and buttons return nodes, buttons
def SchemaFactory(form, fields, actions, force=False): """ converts the fields to colander schema nodes including widget. If fielddef has node set and force is false node is used as widget. To overwrite set force = True. SchemaNode(...) """ nodes = [] for field in fields: # use field configuration node: node must be a valid # SchemaNode if field.get("node") and not force: nodes.append(field.node) continue # Default node setup # Basic values for all fields and widgets kw = { "name": field.id, "title": field.name, "description": field.description, "configuration": field } kwWidget = {"form": form, "configuration": field} if field.settings and isinstance(field.settings, dict): kwWidget.update(field.settings) # ---------------------------------------------------------- # bw 0.9.12 -> moved from `field.settings` to `field` # to be removed in future. use field.widget and field.validator instead. if field.settings and field.settings.get("validator"): kw["validator"] = field.settings["validator"] if field.settings and field.settings.get("widget"): kw["widget"] = field.settings["widget"] # ---------------------------------------------------------- # custom validator if field.get("validator"): kw["validator"] = field.validator # custom widget if field.get("widget"): kw["widget"] = field.widget # setup custom widgets if "widget" in kw and kw["widget"]: widget = kw["widget"] if isinstance(widget, basestring): widget = ResolveName(widget) kw["widget"] = widget(**kwWidget) elif callable(widget): kw["widget"] = widget(**kwWidget) else: widget.form = form widget.configuration = field kw["widget"] = widget # setup custom validator if "validator" in kw and kw["validator"]: validator = kw["validator"] if isinstance(validator, basestring): validator = ResolveName(validator) kw["validator"] = validator # setup missing and default value if not field.required: kw["missing"] = null # or "" ? if field.default is not None: kw["default"] = field.default if field.get("schema"): n = SchemaNode(field.get("schema"), **kw) elif field.hidden: n = hidden_node(field, kw, kwWidget, form) else: n = apply(nodeMapping[field.datatype], (field, kw, kwWidget, form)) # add node to form if not n: continue nodes.append(n) # add buttons buttons = [] for action in actions: if action.get("hidden"): continue buttons.append( Button(name=u"%s%s" % (action.get("id"), form.actionPostfix), title=action.get("name"), action=action, cls=action.get("cls", "btn submit"))) # returns the prepared nodes and buttons return nodes, buttons
def _CheckCondition(self, profile): if not hasattr(profile, "condition"): return True c = ResolveName(profile.condition) return c(self)