From 50fe15e2747c5b9f81e17cb389ccf74f589d4671 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 18 Aug 2015 23:35:53 +0300 Subject: Added custom session serializer --- servo/lib/utils.py | 19 +++++++++++++++++++ settings.py | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3