[damned-lies] Prevent cascade deleting relate actions of deleted accounts
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Prevent cascade deleting relate actions of deleted accounts
- Date: Mon, 22 Mar 2021 21:30:42 +0000 (UTC)
commit 0ba0c5d2ed45728bc433a78927be7db3235e3177
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Mar 22 22:29:22 2021 +0100
Prevent cascade deleting relate actions of deleted accounts
people/templatetags/people.py | 4 ++--
templates/vertimus/vertimus_detail.html | 6 +++++-
.../migrations/0008_actions_on_delete_setnull.py | 22 ++++++++++++++++++++++
vertimus/models.py | 4 ++--
4 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/people/templatetags/people.py b/people/templatetags/people.py
index 4770c69f..3acf4616 100644
--- a/people/templatetags/people.py
+++ b/people/templatetags/people.py
@@ -26,7 +26,7 @@ def people_list(lst):
@register.filter
def people_image(person):
nobody = settings.STATIC_URL + "img/nobody.png"
- if person.avatar_service:
+ if person and person.avatar_service:
digest = hashlib.md5(person.email.lower().encode("utf-8")).hexdigest()
url = AVATAR_SERVICES[person.avatar_service].format(
hash=digest,
@@ -36,7 +36,7 @@ def people_image(person):
tag = format_html(
'<img class="img-circle" src="{url}" alt="{alt}" crossorigin="anonymous">', url=url,
alt=_("avatar icon")
)
- elif person.image:
+ elif person and person.image:
tag = format_html(
'<img class="img-circle" src="{}" alt="{}" onerror="this.onerror = null; this.src=\'{}\'">',
person.image, person.name, nobody
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 19ee8857..6b43c880 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -192,7 +192,11 @@ $(document).ready(function() {
<div class="vertimus_action">
<div class="vertimus_action_head">
<div class="face_image">{{ action.person|people_image }}</div>
- <a href="{{ action.person.get_absolute_url }}">{{ action.person.name }}</a><br>
+ {% if action.person %}
+ <a href="{{ action.person.get_absolute_url }}">{{ action.person.name }}</a><br>
+ {% else %}
+ <em>{% trans "deleted account" %}</em><br>
+ {% endif %}
{% if action.file or action.comment %}
<a name="{{ action.id }}" href="#{{ action.id }}" title="{% trans 'Link to this comment' %}">
<img alt="link comment icon" class="action_icons" src="{{ STATIC_URL }}img/share.png">
diff --git a/vertimus/migrations/0008_actions_on_delete_setnull.py
b/vertimus/migrations/0008_actions_on_delete_setnull.py
new file mode 100644
index 00000000..63815923
--- /dev/null
+++ b/vertimus/migrations/0008_actions_on_delete_setnull.py
@@ -0,0 +1,22 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('people', '__first__'),
+ ('vertimus', '0006_pofile_path_relative'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='action',
+ name='person',
+ field=models.ForeignKey(null=True, on_delete=models.deletion.SET_NULL, to='people.person'),
+ ),
+ migrations.AlterField(
+ model_name='actionarchived',
+ name='person',
+ field=models.ForeignKey(null=True, on_delete=models.deletion.SET_NULL, to='people.person'),
+ ),
+ ]
diff --git a/vertimus/models.py b/vertimus/models.py
index 3dc51eda..d1c983f3 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -348,7 +348,7 @@ class MergedPoFile(PoFile):
class ActionAbstract(models.Model):
""" Common model for Action and ActionArchived """
state_db = models.ForeignKey(State, on_delete=models.CASCADE)
- person = models.ForeignKey(Person, on_delete=models.CASCADE)
+ person = models.ForeignKey(Person, null=True, on_delete=models.SET_NULL)
name = models.SlugField(max_length=8)
created = models.DateTimeField(editable=False)
@@ -430,7 +430,7 @@ class ActionAbstract(models.Model):
file_history.insert(0, {
'action_id': action.id,
'title': gettext("Uploaded file by %(name)s on %(date)s") % {
- 'name': action.person.name,
+ 'name': action.person.name if action.person else gettext('deleted account'),
'date': action.created},
})
return history
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]