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 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'servo') 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) -- cgit v1.2.3