Exemple #1
0
def snapshot_created(instance):
    """Snapshot created date
    """
    last_snapshot = get_last_snapshot(instance)
    snapshot_created = get_created(last_snapshot)
    return api.to_date(snapshot_created)
Exemple #2
0
def action(instance):
    """Returns the last performed action
    """
    last_snapshot = get_last_snapshot(instance)
    return get_action(last_snapshot)
Exemple #3
0
def actor(instance):
    """Last modifiying user
    """
    last_snapshot = get_last_snapshot(instance)
    return get_actor(last_snapshot)
Exemple #4
0
def fullname(instance):
    """Last modifiying user
    """
    last_snapshot = get_last_snapshot(instance)
    return get_fullname(last_snapshot)
Exemple #5
0
    def folderitem(self, obj, item, index):
        """Service triggered each time an item is iterated in folderitems.
        The use of this service prevents the extra-loops in child objects.
        :obj: the instance of the class to be foldered
        :item: dict containing the properties of the object to be used by
            the template
        :index: current index of the item
        """
        obj = api.get_object(obj)

        # We are using the existing logic from the auditview
        logview = api.get_view("auditlog", context=obj, request=self.request)

        # get the last snapshot
        snapshot = get_last_snapshot(obj)
        # get the metadata of the last snapshot
        metadata = get_snapshot_metadata(snapshot)

        title = obj.Title()
        url = obj.absolute_url()
        auditlog_url = "{}/@@auditlog".format(url)

        # Title
        item["title"] = title
        # Link the title to the auditlog of the object
        item["replace"]["title"] = get_link(auditlog_url, value=title)

        # Version
        version = get_snapshot_version(obj, snapshot)
        item["version"] = version

        # Modification Date
        m_date = metadata.get("modified")
        item["modified"] = logview.to_localized_time(m_date)

        # Actor
        actor = metadata.get("actor")
        item["actor"] = actor

        # Fullname
        properties = api.get_user_properties(actor)
        item["fullname"] = properties.get("fullname", actor)

        # Roles
        roles = metadata.get("roles", [])
        item["roles"] = ", ".join(roles)

        # Remote Address
        remote_address = metadata.get("remote_address")
        item["remote_address"] = remote_address

        # Action
        action = metadata.get("action")
        item["action"] = logview.translate_state(action)

        # Review State
        review_state = metadata.get("review_state")
        item["review_state"] = logview.translate_state(review_state)

        # get the previous snapshot
        prev_snapshot = get_snapshot_by_version(obj, version - 1)
        if prev_snapshot:
            prev_metadata = get_snapshot_metadata(prev_snapshot)
            prev_review_state = prev_metadata.get("review_state")
            if prev_review_state != review_state:
                item["replace"]["review_state"] = "{} → {}".format(
                    logview.translate_state(prev_review_state),
                    logview.translate_state(review_state))

            # Rendered Diff
            diff = compare_snapshots(snapshot, prev_snapshot)
            item["diff"] = logview.render_diff(diff)

        return item