Bug #1247: Add a link to attachment (added or modified) in emails

remotes/origin/enhancement/email-actions
David Barragán Merino 2014-10-07 19:04:42 +02:00
parent bbc6635812
commit c205f081cd
4 changed files with 21 additions and 8 deletions

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -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,

View File

@ -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:

View File

@ -37,9 +37,10 @@
{% for att in values['new']%}
<dd style="background: #eee; padding: 5px 15px; color: #444">
<i>
{{ att.filename|linebreaksbr }} {% if att.description %}({{ att.description|linebreaksbr }}){% endif %}
</i>
<a href="{{ att.url }}" target="_blank" style="font-weight: bold; color: #444">
{{ att.filename|linebreaksbr }}
</a>
{% if att.description %}<i> {{ att.description|linebreaksbr }}</i>{% endif %}
</dd>
{% endfor %}
{% endif %}
@ -51,7 +52,9 @@
{% for att in values['changed'] %}
<dd style="background: #eee; padding: 5px 15px; color: #444">
<b>{{ att.filename|linebreaksbr }}</b>
<a href="{{ att.url }}" target="_blank" style="font-weight: bold; color: #444">
{{ att.filename|linebreaksbr }}
</a>
<ul>
{% if att.changes.is_deprecated %}
{% if att.changes.is_deprecated.1 %}