add saving favorite locations
[qcg-portal.git] / filex / templatetags / filex.py
diff --git a/filex/templatetags/filex.py b/filex/templatetags/filex.py
new file mode 100644 (file)
index 0000000..e854e49
--- /dev/null
@@ -0,0 +1,37 @@
+import json
+
+from bootstrap3.forms import render_form
+from django import template
+
+from ..forms import FavoriteForm
+
+
+register = template.Library()
+
+
+@register.simple_tag(takes_context=True)
+def locations(context):
+    user = context['request'].user
+
+    result = [
+        {'group': 'sys', 'host': 'moss.man.poznan.pl', 'path': '/home/plg-users/' + user.username},
+        {'group': 'sys', 'host': 'qcg.man.poznan.pl', 'path': '/home/plgrid/' + user.username},
+        {'group': 'sys', 'host': 'ui.grid.icm.edu.pl', 'path': '/icm/hydra/home/grid/' + user.username},
+        {'group': 'sys', 'host': 'ui.plgrid.wcss.wroc.pl', 'path': '/home/grid/users/' + user.username},
+        {'group': 'sys', 'host': 'ui.grid.task.gda.pl', 'path': '/home/plgrid/' + user.username},
+        {'group': 'sys', 'host': 'zeus.cyfronet.pl', 'path': '/people/' + user.username}
+    ]
+
+    for item in user.favorites.values('host', 'path'):
+        item['group'] = 'usr'
+        result.append(item)
+
+    for item in result:
+        item['value'] = item['host'] + item['path']
+
+    return json.dumps(result)
+
+
+@register.simple_tag
+def fav_form():
+    return render_form(FavoriteForm(), layout='horizontal')