From 7d30ee5e00deb350b4c1e5b33f1eaa2e78b7b4de Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 17 Jun 2015 17:11:15 +0200 Subject: [PATCH] Fixing history import and export --- taiga/export_import/serializers.py | 4 +++- taiga/export_import/service.py | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/taiga/export_import/serializers.py b/taiga/export_import/serializers.py index 0aca3999..ec0ed783 100644 --- a/taiga/export_import/serializers.py +++ b/taiga/export_import/serializers.py @@ -241,7 +241,9 @@ class HistoryExportSerializerMixin(serializers.ModelSerializer): history = serializers.SerializerMethodField("get_history") def get_history(self, obj): - history_qs = history_service.get_history_queryset_by_model_instance(obj) + history_qs = history_service.get_history_queryset_by_model_instance(obj, + types=(history_models.HistoryType.change, history_models.HistoryType.create,)) + return HistoryExportSerializer(history_qs, many=True).data diff --git a/taiga/export_import/service.py b/taiga/export_import/service.py index 32ee9710..bd3049b9 100644 --- a/taiga/export_import/service.py +++ b/taiga/export_import/service.py @@ -22,7 +22,7 @@ from django.template.defaultfilters import slugify from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist -from taiga.projects.history.services import make_key_from_model_object +from taiga.projects.history.services import make_key_from_model_object, take_snapshot from taiga.timeline.service import build_project_namespace from taiga.projects.references import sequences as seq from taiga.projects.references import models as refs @@ -229,9 +229,13 @@ def store_task(project, data): for task_attachment in data.get("attachments", []): store_attachment(project, serialized.object, task_attachment) - for history in data.get("history", []): + history_entries = data.get("history", []) + for history in history_entries: store_history(project, serialized.object, history) + if not history_entries: + take_snapshot(serialized.object, user=serialized.object.owner) + custom_attributes_values = data.get("custom_attributes_values", None) if custom_attributes_values: custom_attributes = serialized.object.project.taskcustomattributes.all().values('id', 'name') @@ -319,9 +323,13 @@ def store_wiki_page(project, wiki_page): for attachment in wiki_page.get("attachments", []): store_attachment(project, serialized.object, attachment) - for history in wiki_page.get("history", []): + history_entries = wiki_page.get("history", []) + for history in history_entries: store_history(project, serialized.object, history) + if not history_entries: + take_snapshot(serialized.object, user=serialized.object.owner) + return serialized add_errors("wiki_pages", serialized.errors) @@ -381,9 +389,13 @@ def store_user_story(project, data): for role_point in data.get("role_points", []): store_role_point(project, serialized.object, role_point) - for history in data.get("history", []): + history_entries = data.get("history", []) + for history in history_entries: store_history(project, serialized.object, history) + if not history_entries: + take_snapshot(serialized.object, user=serialized.object.owner) + custom_attributes_values = data.get("custom_attributes_values", None) if custom_attributes_values: custom_attributes = serialized.object.project.userstorycustomattributes.all().values('id', 'name') @@ -434,9 +446,13 @@ def store_issue(project, data): for attachment in data.get("attachments", []): store_attachment(project, serialized.object, attachment) - for history in data.get("history", []): + history_entries = data.get("history", []) + for history in history_entries: store_history(project, serialized.object, history) + if not history_entries: + take_snapshot(serialized.object, user=serialized.object.owner) + custom_attributes_values = data.get("custom_attributes_values", None) if custom_attributes_values: custom_attributes = serialized.object.project.issuecustomattributes.all().values('id', 'name')