Esempio n. 1
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = User.objects.get(id=instance.user["pk"])

    extra_data = {
        "values_diff": instance.values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    _push_to_timelines(project, user, obj, event_type, extra_data=extra_data)
Esempio n. 2
0
def generate_timeline(initial_date, final_date, project_id):
    if initial_date or final_date or project_id:
        timelines = Timeline.objects.all()
        if initial_date:
            timelines = timelines.filter(created__gte=initial_date)
        if final_date:
            timelines = timelines.filter(created__lt=final_date)
        if project_id:
            timelines = timelines.filter(project__id=project_id)

        timelines.delete()

    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        projects = Project.objects.order_by("created_date")
        history_entries = HistoryEntry.objects.order_by("created_at")

        if initial_date:
            projects = projects.filter(created_date__gte=initial_date)
            history_entries = history_entries.filter(created_at__gte=initial_date)

        if final_date:
            projects = projects.filter(created_date__lt=final_date)
            history_entries = history_entries.filter(created_at__lt=final_date)

        if project_id:
            project = Project.objects.get(id=project_id)
            epic_keys = ['epics.epic:%s'%(id) for id in project.epics.values_list("id", flat=True)]
            us_keys = ['userstories.userstory:%s'%(id) for id in project.user_stories.values_list("id",
                                                                                                  flat=True)]
            tasks_keys = ['tasks.task:%s'%(id) for id in project.tasks.values_list("id", flat=True)]
            issue_keys = ['issues.issue:%s'%(id) for id in project.issues.values_list("id", flat=True)]
            wiki_keys = ['wiki.wikipage:%s'%(id) for id in project.wiki_pages.values_list("id", flat=True)]
            keys = epic_keys + us_keys + tasks_keys + issue_keys + wiki_keys

            projects = projects.filter(id=project_id)
            history_entries = history_entries.filter(key__in=keys)

            #Memberships
            for membership in project.memberships.exclude(user=None).exclude(user=project.owner):
                _push_to_timelines(project, membership.user, membership, "create", membership.created_at)

        for project in projects.iterator():
            print("Project:", project)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project, project.owner, project, "create", project.created_date,
                               extra_data=extra_data)
            del extra_data

        for historyEntry in history_entries.iterator():
            print("History entry:", historyEntry.created_at)
            try:
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")

    bulk_creator.flush()
Esempio n. 3
0
def generate_timeline(initial_date, final_date, project_id):
    if initial_date or final_date or project_id:
        timelines = Timeline.objects.all()
        if initial_date:
            timelines = timelines.filter(created__gte=initial_date)
        if final_date:
            timelines = timelines.filter(created__lt=final_date)
        if project_id:
            timelines = timelines.filter(project__id=project_id)

        timelines.delete()

    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        projects = Project.objects.order_by("created_date")
        history_entries = HistoryEntry.objects.order_by("created_at")

        if initial_date:
            projects = projects.filter(created_date__gte=initial_date)
            history_entries = history_entries.filter(created_at__gte=initial_date)

        if final_date:
            projects = projects.filter(created_date__lt=final_date)
            history_entries = history_entries.filter(created_at__lt=final_date)

        if project_id:
            project = Project.objects.get(id=project_id)
            us_keys = ['userstories.userstory:%s'%(id) for id in project.user_stories.values_list("id", flat=True)]
            tasks_keys = ['tasks.task:%s'%(id) for id in project.tasks.values_list("id", flat=True)]
            issue_keys = ['issues.issue:%s'%(id) for id in project.issues.values_list("id", flat=True)]
            wiki_keys = ['wiki.wikipage:%s'%(id) for id in project.wiki_pages.values_list("id", flat=True)]
            keys = us_keys + tasks_keys + issue_keys + wiki_keys

            projects = projects.filter(id=project_id)
            history_entries = history_entries.filter(key__in=keys)

            #Memberships
            for membership in project.memberships.exclude(user=None).exclude(user=project.owner):
                bulk_creator.created = membership.created_at
                _push_to_timelines(project, membership.user, membership, "create")

        for project in projects.iterator():
            bulk_creator.created = project.created_date
            print("Project:", bulk_creator.created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project, project.owner, project, "create", extra_data=extra_data)
            del extra_data

        for historyEntry in history_entries.iterator():
            print("History entry:", historyEntry.created_at)
            try:
                bulk_creator.created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")

    bulk_creator.flush()
Esempio n. 4
0
def generate_timeline(apps, schema_editor):
    global created
    global timelime_objects
    with patch('taiga.timeline.service._add_to_object_timeline',
               new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        for project in Project.objects.order_by("created_date").iterator():
            created = project.created_date
            print("Project:", created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project,
                               project.owner,
                               project,
                               "create",
                               extra_data=extra_data)

        Timeline.objects.bulk_create(timelime_objects, batch_size=10000)
        timelime_objects = []

        for historyEntry in HistoryEntry.objects.order_by(
                "created_at").iterator():
            print("History entry:", historyEntry.created_at)
            try:
                created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")

        Timeline.objects.bulk_create(timelime_objects, batch_size=10000)
def generate_timeline(apps, schema_editor):
    global created
    global timelime_objects
    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        for project in Project.objects.order_by("created_date").iterator():
            created = project.created_date
            print("Project:", created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project, project.owner, project, "create", extra_data=extra_data)

        Timeline.objects.bulk_create(timelime_objects, batch_size=10000)
        timelime_objects = []

        for historyEntry in HistoryEntry.objects.order_by("created_at").iterator():
            print("History entry:", historyEntry.created_at)
            try:
                created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")

        Timeline.objects.bulk_create(timelime_objects, batch_size=10000)
Esempio n. 6
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = User.objects.get(id=instance.user["pk"])

    extra_data = {
        "values_diff": instance.values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    _push_to_timelines(project, user, obj, event_type, extra_data=extra_data)
Esempio n. 7
0
def generate_timeline():
    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Users api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        users = get_user_model().objects.order_by("date_joined")
        for user in users.iterator():
            print("User:"******"values_diff": {},
                "user": extract_user_info(user),
            }
def generate_timeline():
    with patch("taiga.timeline.service._add_to_object_timeline", new=custom_add_to_object_timeline):
        # Users api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        users = User.objects.order_by("date_joined")
        for user in users.iterator():
            print("User:"******"values_diff": {}, "user": extract_user_info(user)}
            _push_to_timelines(None, user, user, "create", user.date_joined, extra_data=extra_data)
            del extra_data

    bulk_creator.flush()
Esempio n. 9
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    if instance.user["pk"] is None:
        return None

    refresh_totals = getattr(instance, "refresh_totals", True)

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = get_user_model().objects.get(id=instance.user["pk"])
    values_diff = instance.values_diff
    _clean_description_fields(values_diff)

    extra_data = {
        "values_diff": values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    # Detect deleted comment
    if instance.delete_comment_date:
        extra_data["comment_deleted"] = True

    # Detect edited comment
    if instance.comment_versions is not None and len(
            instance.comment_versions) > 0:
        extra_data["comment_edited"] = True

    created_datetime = instance.created_at
    _push_to_timelines(
        project,
        user,
        obj,
        event_type,
        created_datetime,
        extra_data=extra_data,
        refresh_totals=refresh_totals,
    )
def generate_timeline():
    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Users api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        users = User.objects.order_by("date_joined")
        for user in users.iterator():
            print("User:"******"values_diff": {},
                "user": extract_user_info(user),
            }
            _push_to_timelines(None, user, user, "create", user.date_joined, extra_data=extra_data)
            del extra_data

    bulk_creator.flush()
Esempio n. 11
0
def generate_timeline(initial_date, final_date):
    if initial_date or final_date:
        timelines = Timeline.objects.all()
        if initial_date:
            timelines = timelines.filter(created__gte=initial_date)
        if final_date:
            timelines = timelines.filter(created__lt=final_date)

        timelines.delete()

    with patch('taiga.timeline.service._add_to_object_timeline',
               new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        projects = Project.objects.order_by("created_date")
        history_entries = HistoryEntry.objects.order_by("created_at")

        if initial_date:
            projects = projects.filter(created_date__gte=initial_date)
            history_entries = history_entries.filter(
                created_at__gte=initial_date)

        if final_date:
            projects = projects.filter(created_date__lt=final_date)
            history_entries = history_entries.filter(created_at__lt=final_date)

        for project in projects.iterator():
            bulk_creator.created = project.created_date
            print("Project:", bulk_creator.created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project,
                               project.owner,
                               project,
                               "create",
                               extra_data=extra_data)
            del extra_data

        for historyEntry in history_entries.iterator():
            print("History entry:", historyEntry.created_at)
            try:
                bulk_creator.created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")
Esempio n. 12
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    if instance.user["pk"] is None:
        return None

    refresh_totals = getattr(instance, "refresh_totals", True)

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = get_user_model().objects.get(id=instance.user["pk"])
    values_diff = instance.values_diff
    _clean_description_fields(values_diff)

    extra_data = {
        "values_diff": values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    # Detect deleted comment
    if instance.delete_comment_date:
        extra_data["comment_deleted"] = True

    # Detect edited comment
    if instance.comment_versions is not None and len(instance.comment_versions)>0:
        extra_data["comment_edited"] = True

    created_datetime = instance.created_at
    _push_to_timelines(project, user, obj, event_type, created_datetime, extra_data=extra_data, refresh_totals=refresh_totals)
Esempio n. 13
0
def generate_timeline():
    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        for project in queryset_iterator(Project.objects.order_by("created_date")):
            bulk_creator.created = project.created_date
            print("Project:", bulk_creator.created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project, project.owner, project, "create", extra_data=extra_data)
            del extra_data

        for historyEntry in queryset_iterator(HistoryEntry.objects.order_by("created_at")):
            print("History entry:", historyEntry.created_at)
            try:
                bulk_creator.created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")
Esempio n. 14
0
def generate_timeline(initial_date, final_date):
    if initial_date or final_date:
        timelines = Timeline.objects.all()
        if initial_date:
            timelines = timelines.filter(created__gte=initial_date)
        if final_date:
            timelines = timelines.filter(created__lt=final_date)

        timelines.delete()

    with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline):
        # Projects api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case
        projects = Project.objects.order_by("created_date")
        history_entries = HistoryEntry.objects.order_by("created_at")

        if initial_date:
            projects = projects.filter(created_date__gte=initial_date)
            history_entries = history_entries.filter(created_at__gte=initial_date)

        if final_date:
            projects = projects.filter(created_date__lt=final_date)
            history_entries = history_entries.filter(created_at__lt=final_date)

        for project in projects.iterator():
            bulk_creator.created = project.created_date
            print("Project:", bulk_creator.created)
            extra_data = {
                "values_diff": {},
                "user": extract_user_info(project.owner),
            }
            _push_to_timelines(project, project.owner, project, "create", extra_data=extra_data)
            del extra_data

        for historyEntry in history_entries.iterator():
            print("History entry:", historyEntry.created_at)
            try:
                bulk_creator.created = historyEntry.created_at
                on_new_history_entry(None, historyEntry, None)
            except ObjectDoesNotExist as e:
                print("Ignoring")