def localize_domain_model_from_descriptor_class(domain_model, descriptor_cls): """Localize the domain model for configuration information in the descriptor i.e. any extended/derived attributes. For any model/descriptor this should be called only once! """ type_key = naming.polymorphic_identity(domain_model) # localize models from descriptors only once! assert type_key not in localize_domain_model_from_descriptor_class.DONE, \ "May not re-localize [%s] domain model from descriptor" % (type_key) localize_domain_model_from_descriptor_class.DONE.append(type_key) log.info("localize_domain_model_from_descriptor_class: (%s, %s)", domain_model.__name__, descriptor_cls.__name__) # ensure cls has own dedicated "extended_properties" list property # i.e. a "extended_properties" key in own cls.__dict__, # and that it is initialized with current (possibly inherited) values domain_model.extended_properties = domain_model.extended_properties[:] for field in descriptor_cls.fields: # extended if field.extended is not None: add_extended_property_to_model(domain_model, field.name, field.extended) # derived if field.derived is not None: add_derived_property_to_model(domain_model, field.name, field.derived) # !+if domain_model.extended_properties: ? instrument_extended_properties(domain_model) mapper_add_relation_vertical_properties(domain_model) # !+AUDIT_EXTENDED_ATTRIBUTES as audit class was created prior to # extended attributes being updated on domain type, need to push onto # it any extended attrs that were read from model's descriptor if IFeatureAudit.implementedBy(domain_model): # either defined manually or created dynamically in feature_audit() audit_kls = getattr(MODEL_MODULE, "%sAudit" % (domain_model.__name__)) # ensure cls has own dedicated "extended_properties" list property audit_kls.extended_properties = domain_model.extended_properties[:] # propagate any extended attributes on head kls also to its audit_kls instrument_extended_properties(audit_kls) # containers for ic in descriptor_cls.info_containers: container_qualname = "bungeni.models.domain.%s" % ( naming.container_class_name(ic.target_type_key)) add_container_property_to_model(domain_model, ic.container_attr_name, container_qualname, ic.rel_attr_name, ic.indirect_key)
def localize_domain_model_from_descriptor_class(domain_model, descriptor_cls): """Localize the domain model for configuration information in the descriptor i.e. any extended/derived attributes. For any model/descriptor this should be called only once! """ type_key = naming.polymorphic_identity(domain_model) # localize models from descriptors only once! assert type_key not in localize_domain_model_from_descriptor_class.DONE, \ "May not re-localize [%s] domain model from descriptor" % (type_key) localize_domain_model_from_descriptor_class.DONE.append(type_key) log.info("localize_domain_model_from_descriptor_class: (%s, %s)", domain_model.__name__, descriptor_cls.__name__) # ensure cls has own dedicated "extended_properties" list property # i.e. a "extended_properties" key in own cls.__dict__, # and that it is initialized with current (possibly inherited) values domain_model.extended_properties = domain_model.extended_properties[:] for field in descriptor_cls.fields: # extended if field.extended is not None: add_extended_property_to_model(domain_model, field.name, field.extended) # derived if field.derived is not None: add_derived_property_to_model(domain_model, field.name, field.derived) # !+if domain_model.extended_properties: ? instrument_extended_properties(domain_model) mapper_add_relation_vertical_properties(domain_model) # !+AUDIT_EXTENDED_ATTRIBUTES as audit class was created prior to # extended attributes being updated on domain type, need to push onto # it any extended attrs that were read from model's descriptor if IFeatureAudit.implementedBy(domain_model): # either defined manually or created dynamically in feature_audit() audit_kls = getattr(MODEL_MODULE, "%sAudit" % (domain_model.__name__)) # ensure cls has own dedicated "extended_properties" list property audit_kls.extended_properties = domain_model.extended_properties[:] # propagate any extended attributes on head kls also to its audit_kls instrument_extended_properties(audit_kls) # containers for ic in descriptor_cls.info_containers: container_qualname = "bungeni.models.domain.%s" % ( naming.container_class_name(ic.target_type_key)) add_container_property_to_model(domain_model, ic.container_attr_name, container_qualname, ic.rel_attr_name, ic.indirect_key)
def getMenuItems(self, context, request): results = [] _url = url.absoluteURL(context, request) if IFeatureDownload.providedBy(context): doc_templates = self.documentTemplates(request.locale) add_template_to_title = len(doc_templates) > 1 for doc_type, title in context.download_feature.get_allowed_types( ): if doc_templates: for template in doc_templates: i18n_title = translate(title) if add_template_to_title: title = "%s [%s]" % (i18n_title, template.get("title")), results.append( dict(title=title, description="", action="%s/download/%s?template=%s" % (_url, doc_type, template.get("location")), selected=False, extra={ "id": "download-%s-%s" % (doc_type, misc.slugify(template.get("location"))), "class": "download-document" }, icon=None, submenu=None)) else: results.append( dict(title=doc_type, description=doc_type, action="%s/%s" % (_url, doc_type), selected=False, icon=None, extra={}, submenu=None)) if interfaces.IRSSRepresentationLayer.providedBy(request): for doc_type, title in XML_TYPES: if doc_type == TYPE_AKOMANTOSO: if IAlchemistContainer.providedBy(context): if not IFeatureDownload.implementedBy( context.domain_model): continue elif doc_type == TYPE_RSS: # rss for content types only availble for auditables if (IFeatureDownload.providedBy(context) and not IFeatureAudit.providedBy(context)): continue elif (IAlchemistContainer.providedBy(context) and not IFeatureAudit.implementedBy( context.domain_model)): continue results.append( dict(title=title, description="", action="%s/feed.%s" % (_url, doc_type), selected=False, icon=None, extra={"id": "download-%s" % doc_type}, submenu=None)) return results
def getMenuItems(self, context, request): results = [] _url = url.absoluteURL(context, request) if IFeatureDownload.providedBy(context): doc_templates = self.documentTemplates(request.locale) add_template_to_title = len(doc_templates) > 1 for doc_type, title in context.download_feature.get_allowed_types(): if doc_templates: for template in doc_templates: i18n_title = translate(title) if add_template_to_title: title="%s [%s]" % (i18n_title, template.get("title")), results.append(dict( title=title, description="", action="%s/download/%s?template=%s" % (_url, doc_type, template.get("location")), selected=False, extra = { "id": "download-%s-%s" %(doc_type, misc.slugify(template.get("location")) ), "class": "download-document" }, icon=None, submenu=None )) else: results.append(dict( title = doc_type, description=doc_type, action = "%s/%s" %(_url, doc_type), selected=False, icon=None, extra={}, submenu=None )) if interfaces.IRSSRepresentationLayer.providedBy(request): for doc_type, title in XML_TYPES: if doc_type == TYPE_AKOMANTOSO: if IAlchemistContainer.providedBy(context): if not IFeatureDownload.implementedBy( context.domain_model ): continue elif doc_type == TYPE_RSS: # rss for content types only availble for auditables if (IFeatureDownload.providedBy(context) and not IFeatureAudit.providedBy(context) ): continue elif (IAlchemistContainer.providedBy(context) and not IFeatureAudit.implementedBy(context.domain_model) ): continue results.append(dict( title = title, description="", action = "%s/feed.%s" %(_url, doc_type), selected=False, icon=None, extra={ "id": "download-%s" % doc_type }, submenu=None )) return results