예제 #1
0
    def _import_action(self, us, action, statuses, options):
        key = make_key_from_model_object(us)
        typename = get_typename_for_model_class(UserStory)
        action_data = self._transform_action_data(us, action, statuses,
                                                  options)
        if action_data is None:
            return

        change_old = action_data['change_old']
        change_new = action_data['change_new']
        hist_type = action_data['hist_type']
        comment = action_data['comment']
        user = action_data['user']

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})

        entry = HistoryEntry.objects.create(
            user=user,
            project_id=us.project.id,
            key=key,
            type=hist_type,
            snapshot=None,
            diff=fdiff.diff,
            values=make_diff_values(typename, fdiff),
            comment=comment,
            comment_html=mdrender(us.project, comment),
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(
            created_at=action['date'])
        return HistoryEntry.objects.get(id=entry.id)
예제 #2
0
    def _import_event(self, obj, event, options, cumulative_data):
        typename = get_typename_for_model_class(type(obj))
        key = make_key_from_model_object(obj)
        event_data = self._transform_event_data(obj, event, options, cumulative_data)
        if event_data is None:
            return

        change_old = event_data['change_old']
        change_new = event_data['change_new']
        user = event_data['user']

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})
        values = make_diff_values(typename, fdiff)
        values.update(event_data['update_values'])
        entry = HistoryEntry.objects.create(
            user=user,
            project_id=obj.project.id,
            key=key,
            type=HistoryType.change,
            snapshot=None,
            diff=fdiff.diff,
            values=values,
            comment="",
            comment_html="",
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(created_at=event['created_at'])
        return HistoryEntry.objects.get(id=entry.id)
예제 #3
0
    def _import_action(self, us, action, statuses, options):
        key = make_key_from_model_object(us)
        typename = get_typename_for_model_class(UserStory)
        action_data = self._transform_action_data(us, action, statuses, options)
        if action_data is None:
            return

        change_old = action_data['change_old']
        change_new = action_data['change_new']
        hist_type = action_data['hist_type']
        comment = action_data['comment']
        user = action_data['user']

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})

        entry = HistoryEntry.objects.create(
            user=user,
            project_id=us.project.id,
            key=key,
            type=hist_type,
            snapshot=None,
            diff=fdiff.diff,
            values=make_diff_values(typename, fdiff),
            comment=comment,
            comment_html=mdrender(us.project, comment),
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(created_at=action['date'])
        return HistoryEntry.objects.get(id=entry.id)
예제 #4
0
    def _import_event(self, obj, event, options, cumulative_data):
        typename = get_typename_for_model_class(type(obj))
        key = make_key_from_model_object(obj)
        event_data = self._transform_event_data(obj, event, options, cumulative_data)
        if event_data is None:
            return

        change_old = event_data['change_old']
        change_new = event_data['change_new']
        user = event_data['user']

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})
        values = make_diff_values(typename, fdiff)
        values.update(event_data['update_values'])
        entry = HistoryEntry.objects.create(
            user=user,
            project_id=obj.project.id,
            key=key,
            type=HistoryType.change,
            snapshot=None,
            diff=fdiff.diff,
            values=values,
            comment="",
            comment_html="",
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(created_at=event['created_at'])
        return HistoryEntry.objects.get(id=entry.id)
    def _import_activity(self, obj, activity, options):
        activity_data = self._transform_activity_data(obj, activity, options)
        if activity_data is None:
            return

        change_old = activity_data["change_old"]
        change_new = activity_data["change_new"]
        hist_type = activity_data["hist_type"]
        comment = activity_data["comment"]
        user = activity_data["user"]

        key = make_key_from_model_object(activity_data["obj"])
        typename = get_typename_for_model_class(type(activity_data["obj"]))

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})

        entry = HistoryEntry.objects.create(
            user=user,
            project_id=obj.project.id,
            key=key,
            type=hist_type,
            snapshot=None,
            diff=fdiff.diff,
            values=make_diff_values(typename, fdiff),
            comment=comment,
            comment_html=mdrender(obj.project, comment),
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(
            created_at=activity["occurred_at"])
        return HistoryEntry.objects.get(id=entry.id)
예제 #6
0
    def _import_history(self, project, obj, history, options):
        key = make_key_from_model_object(obj)
        typename = get_typename_for_model_class(obj.__class__)
        history_data = self._transform_history_data(project, obj, history, options)
        if history_data is None:
            return

        change_old = history_data['change_old']
        change_new = history_data['change_new']
        hist_type = history_data['hist_type']
        comment = history_data['comment']
        user = history_data['user']

        diff = make_diff_from_dicts(change_old, change_new)
        fdiff = FrozenDiff(key, diff, {})

        values = make_diff_values(typename, fdiff)
        values.update(history_data['update_values'])

        entry = HistoryEntry.objects.create(
            user=user,
            project_id=obj.project.id,
            key=key,
            type=hist_type,
            snapshot=None,
            diff=fdiff.diff,
            values=values,
            comment=comment,
            comment_html=mdrender(obj.project, comment),
            is_hidden=False,
            is_snapshot=False,
        )
        HistoryEntry.objects.filter(id=entry.id).update(created_at=history['created'])
        return HistoryEntry.objects.get(id=entry.id)
예제 #7
0
파일: utils.py 프로젝트: sj1980/taiga-back
def attach_total_comments_to_queryset(queryset, as_field="total_comments"):
    """Attach a total comments counter to each object of the queryset.

    :param queryset: A Django projects queryset object.
    :param as_field: Attach the counter as an attribute with this name.

    :return: Queryset object with the additional `as_field` field.
    """
    model = queryset.model
    sql = """
             SELECT COUNT(history_historyentry.id)
               FROM history_historyentry
              WHERE history_historyentry.key = CONCAT('{key_prefix}', {tbl}.id) AND
                    history_historyentry.comment is not null AND
                    history_historyentry.comment != ''
          """

    typename = get_typename_for_model_class(model)

    sql = sql.format(tbl=model._meta.db_table, key_prefix="{}:".format(typename))

    queryset = queryset.extra(select={as_field: sql})
    return queryset
예제 #8
0
파일: utils.py 프로젝트: zen9073/taiga-back
def attach_total_comments_to_queryset(queryset, as_field="total_comments"):
    """Attach a total comments counter to each object of the queryset.

    :param queryset: A Django projects queryset object.
    :param as_field: Attach the counter as an attribute with this name.

    :return: Queryset object with the additional `as_field` field.
    """
    model = queryset.model
    sql = """
             SELECT COUNT(history_historyentry.id)
               FROM history_historyentry
              WHERE history_historyentry.key = CONCAT('{key_prefix}', {tbl}.id) AND
                    history_historyentry.comment is not null AND
                    history_historyentry.comment != ''
          """

    typename = get_typename_for_model_class(model)

    sql = sql.format(tbl=model._meta.db_table,
                     key_prefix="{}:".format(typename))

    queryset = queryset.extra(select={as_field: sql})
    return queryset