From c205f081cd04c645b8d7349c8a4a1007529fb418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Tue, 7 Oct 2014 19:04:42 +0200 Subject: [PATCH] Bug #1247: Add a link to attachment (added or modified) in emails --- taiga/base/utils/diff.py | 7 ++++++- taiga/projects/history/freeze_impl.py | 1 + taiga/projects/history/models.py | 10 +++++++--- .../templates/emails/includes/fields_diff-html.jinja | 11 +++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/taiga/base/utils/diff.py b/taiga/base/utils/diff.py index 3d4f0aa8..7c8ea034 100644 --- a/taiga/base/utils/diff.py +++ b/taiga/base/utils/diff.py @@ -15,7 +15,7 @@ # along with this program. If not, see . -def make_diff(first:dict, second:dict, not_found_value=None) -> dict: +def make_diff(first:dict, second:dict, not_found_value=None, excluded_keys:tuple=()) -> dict: """ Compute a diff between two dicts. """ @@ -39,4 +39,9 @@ def make_diff(first:dict, second:dict, not_found_value=None) -> dict: if frst == scnd: del diff[key] + # Removed excluded keys + for key in excluded_keys: + if key in diff: + del diff[key] + return diff diff --git a/taiga/projects/history/freeze_impl.py b/taiga/projects/history/freeze_impl.py index 2d350340..1af7bcf0 100644 --- a/taiga/projects/history/freeze_impl.py +++ b/taiga/projects/history/freeze_impl.py @@ -162,6 +162,7 @@ def extract_attachments(obj) -> list: for attach in obj.attachments.all(): yield {"id": attach.id, "filename": os.path.basename(attach.attached_file.name), + "url": attach.attached_file.url, "description": attach.description, "is_deprecated": attach.is_deprecated, "description": attach.description, diff --git a/taiga/projects/history/models.py b/taiga/projects/history/models.py index 9fa3deb5..809cae1c 100644 --- a/taiga/projects/history/models.py +++ b/taiga/projects/history/models.py @@ -166,10 +166,14 @@ 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]: + changes = make_diff_from_dicts(oldattachs[aid], newattachs[aid], + excluded_keys=("filename", "url")) + + if changes: change = { - "filename": oldattachs[aid]["filename"], - "changes": make_diff_from_dicts(oldattachs[aid], newattachs[aid]) + "filename": newattachs[aid]["filename"], + "url": newattachs[aid]["url"], + "changes": changes } attachments["changed"].append(change) elif aid in oldattachs and aid not in newattachs: 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 ebd2cce4..049bf6cc 100644 --- a/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja +++ b/taiga/projects/history/templates/emails/includes/fields_diff-html.jinja @@ -37,9 +37,10 @@ {% for att in values['new']%}
- - {{ att.filename|linebreaksbr }} {% if att.description %}({{ att.description|linebreaksbr }}){% endif %} - + + {{ att.filename|linebreaksbr }} + + {% if att.description %} {{ att.description|linebreaksbr }}{% endif %}
{% endfor %} {% endif %} @@ -51,7 +52,9 @@ {% for att in values['changed'] %}
- {{ att.filename|linebreaksbr }} + + {{ att.filename|linebreaksbr }} +
    {% if att.changes.is_deprecated %} {% if att.changes.is_deprecated.1 %}