def test_invalidate_cache(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) SCHEMA_CACHE.get(portal_type) SCHEMA_CACHE.behavior_schema_interfaces(fti) self.assertIn("_v_schema_behavior_schema_interfaces", fti.__dict__.keys()) invalidate_cache(fti) self.assertNotIn("_v_schema_behavior_schema_interfaces", fti.__dict__.keys())
def test_invalidate_cache(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) SCHEMA_CACHE.get(portal_type) SCHEMA_CACHE.behavior_schema_interfaces(fti) self.assertIn('_v_schema_behavior_schema_interfaces', fti.__dict__.keys()) invalidate_cache(fti) self.assertNotIn('_v_schema_behavior_schema_interfaces', fti.__dict__.keys())
def getAdditionalSchemata(context=None, portal_type=None): """Get additional schemata for this context or this portal_type. Additional form field schemata can be defined in behaviors. Usually either context or portal_type should be set, not both. The idea is that for edit forms or views you pass in a context (and we get the portal_type from there) and for add forms you pass in a portal_type (and the context is irrelevant then). If both are set, the portal_type might get ignored, depending on which code path is taken. """ log.debug("getAdditionalSchemata with context %r and portal_type %s", context, portal_type) if context is None and portal_type is None: return if context: behavior_assignable = IBehaviorAssignable(context, None) else: behavior_assignable = None if behavior_assignable is None: log.debug("No behavior assignable found, only checking fti.") # Usually an add-form. if portal_type is None: portal_type = context.portal_type for schema_interface in SCHEMA_CACHE.behavior_schema_interfaces( portal_type ): form_schema = IFormFieldProvider(schema_interface, None) if form_schema is not None: yield form_schema else: log.debug("Behavior assignable found for context.") for behavior_reg in behavior_assignable.enumerateBehaviors(): form_schema = IFormFieldProvider(behavior_reg.interface, None) if form_schema is not None: yield form_schema
def getAdditionalSchemata(context=None, portal_type=None): """Get additional schemata for this context or this portal_type. Additional form field schemata can be defined in behaviors. Usually either context or portal_type should be set, not both. The idea is that for edit forms or views you pass in a context (and we get the portal_type from there) and for add forms you pass in a portal_type (and the context is irrelevant then). If both are set, the portal_type might get ignored, depending on which code path is taken. """ log.debug("getAdditionalSchemata with context %r and portal_type %s", context, portal_type) if context is None and portal_type is None: return if context: behavior_assignable = IBehaviorAssignable(context, None) else: behavior_assignable = None if behavior_assignable is None: log.debug("No behavior assignable found, only checking fti.") # Usually an add-form. if portal_type is None: portal_type = context.portal_type for schema_interface in SCHEMA_CACHE.behavior_schema_interfaces( portal_type ): form_schema = IFormFieldProvider(schema_interface, None) if form_schema is not None: yield form_schema else: log.debug("Behavior assignable found for context.") for behavior_reg in behavior_assignable.enumerateBehaviors(): form_schema = IFormFieldProvider(behavior_reg.interface, None) if form_schema is not None: yield form_schema