Bug #1247: Add a link to attachment (added or modified) in emails
parent
bbc6635812
commit
c205f081cd
|
@ -15,7 +15,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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.
|
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:
|
if frst == scnd:
|
||||||
del diff[key]
|
del diff[key]
|
||||||
|
|
||||||
|
# Removed excluded keys
|
||||||
|
for key in excluded_keys:
|
||||||
|
if key in diff:
|
||||||
|
del diff[key]
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
|
|
|
@ -162,6 +162,7 @@ def extract_attachments(obj) -> list:
|
||||||
for attach in obj.attachments.all():
|
for attach in obj.attachments.all():
|
||||||
yield {"id": attach.id,
|
yield {"id": attach.id,
|
||||||
"filename": os.path.basename(attach.attached_file.name),
|
"filename": os.path.basename(attach.attached_file.name),
|
||||||
|
"url": attach.attached_file.url,
|
||||||
"description": attach.description,
|
"description": attach.description,
|
||||||
"is_deprecated": attach.is_deprecated,
|
"is_deprecated": attach.is_deprecated,
|
||||||
"description": attach.description,
|
"description": attach.description,
|
||||||
|
|
|
@ -166,10 +166,14 @@ class HistoryEntry(models.Model):
|
||||||
|
|
||||||
for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())):
|
for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())):
|
||||||
if aid in oldattachs and aid in newattachs:
|
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 = {
|
change = {
|
||||||
"filename": oldattachs[aid]["filename"],
|
"filename": newattachs[aid]["filename"],
|
||||||
"changes": make_diff_from_dicts(oldattachs[aid], newattachs[aid])
|
"url": newattachs[aid]["url"],
|
||||||
|
"changes": changes
|
||||||
}
|
}
|
||||||
attachments["changed"].append(change)
|
attachments["changed"].append(change)
|
||||||
elif aid in oldattachs and aid not in newattachs:
|
elif aid in oldattachs and aid not in newattachs:
|
||||||
|
|
|
@ -37,9 +37,10 @@
|
||||||
|
|
||||||
{% for att in values['new']%}
|
{% for att in values['new']%}
|
||||||
<dd style="background: #eee; padding: 5px 15px; color: #444">
|
<dd style="background: #eee; padding: 5px 15px; color: #444">
|
||||||
<i>
|
<a href="{{ att.url }}" target="_blank" style="font-weight: bold; color: #444">
|
||||||
{{ att.filename|linebreaksbr }} {% if att.description %}({{ att.description|linebreaksbr }}){% endif %}
|
{{ att.filename|linebreaksbr }}
|
||||||
</i>
|
</a>
|
||||||
|
{% if att.description %}<i> {{ att.description|linebreaksbr }}</i>{% endif %}
|
||||||
</dd>
|
</dd>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -51,7 +52,9 @@
|
||||||
|
|
||||||
{% for att in values['changed'] %}
|
{% for att in values['changed'] %}
|
||||||
<dd style="background: #eee; padding: 5px 15px; color: #444">
|
<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>
|
<ul>
|
||||||
{% if att.changes.is_deprecated %}
|
{% if att.changes.is_deprecated %}
|
||||||
{% if att.changes.is_deprecated.1 %}
|
{% if att.changes.is_deprecated.1 %}
|
||||||
|
|
Loading…
Reference in New Issue