From 1cec74642324d451ca577b670c80e7f8bbefb969 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 2 Mar 2015 13:36:22 +0100 Subject: [PATCH] two type option for restricting qualifier 'assign' settings --- browser/form.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/browser/form.py b/browser/form.py index e2c7a37..4482df4 100755 --- a/browser/form.py +++ b/browser/form.py @@ -212,15 +212,37 @@ class ObjectForm(NodeView): def typeManager(self): return ITypeManager(self.target) + @Lazy + def targetType(self): + return self.target.getType() + @Lazy def presetTypesForAssignment(self): - types = list(self.typeManager.listTypes(include=('assign',))) + types = [] + tn = getName(self.targetType) + for t in self.typeManager.listTypes(include=('assign',)): + # check if type is appropriate for the object to be created + opt = IOptions(adapted(t.context))('qualifier_assign_to') + #print '***', t.context.__name__, opt, tn + if not opt or tn in opt: + types.append(t) assigned = [r.context.conceptType for r in self.assignments] types = [t for t in types if t.typeProvider not in assigned] return [dict(title=t.title, token=t.tokenForSearch) for t in types] def conceptsForType(self, token): result = ConceptQuery(self).query(type=token) + # check typeOption: include only matching instances + include = [] + type = self.conceptManager[token.split(':')[-1]] + #print '###', token, repr(type) + opt = IOptions(adapted(type))('qualifier_assign_check_parents') + if opt: + for p in self.target.getAllParents([self.defaultPredicate]): + for c in p.object.getChildren([self.defaultPredicate]): + include.append(c) + if include: + result = [c for c in result if c in include] fv = FilterView(self.context, self.request) result = fv.apply(result) result.sort(key=lambda x: x.title) @@ -325,6 +347,10 @@ class CreateObjectForm(ObjectForm): if typeToken: return self.loopsRoot.loopsTraverse(typeToken) + @Lazy + def targetType(self): + return self.typeConcept + @Lazy def adapted(self): ad = self.typeInterface(Resource())