FIX: Użytkownik bez ustawionego cookie nie mógł wejść na stronę (błąd w EditorSetting...
authorzuber <marek@stepniowski.com>
Wed, 2 Sep 2009 11:07:10 +0000 (13:07 +0200)
committerzuber <marek@stepniowski.com>
Wed, 2 Sep 2009 11:07:10 +0000 (13:07 +0200)
apps/explorer/middleware.py
apps/explorer/views.py
project/settings.py

index 661a7a6..018f1aa 100644 (file)
@@ -6,14 +6,18 @@ from django.utils import simplejson
 from explorer import models
 
 
 from explorer import models
 
 
+EDITOR_DEFAULT_SETTINGS_JSON = simplejson.dumps(settings.EDITOR_DEFAULT_SETTINGS)
+
+
 class EditorSettingsMiddleware(object):
     def process_request(self, request):
         if request.user.is_anonymous():
             return
 class EditorSettingsMiddleware(object):
     def process_request(self, request):
         if request.user.is_anonymous():
             return
-        cookie_settings = request.COOKIES.get(settings.EDITOR_COOKIE_NAME, '{}')
+        cookie_settings = request.COOKIES.get(settings.EDITOR_COOKIE_NAME, EDITOR_DEFAULT_SETTINGS_JSON)
         
         cookie_settings = simplejson.loads(urllib.unquote(cookie_settings))
         last_update = cookie_settings.get('lastUpdate', 0)
         
         cookie_settings = simplejson.loads(urllib.unquote(cookie_settings))
         last_update = cookie_settings.get('lastUpdate', 0)
+        cookie_settings['lastUpdate'] = last_update
         
         try:
             editor_settings = models.EditorSettings.objects.get(user=request.user)
         
         try:
             editor_settings = models.EditorSettings.objects.get(user=request.user)
@@ -24,7 +28,6 @@ class EditorSettingsMiddleware(object):
 
         # print editor_settings.get_settings_value()['lastUpdate'], '<>', last_update
         if editor_settings.get_settings_value()['lastUpdate'] < last_update:
 
         # print editor_settings.get_settings_value()['lastUpdate'], '<>', last_update
         if editor_settings.get_settings_value()['lastUpdate'] < last_update:
-            print "\n\nZmiana!\n\n"
             editor_settings.set_settings_value(cookie_settings)
             editor_settings.save()
 
             editor_settings.set_settings_value(cookie_settings)
             editor_settings.save()
 
index 79160f8..6754930 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 import urllib2
 import hg
 from librarian import html, parser, dcparser, ParseError, ValidationError
 import urllib2
 import hg
 from librarian import html, parser, dcparser, ParseError, ValidationError
index 3bfc7db..22d9bdd 100644 (file)
@@ -119,6 +119,12 @@ INSTALLED_APPS = (
 # REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
 IMAGE_DIR = 'images'
 EDITOR_COOKIE_NAME = 'options'
 # REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
 IMAGE_DIR = 'images'
 EDITOR_COOKIE_NAME = 'options'
+EDITOR_DEFAULT_SETTINGS = {
+    'panels': [
+        {'name': 'htmleditor', 'ratio': 0.5},
+        {'name': 'gallery', 'ratio': 0.5}
+    ],
+}
 
 try:
     from localsettings import *
 
 try:
     from localsettings import *