コード例 #1
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)
コード例 #2
0
 def expand_containers(self, items, containers, _url, chain=(), context=None):
     #seen_context = False
     _url = _url.rstrip("/")
     current = False
     
     for key, container in containers:
         assert IAlchemistContainer.providedBy(container)
         
         # do not include doc containers for docs who do not specifically 
         # declare the parent group instance as a workspace.group_name
         if IDoc.implementedBy(container.domain_model):
             group = get_group_for_context(container)
             assert IGroup.providedBy(group)
             doc_type_key = naming.polymorphic_identity(container.domain_model)
             if not group.is_type_workspaced(doc_type_key):
                 continue
         
         label = container.domain_model.__name__
         descriptor = utils.get_descriptor(container.domain_model)
         order = 999
         if descriptor:
             order = descriptor.order
             label = getattr(descriptor, "container_name", None) or \
                 getattr(descriptor, "display_name", None)
         
         if context is not None:
             current = container.__name__ == context.__name__
         selected = not len(chain) and current
         if current:
             #seen_context = True
             nodes = self.expand(chain)
         else:
             nodes = ()
         
         key_url = "%s/%s" % (_url, key)
         items.append({
                 "id": self.get_nav_entry_id(key_url),
                 "order": order,
                 "label": translate(label, 
                     target_language=get_default_language(),
                     domain="bungeni"),
                 "url": key_url,
                 "current": current,
                 "selected": selected,
                 "kind": "container",
                 "nodes": nodes,
             })
     items.sort(key=lambda item:(item['order'], item['label']))
コード例 #3
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)