Convert index view context to json
authorKostas Papadimitriou <kpap@grnet.gr>
Mon, 3 Jun 2013 10:15:52 +0000 (13:15 +0300)
committerKostas Papadimitriou <kpap@grnet.gr>
Mon, 3 Jun 2013 10:15:52 +0000 (13:15 +0300)
to safely append any type of values to otherProperties javascript object

snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/other_properties.html
snf-pithos-webclient/pithos_webclient/views.py

index dd70d47..acc5378 100644 (file)
@@ -1,7 +1,7 @@
 {% for key, value in branding_settings.items %}
-    otherProperties.{{ key }} = "{{ value }}";
+    otherProperties.{{ key }} = {{ value|safe }};
 {% endfor %}
 
 {% for key, value in urls_config.items %}
-    otherProperties.{{ key }} = "{{ value }}";
+    otherProperties.{{ key }} = "{{ value|safe }}";
 {% endfor %}
index 5fcf306..6ecb3dd 100644 (file)
 # interpreted as representing official policies, either expressed
 # or implied, of GRNET S.A.
 
+import json
+import copy
+
 from django.views.generic.simple import direct_to_template
+from django.conf import settings as django_settings
 
 from pithos_webclient import settings
-from pithos_webclient.version import  __version__
-
-from django.conf import settings as django_settings
+from pithos_webclient.version import __version__
 
 from synnefo_branding.utils import get_branding_dict
 
-MEDIA_URL = getattr(settings, "PITHOS_WEB_CLIENT_MEDIA_URL", \
-        getattr(django_settings, "MEDIA_URL", "/static/"))
+
+MEDIA_URL = getattr(settings, "PITHOS_WEB_CLIENT_MEDIA_URL",
+                    getattr(django_settings, "MEDIA_URL", "/static/"))
 
 URLS_CONFIG = {
     'STORAGE_API_URL': settings.PITHOS_URL.rstrip('/') + '/',
@@ -53,6 +56,14 @@ URLS_CONFIG = {
 
 def index(request):
     branding_settings = get_branding_dict("")
+    urls_config = copy.deepcopy(URLS_CONFIG)
+
+    for key, value in urls_config.iteritems():
+        urls_config[key] = json.dumps(value)
+
+    for key, value in branding_settings.iteritems():
+        branding_settings[key] = json.dumps(value)
+
     return direct_to_template(request, 'pithos_webclient/index.html', {
         'settings': settings,
         'MEDIA_URL': MEDIA_URL,