From d807c5cda89d130d2ea62f4b1e0d2488ac4494e7 Mon Sep 17 00:00:00 2001
From: root <root@ambotic.ascorp.net>
Date: Fri, 6 Jan 2012 18:10:33 +0000
Subject: [PATCH 2/3] Ticket 12232
Signed-off-by: root <root@vbox5.ascorp.net>
---
django/contrib/admin/models.py | 16 ++++++++++++++++
django/contrib/admin/templates/admin/index.html | 2 +-
.../admin/templates/admin/object_history.html | 12 +++++++-----
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py
index 0e5b8a7..5767a34 100644
a
|
b
|
class LogEntryManager(models.Manager):
|
14 | 14 | def log_action(self, user_id, content_type_id, object_id, object_repr, action_flag, change_message=''): |
15 | 15 | e = self.model(None, None, user_id, content_type_id, smart_unicode(object_id), object_repr[:200], action_flag, change_message) |
16 | 16 | e.save() |
| 17 | if (action_flag == DELETION): |
| 18 | # put all object log entries with the was_deleted flag as True |
| 19 | self.model.objects.filter(content_type=content_type_id,object_id=object_id).update(was_deleted=True) |
17 | 20 | |
18 | 21 | class LogEntry(models.Model): |
19 | 22 | action_time = models.DateTimeField(_('action time'), auto_now=True) |
… |
… |
class LogEntry(models.Model):
|
23 | 26 | object_repr = models.CharField(_('object repr'), max_length=200) |
24 | 27 | action_flag = models.PositiveSmallIntegerField(_('action flag')) |
25 | 28 | change_message = models.TextField(_('change message'), blank=True) |
| 29 | was_deleted = models.NullBooleanField(default=False, blank=False, null=True) |
26 | 30 | |
27 | 31 | objects = LogEntryManager() |
28 | 32 | |
… |
… |
class LogEntry(models.Model):
|
54 | 58 | def is_deletion(self): |
55 | 59 | return self.action_flag == DELETION |
56 | 60 | |
| 61 | def is_deleted(self): |
| 62 | "Returns if the log entry line is referenced to a deleted object or not" |
| 63 | return self.was_deleted == True |
| 64 | |
| 65 | def edited_object_still_exists(self): |
| 66 | "Check whether the edited object has been removed by a subsequent action" |
| 67 | try: |
| 68 | self.get_edited_object() |
| 69 | return True |
| 70 | except Exception: |
| 71 | return False |
| 72 | |
57 | 73 | def get_edited_object(self): |
58 | 74 | "Returns the edited object represented by this log entry" |
59 | 75 | return self.content_type.get_object_for_this_type(pk=self.object_id) |
diff --git a/django/contrib/admin/templates/admin/index.html b/django/contrib/admin/templates/admin/index.html
index a8ced39..9c5a645 100644
a
|
b
|
|
60 | 60 | <ul class="actionlist"> |
61 | 61 | {% for entry in admin_log %} |
62 | 62 | <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}"> |
63 | | {% if entry.is_deletion or not entry.get_admin_url %} |
| 63 | {% if entry.is_deleted or not entry.get_admin_url or not entry.edited_object_still_exists %} |
64 | 64 | {{ entry.object_repr }} |
65 | 65 | {% else %} |
66 | 66 | <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a> |
diff --git a/django/contrib/admin/templates/admin/object_history.html b/django/contrib/admin/templates/admin/object_history.html
index ebd1960..e563f16 100644
a
|
b
|
|
28 | 28 | </thead> |
29 | 29 | <tbody> |
30 | 30 | {% for action in action_list %} |
31 | | <tr> |
32 | | <th scope="row">{{ action.action_time|date:"DATETIME_FORMAT" }}</th> |
33 | | <td>{{ action.user.username }}{% if action.user.get_full_name %} ({{ action.user.get_full_name }}){% endif %}</td> |
34 | | <td>{{ action.change_message }}</td> |
35 | | </tr> |
| 31 | {% if not action.is_deleted %} |
| 32 | <tr> |
| 33 | <th scope="row">{{ action.action_time|date:"DATETIME_FORMAT" }}</th> |
| 34 | <td>{{ action.user.username }}{% if action.user.get_full_name %} ({{ action.user.get_full_name }}){% endif %}</td> |
| 35 | <td>{{ action.change_message }}</td> |
| 36 | </tr> |
| 37 | {% endif %} |
36 | 38 | {% endfor %} |
37 | 39 | </tbody> |
38 | 40 | </table> |