Ticket #8472: recent_action_on_appindex.diff
File recent_action_on_appindex.diff, 4.9 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/templatetags/log.py
1 1 from django import template 2 2 from django.contrib.admin.models import LogEntry 3 from django.contrib.contenttypes.models import ContentType 3 4 4 5 register = template.Library() 5 6 6 7 class AdminLogNode(template.Node): 7 def __init__(self, limit, varname, user ):8 self.limit, self.varname, self.user = limit, varname, user8 def __init__(self, limit, varname, user, current_app): 9 self.limit, self.varname, self.user, self.current_app = limit, varname, user, current_app 9 10 10 11 def __repr__(self): 11 12 return "<GetAdminLog Node>" … … 17 18 user_id = self.user 18 19 if not user_id.isdigit(): 19 20 user_id = context[self.user].id 20 context[self.varname] = LogEntry.objects.filter(user__id__exact=user_id).select_related('content_type', 'user')[:self.limit] 21 filters = {'user__id__exact': user_id} 22 23 if self.current_app and len(context['app_list']) == 1: # If there are more than one app don't use the filter 24 current_app = context['app_list'][0]['name'].lower() 25 contenttypes = ContentType.objects.filter(app_label=current_app) 26 ids = [contenttype.id for contenttype in contenttypes] 27 filters['content_type__in'] = ids 28 29 context[self.varname] = LogEntry.objects.filter(**filters).select_related('content_type', 'user')[:self.limit] 21 30 return '' 22 31 23 32 class DoGetAdminLog: … … 26 35 27 36 Usage:: 28 37 29 {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %}38 {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] for_current_app %} 30 39 31 40 Examples:: 32 41 42 {% get_admin_log 10 as admin_log for_user 23 for_current_app %} 33 43 {% get_admin_log 10 as admin_log for_user 23 %} 34 44 {% get_admin_log 10 as admin_log for_user user %} 35 45 {% get_admin_log 10 as admin_log %} 36 46 47 The option ``for_current_app`` should be used only inside of an 48 application index. It will look up for the current app inside of app_list. 49 If this option is used on any other place, it just won't make any filter. 37 50 Note that ``context_var_containing_user_obj`` can be a hard-coded integer 38 51 (user ID) or the name of a template context variable containing the user 39 52 object whose ID you want. … … 52 65 if len(tokens) > 4: 53 66 if tokens[4] != 'for_user': 54 67 raise template.TemplateSyntaxError("Fourth argument in '%s' must be 'for_user'" % self.tag_name) 55 return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None)) 68 if len(tokens) > 6: 69 if tokens[6] != 'for_current_app': 70 raise template.TemplateSyntaxError("Fifth argument in '%s' must be 'for_current_app'" % self.tag_name) 71 return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None), current_app=(len(tokens) > 6)) 56 72 57 73 register.tag('get_admin_log', DoGetAdminLog('get_admin_log')) -
django/contrib/admin/templates/admin/app_index.html
12 12 13 13 {% endif %} 14 14 15 {% block sidebar %}{% endblock %} 16 No newline at end of file 15 {% block sidebar %} 16 <div id="content-related"> 17 <div class="module" id="recent-actions-module"> 18 <h2>{% trans 'Recent Actions' %}</h2> 19 <h3>{% trans 'My Actions' %}</h3> 20 {% load log %} 21 {% get_admin_log 10 as admin_log for_user user for_current_app %} 22 {% if not admin_log %} 23 <p>{% trans 'None available' %}</p> 24 {% else %} 25 <ul class="actionlist"> 26 {% for entry in admin_log %} 27 <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}"> 28 {% if entry.is_deletion or not entry.get_admin_url %} 29 {{ entry.object_repr }} 30 {% else %} 31 <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a> 32 {% endif %} 33 <br/> 34 {% if entry.content_type %} 35 <span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span> 36 {% else %} 37 <span class="mini quiet">{% trans 'Unknown content' %}</span> 38 {% endif %} 39 </li> 40 {% endfor %} 41 </ul> 42 {% endif %} 43 </div> 44 </div> 45 {% endblock %}