Code

Ticket #12232: t12232_r11366.patch

File t12232_r11366.patch, 4.5 KB (added by anonymous, 5 years ago)
  • django/contrib/admin/models.py

     
    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) 
     
    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    objects = LogEntryManager() 
    2731    class Meta: 
    2832        verbose_name = _('log entry') 
     
    4246    def is_deletion(self): 
    4347        return self.action_flag == DELETION 
    4448 
     49    def is_deleted(self): 
     50        "Returns if the log entry line is referenced to a deleted object or not" 
     51        return self.was_deleted == True 
     52 
    4553    def get_edited_object(self): 
    4654        "Returns the edited object represented by this log entry" 
    4755        return self.content_type.get_object_for_this_type(pk=self.object_id) 
  • django/contrib/admin/templates/admin/object_history.html

     
    2626        </thead> 
    2727        <tbody> 
    2828        {% for action in action_list %} 
    29         <tr> 
    30             <th scope="row">{{ action.action_time|date:_("DATETIME_FORMAT") }}</th> 
    31             <td>{{ action.user.username }}{% if action.user.get_full_name %} ({{ action.user.get_full_name }}){% endif %}</td> 
    32             <td>{{ action.change_message }}</td> 
    33         </tr> 
     29            {% if not action.is_deleted %} 
     30            <tr> 
     31                <th scope="row">{{ action.action_time|date:_("DATETIME_FORMAT") }}</th> 
     32                <td>{{ action.user.username }}{% if action.user.get_full_name %} ({{ action.user.get_full_name }}){% endif %}</td> 
     33                <td>{{ action.change_message }}</td> 
     34            </tr> 
     35            {% endif %} 
    3436        {% endfor %} 
    3537        </tbody> 
    3638    </table> 
  • django/contrib/admin/templates/admin/index.html

     
    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 %} 
     63                {% if entry.is_deleted %} 
    6464                    {{ entry.object_repr }} 
    6565                {% else %} 
    6666                    <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a> 
  • django/contrib/admin/options.py

     
    387387            content_type_id = ContentType.objects.get_for_model(object).pk, 
    388388            object_id       = object.pk, 
    389389            object_repr     = force_unicode(object), 
    390             action_flag     = ADDITION 
     390            action_flag     = ADDITION, 
     391            change_message  = _('%s was added.' % object._meta.verbose_name)             
    391392        ) 
    392393 
    393394    def log_change(self, request, object, message): 
     
    420421            content_type_id = ContentType.objects.get_for_model(self.model).pk, 
    421422            object_id       = object.pk, 
    422423            object_repr     = object_repr, 
    423             action_flag     = DELETION 
     424            action_flag     = DELETION, 
     425            change_message  = _('%s was deleted.' % object._meta.verbose_name) 
    424426        ) 
    425427 
    426428    def action_checkbox(self, obj):