aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-08-18 23:35:53 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-08-18 23:35:53 +0300
commit50fe15e2747c5b9f81e17cb389ccf74f589d4671 (patch)
treeaf92314822ea9d519e283cdd1713d99f8014030c
parent2e2e8b3e38a893550929f6e57f67dfdb0a3a3f6b (diff)
downloadServo-50fe15e2747c5b9f81e17cb389ccf74f589d4671.tar.gz
Servo-50fe15e2747c5b9f81e17cb389ccf74f589d4671.tar.bz2
Servo-50fe15e2747c5b9f81e17cb389ccf74f589d4671.zip
Added custom session serializer
-rw-r--r--servo/lib/utils.py19
-rw-r--r--settings.py3
2 files changed, 21 insertions, 1 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py
index 20da7d5..ed77897 100644
--- a/servo/lib/utils.py
+++ b/servo/lib/utils.py
@@ -24,6 +24,17 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
+import json
+from django.db.models import Model
+from django.core.serializers.json import DjangoJSONEncoder
+
+
+def multiprint(*args):
+ """
+ Emulate JS console.log()
+ """
+ print(', '.join(args))
+
def choices_to_dict(t):
"""
Converts a ChoiceField two-tuple to a dict (for JSON)
@@ -51,3 +62,11 @@ def cache_getset(k, v):
val = v()
cache.set(k, val)
return val
+
+
+class SessionSerializer:
+ def dumps(self, obj):
+ return json.dumps(obj, cls=DjangoJSONEncoder)
+
+ def loads(self, data):
+ return json.loads(data, cls=DjangoJSONEncoder)
diff --git a/settings.py b/settings.py
index 78290c0..71a3cea 100644
--- a/settings.py
+++ b/settings.py
@@ -241,8 +241,9 @@ REST_FRAMEWORK = {
ENABLE_RULES = True
TIMEZONE = 'Europe/Helsinki'
+SESSION_SERIALIZER = 'servo.lib.utils.SessionSerializer'
from local_settings import *
os.environ['GSX_CERT'] = GSX_CERT
-os.environ['GSX_KEY'] = GSX_KEY \ No newline at end of file
+os.environ['GSX_KEY'] = GSX_KEY