Denis K преди 8 години
родител
ревизия
b145be8f4f
променени са 2 файла, в които са добавени 15 реда и са изтрити 10 реда
  1. 4 10
      jet/dashboard/dashboard.py
  2. 11 0
      jet/utils.py

+ 4 - 10
jet/dashboard/dashboard.py

@@ -1,4 +1,3 @@
-from django.template import Context
 from importlib import import_module
 from django.core.urlresolvers import reverse
 from django.template.loader import render_to_string
@@ -6,7 +5,8 @@ from jet.dashboard import modules
 from jet.dashboard.models import UserDashboardModule
 from django.utils.translation import ugettext_lazy as _
 from jet.ordered_set import OrderedSet
-from jet.utils import get_admin_site_name
+from jet.utils import get_admin_site_name, context_to_dict
+
 try:
     from django.template.context_processors import csrf
 except ImportError:
@@ -48,12 +48,6 @@ class Dashboard(object):
         self.set_context(context)
 
     def set_context(self, context):
-        if isinstance(context, Context):
-            flat = {}
-            for d in context.dicts:
-                flat.update(d)
-            context = flat
-
         self.context = context
         self.init_with_context(context)
         self.load_modules()
@@ -153,7 +147,7 @@ class Dashboard(object):
         self.modules = loaded_modules
 
     def render(self):
-        context = self.context
+        context = context_to_dict(self.context)
         context.update({
             'columns': range(self.columns),
             'modules': self.modules,
@@ -164,7 +158,7 @@ class Dashboard(object):
         return render_to_string('jet.dashboard/dashboard.html', context)
 
     def render_tools(self):
-        context = self.context
+        context = context_to_dict(self.context)
         context.update({
             'children': self.children,
             'app_label': self.app_label,

+ 11 - 0
jet/utils.py

@@ -1,5 +1,6 @@
 import datetime
 import json
+from django.template import Context
 from django.utils import translation
 from jet import settings
 from jet.models import PinnedApplication
@@ -426,3 +427,13 @@ def get_menu_items(context):
                 app['current'] = False
 
     return app_list
+
+
+def context_to_dict(context):
+    if isinstance(context, Context):
+        flat = {}
+        for d in context.dicts:
+            flat.update(d)
+        context = flat
+
+    return context