A somewhat usable and tested version.
[django-ssify.git] / ssify / serializers.py
index a96356c..8a44c7b 100644 (file)
@@ -1,19 +1,25 @@
+# -*- coding: utf-8 -*-
+# This file is part of django-ssify, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
+#
+from __future__ import unicode_literals
 import json
 from .variables import SsiVariable, SsiExpect
 
 
 def _json_default(o):
     if isinstance(o, SsiVariable):
-        return {'__var__': o.name}
+        return {'__var__': o.definition}
     if isinstance(o, SsiExpect):
         return {'__expect__': o.name}
     raise TypeError(o, 'not JSON serializable')
 
 
 def _json_obj_hook(obj):
-    if obj.keys() == ['__var__']:
-        return SsiVariable(name=obj['__var__'])
-    if obj.keys() == ['__expect__']:
+    keys = list(obj.keys())
+    if keys == ['__var__']:
+        return SsiVariable(*obj['__var__'])
+    if keys == ['__expect__']:
         return SsiExpect(obj['__expect__'])
     return obj