def afterFieldModified(obj, event): """ """ field_type = obj.field_type behavior = 'Products.CMFPlomino.fields.%s.I%sField' % ( field_type.lower(), field_type.capitalize(), ) # reset behavior if changed existing_behaviors = instance_behaviors_of(obj) if not(len(existing_behaviors) == 1 and existing_behaviors[0] == behavior): # clean up current behavior disable_behaviors(obj, existing_behaviors, []) # also clean up attributes declared in different field schema for attr in ['widget', 'format', 'type', ]: if hasattr(obj, attr): setattr(obj, attr, None) enable_behaviors(obj, [behavior, ], []) # cleanup compiled formulas obj.cleanFormulaScripts( SCRIPT_ID_DELIMITER.join(["field", obj.getPhysicalPath()[-2], obj.id])) # re-index db = obj.getParentDatabase() if obj.to_be_indexed and not db.do_not_reindex: db.getIndex().createFieldIndex( obj.id, obj.field_type, indextype=obj.index_type, fieldmode=obj.field_mode, )
def enable_aspect(self): enable_behaviors(self.context, (self.aspect_behavior, ), (self.aspect_schema, )) self.context.plone_utils.addPortalMessage( _(u'enabled_aspect', default=u'Added ${aspect} to object.', mapping={'aspect': self.aspect_title})) self.request.response.redirect(self.context.absolute_url())
def enable_aspect(self): enable_behaviors(self.context, (self.aspect_behavior,), (self.aspect_schema,)) self.context.plone_utils.addPortalMessage( _(u'enabled_aspect', default=u'Added ${aspect} to object.', mapping={'aspect': self.aspect_title})) self.request.response.redirect(self.context.absolute_url())
def create(self, data): fti = getUtility(IDexterityFTI, name=self.portal_type) container = aq_inner(self.context) content = createObject(fti.factory) if hasattr(content, '_setPortalTypeName'): content._setPortalTypeName(fti.getId()) if IAcquirer.providedBy(content): content = content.__of__(container) for behavior in get_default_variant_aspects(self.context): name = dotted_name(behavior) enable_behaviors(content, (name, ), (behavior, ), reindex=False) form.applyChanges(self, content, data) for group in self.groups: form.applyChanges(group, content, data) return aq_base(content)
def create(self, data): fti = getUtility(IDexterityFTI, name=self.portal_type) container = aq_inner(self.context) content = createObject(fti.factory) if hasattr(content, '_setPortalTypeName'): content._setPortalTypeName(fti.getId()) if IAcquirer.providedBy(content): content = content.__of__(container) for behavior in get_default_variant_aspects(self.context): name = dotted_name(behavior) enable_behaviors(content, (name,), (behavior,), reindex=False) form.applyChanges(self, content, data) for group in self.groups: form.applyChanges(group, content, data) return aq_base(content)