Преглед изворни кода

Add change message as tooltip to recent action dashboard module.

Michael Kutý пре 8 година
родитељ
комит
56aec95472

+ 3 - 3
jet/dashboard/templates/jet.dashboard/modules/recent_actions.html

@@ -1,4 +1,4 @@
-{% load i18n %}
+{% load i18n jet_dashboard_tags %}
 
 <ul>
     {% if not module.children %}
@@ -31,9 +31,9 @@
                     {% endif %}
 
                     {% if entry.is_deletion or not entry.get_admin_url %}
-                        <span class="tooltip" title="{{ entry.change_message }}">{{ entry.object_repr }}</span>
+                        <span class="tooltip" title="{{ entry|format_change_message }}">{{ entry.object_repr }}</span>
                     {% else %}
-                        <a title="{{ entry.change_message }}" class="tooltip" href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
+                        <a title="{{ entry|format_change_message }}" class="tooltip" href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
                     {% endif %}
                 </div>
             </li>

+ 12 - 4
jet/dashboard/templatetags/jet_dashboard_tags.py

@@ -1,6 +1,5 @@
 from __future__ import unicode_literals
 from django import template
-from django.core.urlresolvers import resolve
 from jet.dashboard.utils import get_current_dashboard
 
 register = template.Library()
@@ -10,7 +9,16 @@ register = template.Library()
 def get_dashboard(context, location):
     dashboard_cls = get_current_dashboard(location)
 
-    resolver = resolve(context['request'].path)
-    app_label = resolver.kwargs.get('app_label')
+    app_label = context['request'].resolver_match.kwargs.get('app_label')
 
-    return dashboard_cls(context, app_label=app_label)
+    return dashboard_cls(context, app_label=app_label)
+
+
+@register.filter()
+def format_change_message(log_entry):
+
+    # Django 1.9+
+    if hasattr(log_entry, "get_change_message"):
+        return log_entry.get_change_message()
+    else:
+        return log_entry.change_message