Ticket #1611: 0002-Ticket-12232.patch

File 0002-Ticket-12232.patch, 4.3 KB (added by anonymous, 12 years ago)

Patch for ticket 12232/1611 against 1.4.2. Adds a new field to LogEntry so you need to migrate (south should take care of it)

  • django/contrib/admin/models.py

    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):  
    1414    def log_action(self, user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):
    1515        e = self.model(None, None, user_id, content_type_id, smart_unicode(object_id), object_repr[:200], action_flag, change_message)
    1616        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)
    1720
    1821class LogEntry(models.Model):
    1922    action_time = models.DateTimeField(_('action time'), auto_now=True)
    class LogEntry(models.Model):  
    2326    object_repr = models.CharField(_('object repr'), max_length=200)
    2427    action_flag = models.PositiveSmallIntegerField(_('action flag'))
    2528    change_message = models.TextField(_('change message'), blank=True)
     29    was_deleted = models.NullBooleanField(default=False, blank=False, null=True)
    2630
    2731    objects = LogEntryManager()
    2832
    class LogEntry(models.Model):  
    5458    def is_deletion(self):
    5559        return self.action_flag == DELETION
    5660
     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
    5773    def get_edited_object(self):
    5874        "Returns the edited object represented by this log entry"
    5975        return self.content_type.get_object_for_this_type(pk=self.object_id)
  • django/contrib/admin/templates/admin/index.html

    diff --git a/django/contrib/admin/templates/admin/index.html b/django/contrib/admin/templates/admin/index.html
    index a8ced39..9c5a645 100644
    a b  
    6060            <ul class="actionlist">
    6161            {% for entry in admin_log %}
    6262            <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 %}
    6464                    {{ entry.object_repr }}
    6565                {% else %}
    6666                    <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
  • django/contrib/admin/templates/admin/object_history.html

    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  
    2828        </thead>
    2929        <tbody>
    3030        {% 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 %}
    3638        {% endfor %}
    3739        </tbody>
    3840    </table>
Back to Top