1. aleray
  2. django-admin-tools

Commits

Alexandre Leray  committed 589d78f

Improved the code to fix issue #43 bug #1

Uses dashboard.get_id() instead of less reliable request data to compute
dasboard unique names.

  • Participants
  • Parent commits 9177824
  • Branches default

Comments (0)

Files changed (4)

File admin_tools/dashboard/forms.py

View file
             **kwargs
         )
         preferences.user = self.user
-        preferences.pathname= self.pathname
+        preferences.pathname = self.pathname
         preferences.save()
         return preferences
 
     class Meta:
-        fields = ('data',)
+        fields = ('pathname', 'data',)
         model = DashboardPreferences

File admin_tools/dashboard/templatetags/admin_tools_dashboard_tags.py

View file
 
     try:
         preferences = DashboardPreferences.objects.get(user=context['request'].user, \
-                pathname=context['request'].META["PATH_INFO"]).data
+                pathname=dashboard.get_id()).data
     except DashboardPreferences.DoesNotExist:
         preferences = '{}'
 

File admin_tools/dashboard/views.py

View file
 from django.contrib.auth.decorators import login_required
 from django.http import HttpResponse
 from django.views.generic.simple import direct_to_template
+from django.utils.datastructures import MultiValueDictKeyError
 
 try:
     from django.views.decorators.csrf import csrf_exempt
     """
     This view serves and validates a preferences form.
     """
-    if request.method == "POST":
-        host = "http://%s" % request.META['HTTP_HOST']
-        pathname = request.META['HTTP_REFERER'][len(host):]
     try:
-        preferences = DashboardPreferences.objects.get(user=request.user, pathname=pathname)
-    except DashboardPreferences.DoesNotExist:
+        preferences = DashboardPreferences.objects.get(user=request.user, \
+                pathname=request.POST['pathname'])
+    except (DashboardPreferences.DoesNotExist, MultiValueDictKeyError):
         preferences = None
     if request.method == "POST":
-        #host = "http://%s" % request.META['HTTP_HOST']
-        #pathname = request.META['HTTP_REFERER'][len(host):]
         form = DashboardPreferencesForm(
             user=request.user,
-            pathname=pathname,
+            pathname=request.POST['pathname'],
             data=request.POST,
             instance=preferences
         )
         elif request.is_ajax():
             return HttpResponse('false')
     else:
-        form = DashboardPreferencesForm(user=request.user, instance=preferences)
+        form = DashboardPreferencesForm(user=request.user, pathname="", instance=preferences)
     return direct_to_template(request, 'admin_tools/dashboard/preferences_form.html', {
         'form': form,   
     })

File admin_tools/media/admin_tools/js/dashboard.js

View file
             return preferences;
         },
         'save_preferences_function': function(options, preferences) {
-            jQuery.post(url, { data: JSON.stringify(preferences) });
+            jQuery.post(url, { pathname: options.dashboard_id, data: JSON.stringify(preferences) });
         }
     });
     $(".group-tabs").tabs();