diff --git a/taiga/base/utils/diff.py b/taiga/base/utils/diff.py new file mode 100644 index 00000000..cff9b15e --- /dev/null +++ b/taiga/base/utils/diff.py @@ -0,0 +1,36 @@ +# Copyright (C) 2014 Andrey Antukh +# Copyright (C) 2014 Jesús Espino +# Copyright (C) 2014 David Barragán +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +def make_diff(first:dict, second:dict, not_found_value=None) -> dict: + """ + Compute a diff between two dicts. + """ + diff = {} + + # Check all keys in first dict + for key in first: + if key not in second: + diff[key] = (first[key], not_found_value) + elif first[key] != second[key]: + diff[key] = (first[key], second[key]) + + # Check all keys in second dict to find missing + for key in second: + if key not in first: + diff[key] = (not_found_value, second[key]) + + return diff diff --git a/taiga/projects/history/models.py b/taiga/projects/history/models.py index cbbb5085..e2e1f67b 100644 --- a/taiga/projects/history/models.py +++ b/taiga/projects/history/models.py @@ -26,6 +26,8 @@ from taiga.mdrender.service import get_diff_of_htmls from .choices import HistoryType from .choices import HISTORY_TYPE_CHOICES +from taiga.base.utils.diff import make_diff as make_diff_from_dicts + class HistoryEntry(models.Model): """ @@ -144,7 +146,11 @@ class HistoryEntry(models.Model): for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())): if aid in oldattachs and aid in newattachs: if oldattachs[aid] != newattachs[aid]: - attachments["changed"].append([oldattachs[aid],newattachs[aid]]) + change = { + "filename": oldattachs[aid]["filename"], + "changes": make_diff_from_dicts(oldattachs[aid], newattachs[aid]) + } + attachments["changed"].append(change) elif aid in oldattachs and aid not in newattachs: attachments["deleted"].append(oldattachs[aid]) elif aid not in oldattachs and aid in newattachs: diff --git a/taiga/projects/history/services.py b/taiga/projects/history/services.py index e04068ed..209e21c9 100644 --- a/taiga/projects/history/services.py +++ b/taiga/projects/history/services.py @@ -40,6 +40,7 @@ from django.db import transaction as tx from taiga.mdrender.service import render as mdrender from taiga.base.utils.db import get_typename_for_model_class +from taiga.base.utils.diff import make_diff as make_diff_from_dicts from .models import HistoryType @@ -145,20 +146,7 @@ def make_diff(oldobj:FrozenObj, newobj:FrozenObj) -> FrozenDiff: first = oldobj.snapshot second = newobj.snapshot - diff = {} - not_found_value = None - - # Check all keys in first dict - for key in first: - if key not in second: - diff[key] = (first[key], not_found_value) - elif first[key] != second[key]: - diff[key] = (first[key], second[key]) - - # Check all keys in second dict to find missing - for key in second: - if key not in first: - diff[key] = (not_found_value, second[key]) + diff = make_diff_from_dicts(first, second) return FrozenDiff(newobj.key, diff, newobj.snapshot) diff --git a/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja b/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja index 769a0579..c6fe66f7 100644 --- a/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja +++ b/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja @@ -49,11 +49,16 @@ {% for att in values['changed'] %}
- {{ att.1.filename|linebreaksbr }} {% if att.1.description %}({{ att.1.description|linebreaksbr }}){% endif %} - {% if att.1.is_deprecated and not att.0.is_deprecated %} - to deprecated - {% elif not att.1.is_deprecated and att.0.is_deprecated %} - to not deprecated + {{ att.filename|linebreaksbr }} + {% if att.changes.is_deprecated %} + {% if att.changes.is_deprecated.1 %} + to deprecated + {% else %} + to not deprecated + {% endif %} + {% endif %} + {% if att.changes.description %} + to att.changes.description.1 {% endif %}
{% endfor %} diff --git a/taiga/projects/history/templates/emails/includes/fields_diff-text.jinja b/taiga/projects/history/templates/emails/includes/fields_diff-text.jinja index 7ee49bfe..c87e318a 100644 --- a/taiga/projects/history/templates/emails/includes/fields_diff-text.jinja +++ b/taiga/projects/history/templates/emails/includes/fields_diff-text.jinja @@ -22,7 +22,7 @@ {% if values.changed %} * {{ _("Changed") }} {% for att in values['changed'] %} - - {{ att.1.filename|linebreaksbr }} + - {{ att.filename|linebreaksbr }} {% endfor %} {% endif %}