Exemplo n.º 1
0
def listing_searchable_text(instance):
    """Fulltext search for the audit metadata
    """
    # get all snapshots
    snapshots = get_snapshots(instance)
    # extract all snapshot values, because we are not interested in the
    # fieldnames (keys)
    values = map(lambda s: s.values(), snapshots)
    # prepare a set of unified catalog data
    catalog_data = set()
    # values to skip
    skip_values = ["None", "true", "True", "false", "False"]
    # internal uid -> title cache
    uid_title_cache = {}

    # helper function to recursively unpack the snapshot values
    def append(value):
        if isinstance(value, (list, tuple)):
            map(append, value)
        elif isinstance(value, (dict)):
            map(append, value.items())
        elif isinstance(value, basestring):
            # convert unicode to UTF8
            if isinstance(value, unicode):
                value = api.safe_unicode(value).encode("utf8")
            # skip single short values
            if len(value) < 2:
                return
            # flush non meaningful values
            if value in skip_values:
                return
            # flush ISO dates
            if re.match(DATE_RX, value):
                return
            # fetch the title
            if re.match(UID_RX, value):
                if value in uid_title_cache:
                    value = uid_title_cache[value]
                else:
                    title_or_id = get_title_or_id_from_uid(value)
                    uid_title_cache[value] = title_or_id
                    value = title_or_id
            catalog_data.add(value)

    # extract all meaningful values
    for value in itertools.chain(values):
        append(value)

    return " ".join(catalog_data)
Exemplo n.º 2
0
def modifiers(instance):
    """Returns a list of all users that modified
    """
    snapshots = get_snapshots(instance)
    return map(get_actor, snapshots)
Exemplo n.º 3
0
    def folderitems(self):
        """Generate folderitems for each version
        """
        items = []
        # get the snapshots
        snapshots = get_snapshots(self.context)
        # reverse the order to get the most recent change first
        snapshots = list(reversed(snapshots))
        # set the total number of items
        self.total = len(snapshots)
        # slice a batch
        batch = snapshots[self.limit_from:self.limit_from + self.pagesize]

        for snapshot in batch:
            item = self.make_empty_item(**snapshot)
            # get the version of the snapshot
            version = get_snapshot_version(self.context, snapshot)

            # Version
            item["version"] = version

            # get the metadata of the diff
            metadata = get_snapshot_metadata(snapshot)

            # Modification Date
            m_date = metadata.get("modified")
            item["modified"] = self.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"] = self.translate_state(action)

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

            # get the previous snapshot
            prev_snapshot = get_snapshot_by_version(self.context, 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"] = "{} &rarr; {}".format(
                        self.translate_state(prev_review_state),
                        self.translate_state(review_state))

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

            # append the item
            items.append(item)

        return items