Ticket #8472: recent_action_on_appindex_v2.diff
File recent_action_on_appindex_v2.diff, 4.5 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, for_app): 9 self.limit, self.varname, self.user, self.for_app = limit, varname, user, for_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.for_app: 24 app_name = template.FilterExpression(self.for_app, template.Parser('')).resolve(context) 25 contenttypes = ContentType.objects.filter(app_label=app_name.lower()) 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_app [appname] %} 30 39 31 40 Examples:: 32 41 42 {% get_admin_log 10 as admin_log for_user 23 for_app "appname" %} 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 %} … … 52 62 if len(tokens) > 4: 53 63 if tokens[4] != 'for_user': 54 64 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)) 65 if len(tokens) > 6: 66 if tokens[6] != 'for_app': 67 raise template.TemplateSyntaxError("Fifth argument in '%s' must be 'for_app'" % self.tag_name) 68 return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None), for_app=(len(tokens) > 7 and tokens[7] or None)) 56 69 57 70 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_app app_list.0.name %} 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 %}