Fix the history of an attachment
parent
6929b3391e
commit
047b0acb20
|
@ -0,0 +1,36 @@
|
||||||
|
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||||
|
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
|
||||||
|
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
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
|
|
@ -26,6 +26,8 @@ from taiga.mdrender.service import get_diff_of_htmls
|
||||||
from .choices import HistoryType
|
from .choices import HistoryType
|
||||||
from .choices import HISTORY_TYPE_CHOICES
|
from .choices import HISTORY_TYPE_CHOICES
|
||||||
|
|
||||||
|
from taiga.base.utils.diff import make_diff as make_diff_from_dicts
|
||||||
|
|
||||||
|
|
||||||
class HistoryEntry(models.Model):
|
class HistoryEntry(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -144,7 +146,11 @@ 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]:
|
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:
|
elif aid in oldattachs and aid not in newattachs:
|
||||||
attachments["deleted"].append(oldattachs[aid])
|
attachments["deleted"].append(oldattachs[aid])
|
||||||
elif aid not in oldattachs and aid in newattachs:
|
elif aid not in oldattachs and aid in newattachs:
|
||||||
|
|
|
@ -40,6 +40,7 @@ from django.db import transaction as tx
|
||||||
|
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.base.utils.db import get_typename_for_model_class
|
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
|
from .models import HistoryType
|
||||||
|
|
||||||
|
@ -145,20 +146,7 @@ def make_diff(oldobj:FrozenObj, newobj:FrozenObj) -> FrozenDiff:
|
||||||
first = oldobj.snapshot
|
first = oldobj.snapshot
|
||||||
second = newobj.snapshot
|
second = newobj.snapshot
|
||||||
|
|
||||||
diff = {}
|
diff = make_diff_from_dicts(first, second)
|
||||||
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])
|
|
||||||
|
|
||||||
return FrozenDiff(newobj.key, diff, newobj.snapshot)
|
return FrozenDiff(newobj.key, diff, newobj.snapshot)
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,16 @@
|
||||||
|
|
||||||
{% 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">
|
||||||
<i>{{ att.1.filename|linebreaksbr }} {% if att.1.description %}({{ att.1.description|linebreaksbr }}){% endif %}</i>
|
<b>{{ att.filename|linebreaksbr }}</b>
|
||||||
{% if att.1.is_deprecated and not att.0.is_deprecated %}
|
{% if att.changes.is_deprecated %}
|
||||||
to <b>deprecated</b>
|
{% if att.changes.is_deprecated.1 %}
|
||||||
{% elif not att.1.is_deprecated and att.0.is_deprecated %}
|
to <i>deprecated</i>
|
||||||
to <b>not deprecated</b>
|
{% else %}
|
||||||
|
to <i>not deprecated</i>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% if att.changes.description %}
|
||||||
|
to <i>att.changes.description.1</i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</dd>
|
</dd>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
{% if values.changed %}
|
{% if values.changed %}
|
||||||
* {{ _("Changed") }}
|
* {{ _("Changed") }}
|
||||||
{% for att in values['changed'] %}
|
{% for att in values['changed'] %}
|
||||||
- {{ att.1.filename|linebreaksbr }}
|
- {{ att.filename|linebreaksbr }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue