[damned-lies] Fixed crash in vertimus_diff view if action has no person



commit 48dd04bcd37e03afeeb2faad3311540335b2fe58
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Oct 16 09:42:04 2021 +0200

    Fixed crash in vertimus_diff view if action has no person

 vertimus/models.py      | 6 +++++-
 vertimus/tests/tests.py | 4 ++++
 vertimus/views.py       | 6 +++---
 3 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index 5472a6a6..a6b0ea3f 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -379,6 +379,10 @@ class ActionAbstract(models.Model):
     def description(self):
         return dict(ACTION_NAMES).get(self.name, None)
 
+    @property
+    def person_name(self):
+        return self.person.name if self.person else gettext('deleted account')
+
     @property
     def most_uptodate_file(self):
         return self.merged_file if self.merged_file else self.file
@@ -429,7 +433,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 if action.person else gettext('deleted account'),
+                            'name': action.person_name,
                             'date': action.created},
                     })
         return history
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 9916f7b9..455ee58b 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -679,6 +679,10 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
             response,
             '<a href="%s">Latest POT file</a>' % str(pot_location).split('scratch')[1]
         )
+        # Should also work if action persons were deleted
+        self.pt.delete()
+        response = self.client.get(diff_url)
+        self.assertContains(response, 'Latest POT file')
 
     def test_uploaded_file_validation(self):
         # Test a non valid po file
diff --git a/vertimus/views.py b/vertimus/views.py
index c749935f..b7149721 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -185,7 +185,7 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
 
     descr_1 = _('<a href="%(url)s">Uploaded file</a> by %(name)s on %(date)s') % {
         'url': action_1.most_uptodate_file.url,
-        'name': action_1.person.name,
+        'name': action_1.person_name,
         'date': action_1.created
     }
 
@@ -195,7 +195,7 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
         file_path_2 = action_2.most_uptodate_filepath
         descr_2 = _('<a href="%(url)s">Uploaded file</a> by %(name)s on %(date)s') % {
             'url': action_2.most_uptodate_file.url,
-            'name': action_2.person.name,
+            'name': action_2.person_name,
             'date': action_2.created,
         }
     else:
@@ -208,7 +208,7 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
             file_path_2 = action_2.most_uptodate_filepath
             descr_2 = _('<a href="%(url)s">Uploaded file</a> by %(name)s on %(date)s') % {
                 'url': action_2.most_uptodate_file.url,
-                'name': action_2.person.name,
+                'name': action_2.person_name,
                 'date': action_2.created,
             }
         else:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]