def getAdditionalSchemata(context=None, portal_type=None): """Get additional schemata for this context or this portal_type. Additional 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 fti = getUtility(IDexterityFTI, name=portal_type) for behavior_name in fti.behaviors: behavior_interface = None behavior_instance = queryUtility(IBehavior, name=behavior_name) if not behavior_instance: try: behavior_interface = resolveDottedName(behavior_name) except (ValueError, ImportError): log.warning("Error resolving behaviour %s", behavior_name) continue else: behavior_interface = behavior_instance.interface if behavior_interface is not None: behavior_schema = IFormFieldProvider(behavior_interface, None) if behavior_schema is not None: yield behavior_schema else: log.debug("Behavior assignable found for context.") for behavior_reg in behavior_assignable.enumerateBehaviors(): behavior_schema = IFormFieldProvider(behavior_reg.interface, None) if behavior_schema is not None: yield behavior_schema
def __call__(self): context = aq_inner(self.context) fieldname = self.request.get('fieldname') portal_type = self.request.get('portal_type') fti = zope.component.getUtility(IDexterityFTI, name=portal_type) schema = fti.lookupSchema() field = schema.get(fieldname) if field is None: # The field might be defined in a behavior schema behavior_assignable = IBehaviorAssignable(context, None) for behavior_reg in behavior_assignable.enumerateBehaviors(): behavior_schema = IFormFieldProvider(behavior_reg.interface, None) if behavior_schema is not None: field = behavior_schema.get(fieldname) if field is not None: break vname = field.vocabularyName factory = zope.component.getUtility(IVocabularyFactory, vname) tree = factory(context) # XXX: "selected" is not set in input.pt, so does it make sense to check # for it here? Only if this json view is called elsewhere, which # doesn't seem to be the case... selected = self.request.get('selected', '').split('|') return JSONWriter().write(dict2dynatree(tree, selected, True, False))
class AddTranslationsForm(AutoExtensibleForm, Form): schema = IFormFieldProvider(IAddTranslation) ignoreContext = True label = _(u"label_add_translations", default=u"Add translations") description = _( u"long_description_add_translations", default=u"This form allows you to add currently existing " u"objects to be the translations of the current " u"object. You have to manually select both the " u"language and the object." ) @button.buttonAndHandler(_(u"add_translations", default=u"Add translations")) def handle_add(self, action): data, errors = self.extractData() if not errors: content = data['content'] language = data['language'] ITranslationManager(self.context)\ .register_translation(language, content) ILanguage(content).set_language(language) return self.request.response.redirect( self.context.absolute_url() + '/add_translations')
class ConnectTranslation(AutoExtensibleForm, Form): schema = IFormFieldProvider(IConnectTranslation) ignoreContext = True label = _(u"label_connect_translation", default=u"Connect translation") description = _( u"long_description_connect_translation", default=u"This form allows you to connect a currently existing " u"translations of the current object.") @button.buttonAndHandler( _(u"connect_translation", default=u"Connect translation")) def handle_add(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return content = data['content'] language = data['language'] ILanguage(content).set_language(language) itm = ITranslationManager(self.context) # the 'register_translation'-method takes content OR # UUID as second parameter. We need to use the UUID # here because otherwise the catalog can't be acquired # and the translation index is not updated itm.register_translation(language, IUUID(content)) return self.request.response.redirect(self.context.absolute_url() + '/modify_translations')
class RemoveTranslationsForm(AutoExtensibleForm, Form): schema = IFormFieldProvider(IRemoveTranslation) ignoreContext = True label = _(u"label_remove_translations", default=u"Remove translations") description = _(u"long_description_remove_translations", default=u"This form allows you to remove the existing " u"translations of the current object. You can " u"just delete the link between the objects " u"or you can delete the object itself.") @button.buttonAndHandler(_(u"unlink selected"), name='unlink') def handle_unlink(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: manager.remove_translation(language) return self.request.response.redirect(self.context.absolute_url() + '/remove_translations') @button.buttonAndHandler(_(u"remove selected"), name='remove') def handle_remove(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: content = manager.get_translation(language) manager.remove_translation(language) aq_parent(content).manage_delObjects([content.getId()]) return self.request.response.redirect(self.context.absolute_url() + '/remove_translations')
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
class ConnectTranslation(AutoExtensibleForm, Form): schema = IFormFieldProvider(IConnectTranslation) ignoreContext = True label = _(u"label_connect_translation", default=u"Connect translation") description = _( u"long_description_connect_translation", default=u"This form allows you to connect a currently existing " u"translations of the current object." ) @button.buttonAndHandler(_(u"connect_translation", default=u"Connect translation")) def handle_add(self, action): data, errors = self.extractData() if not errors: content = data['content'] language = data['language'] ITranslationManager(self.context)\ .register_translation(language, content) ILanguage(content).set_language(language) return self.request.response.redirect( self.context.absolute_url() + '/modify_translations')