def __call__(self, add=None, remove=None, field=None): if add or remove: schema_field = ISchema(self.context)[field] values = list(schema_field.get(self.context)) setter = schema_field.getMutator(self.context) controller = None displayList = None try: displayList = schema_field.vocabulary.getDisplayList(\ self.context) controller = lambda value: value in displayList except AttributeError: raise AttributeError("This Widget needs a vocabulary that " "implements IVocabulary") if add: if controller(add) and add not in values: setter(values + [add]) self.context.reindexObject() return displayList.getValue(add) if remove: if remove in values: values.remove(remove) setter(values) self.context.reindexObject() return displayList.getValue(remove) return super(BrowserView, self).__call__()
def Schema(self): """ Overrides field definitions in fly. Note that you want to cache the result of this method as it is called many times when rendering view / edit for the content item. """ schema = self.getCachedValue("researcher_schema") if schema is not None: return schema #print "Re-creating schema" # Create modifiable copy of schema # See Products.Archetypes.BaseObject1 schema = ISchema(self) schema = schema.copy() schema = ImplicitAcquisitionWrapper(schema, self) settings = self.getResearchSettings() for row in settings.getFieldCustomizations(): name = row.get("fieldName", None) vocab = row.get("vocabToUse", None) field = schema.get(name, None) if field and vocab and hasattr(field, "vocabulary"): # Modify field copy ion displayList = settings.getVocabulary(vocab) if displayList is not None: field.vocabulary = displayList self.setCachedValue("researcher_schema", schema) return schema