Пример #1
0
 def update(self, transition_id=None):
     if IWorkspaceContainer.providedBy(self.context.__parent__):
         self._old_url = WorkspaceAbsoluteURLView(
             self.context, self.request)()
     workflow = interfaces.IWorkflow(self.context)
     if transition_id:
         transition = workflow.get_transition(transition_id)
         title = translate(_(transition.title), context=self.request)
         self.status = translate(
             _(u"Confirmation required for workflow transition: '${title}'",
                 mapping={"title": title}
             ), 
             context=self.request)
     self.setupActions(transition_id)
     
     if (ILegislativeContent.providedBy(self.context) and
             get_mask(self.context) == "manual" and 
             not self.context.registry_number
         ):
         self.form_fields = self.form_fields.omit("note", "date_active")
     else:
         self.form_fields = self.form_fields.omit("registry_number")
     
     if not self.actions: 
         self.form_fields = self.form_fields.omit("note", "date_active")
     elif not IFeatureAudit.providedBy(self.context):
         self.form_fields = self.form_fields.omit("note", "date_active")
     # !+SUPERFLUOUS_ObejctModifiedEvent(mr, nov-2011) the following update()
     # is causing a ModifiedEvent to be fired, causing a modify change to be 
     # logged (while this workflow change should be just that).
     super(WorkflowActionViewlet, self).update()
Пример #2
0
    def update(self, transition_id=None):
        if IWorkspaceContainer.providedBy(self.context.__parent__):
            self._old_url = WorkspaceAbsoluteURLView(self.context,
                                                     self.request)()
        workflow = interfaces.IWorkflow(self.context)
        if transition_id:
            transition = workflow.get_transition(transition_id)
            title = translate(_(transition.title), context=self.request)
            self.status = translate(_(
                u"Confirmation required for workflow transition: '${title}'",
                mapping={"title": title}),
                                    context=self.request)
        self.setupActions(transition_id)

        if (ILegislativeContent.providedBy(self.context)
                and get_mask(self.context) == "manual"
                and not self.context.registry_number):
            self.form_fields = self.form_fields.omit("note", "date_active")
        else:
            self.form_fields = self.form_fields.omit("registry_number")

        if not self.actions:
            self.form_fields = self.form_fields.omit("note", "date_active")
        elif not IFeatureAudit.providedBy(self.context):
            self.form_fields = self.form_fields.omit("note", "date_active")
        # !+SUPERFLUOUS_ObejctModifiedEvent(mr, nov-2011) the following update()
        # is causing a ModifiedEvent to be fired, causing a modify change to be
        # logged (while this workflow change should be just that).
        super(WorkflowActionViewlet, self).update()
Пример #3
0
def _get_auditable_ancestor(obj):
    parent = obj.__parent__
    while parent:
        if IFeatureAudit.providedBy(parent):
            return parent
        else:
            parent = getattr(parent, "__parent__", None)
Пример #4
0
def _get_auditable_ancestor(obj):
    parent = obj.__parent__
    while parent:
        if IFeatureAudit.providedBy(parent):
            return parent
        else:
            parent = getattr(parent, "__parent__", None)
Пример #5
0
 def update(self, transition_id=None):
     # set up viewlets; the view is rendered from viewlets for
     # historic reasons; this may be refactored anytime.
     if IFeatureAudit.providedBy(self.context):
         self.history_viewlet = WorkflowHistoryViewlet(
             self.context, self.request, self, None)
         self.history_viewlet.update()
     self.action_viewlet = WorkflowActionViewlet(self.context, self.request,
                                                 self, None)
     self.action_viewlet.update(transition_id=transition_id)
Пример #6
0
 def retract_is_allowed(context):
     """A workflow condition, for system use only, for auto "retract" transition.
     """
     if IFeatureAudit.providedBy(context):
         changes = domain.get_changes(context, "workflow")
         if changes:
             prev_change = changes[0].seq_previous
             if prev_change:
                 return from_state_id == prev_change.audit.status
     return True
Пример #7
0
 def update(self, transition_id=None):
     # set up viewlets; the view is rendered from viewlets for
     # historic reasons; this may be refactored anytime.
     if IFeatureAudit.providedBy(self.context):
         self.history_viewlet = WorkflowHistoryViewlet(
             self.context, self.request, self, None)
         self.history_viewlet.update()
     self.action_viewlet = WorkflowActionViewlet(
         self.context, self.request, self, None)
     self.action_viewlet.update(transition_id=transition_id)
Пример #8
0
 def retract_is_allowed(context):
     """A workflow condition, for system use only, for auto "retract" transition.
     """
     if IFeatureAudit.providedBy(context):
         changes = domain.get_changes(context, "workflow")
         if changes:
             prev_change = changes[0].seq_previous
             if prev_change:
                 return from_state_id == prev_change.audit.status
     return True
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
    def get_min_date_active(self):
        """Determine the min_date_active to validate against.
        """
        def is_workflowed_and_draft(instance):
            """is item workflowed, and if so is it in a logical draft state?
            """
            if interfaces.IWorkflowed.providedBy(instance):
                wf = interfaces.IWorkflow(instance)
                return instance.status in wf.get_state_ids(tagged=["draft"],
                                                           restrict=False)
            return False

        instance = removeSecurityProxy(self.context)
        min_date_active = None

        if IFeatureAudit.providedBy(self.context):
            # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data
            # for workflowed items via the UI -- note, ideally we should be
            # able to also control the item's creation active_date.
            #
            # If a workflowed item is in draft state, we do NOT take the
            # date_active of its last change as the min_date_active, but
            # let that min fallback to chamber's creation date...
            if not is_workflowed_and_draft(instance):
                changes = get_changes(instance, "workflow")
                if changes:
                    # then use the "date_active" of the most recent entry
                    min_date_active = changes[-1].date_active

        if not min_date_active:
            # ok, try determine a min_date_active in another way, namely via the
            # start_date of the instance itself (if it supports it) or of the
            # "chamber" the instance "lives" in... !+sitting, session, ...?
            if IGroup.providedBy(instance) or IGroupMember.providedBy(
                    instance):
                start_date = instance.start_date
            else:
                start_date = models.utils.get_chamber_for_context(
                    instance).start_date
            assert start_date is not None, \
                "Cannot determine min_date_active for worklfowed instance: %s" % (instance)
            min_date_active = datetime.datetime.combine(
                start_date, datetime.time())

        # As the precision of the UI-submitted datetime is only to the minute,
        # we adjust min_date_active by a margin of 59 secs earlier to avoid
        # issues of doing 2 transitions in quick succession (within same minute)
        # the 2nd of which could be taken to be too old...
        return min_date_active - datetime.timedelta(seconds=59)
Пример #12
0
 def get_min_date_active(self):
     """Determine the min_date_active to validate against.
     """
     
     def is_workflowed_and_draft(instance):
         """is item workflowed, and if so is it in a logical draft state?
         """
         if interfaces.IWorkflowed.providedBy(instance):
             wf = interfaces.IWorkflow(instance)
             return instance.status in wf.get_state_ids(tagged=["draft"],
                 restrict=False)
         return False
     
     instance = removeSecurityProxy(self.context)
     min_date_active = None
     
     if IFeatureAudit.providedBy(self.context):
         # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data 
         # for workflowed items via the UI -- note, ideally we should be 
         # able to also control the item's creation active_date.
         #
         # If a workflowed item is in draft state, we do NOT take the 
         # date_active of its last change as the min_date_active, but
         # let that min fallback to chamber's creation date...
         if not is_workflowed_and_draft(instance):
             changes = get_changes(instance, "workflow")
             if changes:
  	            # then use the "date_active" of the most recent entry
                 min_date_active = changes[-1].date_active
     
     if not min_date_active:
         # ok, try determine a min_date_active in another way, namely via the
         # start_date of the instance itself (if it supports it) or of the 
         # "chamber" the instance "lives" in... !+sitting, session, ...?
         if IGroup.providedBy(instance) or IGroupMember.providedBy(instance):
             start_date = instance.start_date
         else:
             start_date = models.utils.get_chamber_for_context(instance).start_date
         assert start_date is not None, \
             "Cannot determine min_date_active for worklfowed instance: %s" % (instance)
         min_date_active = datetime.datetime.combine(start_date, datetime.time())
     
     # As the precision of the UI-submitted datetime is only to the minute, 
     # we adjust min_date_active by a margin of 59 secs earlier to avoid 
     # issues of doing 2 transitions in quick succession (within same minute) 
     # the 2nd of which could be taken to be too old...
     return min_date_active - datetime.timedelta(seconds=59)
Пример #13
0
    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
Пример #14
0
 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