Added hirarchy view for users
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 29 Jul 2010 21:39:10 +0000 (21:39 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 29 Jul 2010 21:39:10 +0000 (21:39 +0000)
bin/djais/templatetags/ais_extras.py
bin/djais/views.py
html_templates/users.html
html_templates/users_tree.html [new file with mode: 0644]

index 35dc2d02cd6580cb5f13fcef7a189b64a8a181f0..8dcf811e538394bd89469f1dbddaa359b742bb68 100644 (file)
@@ -1,5 +1,6 @@
 # -*- encofing: utf8 -*-
 from django import template
+from django.utils.html import escape
 from ais.common import mmsi_to_strmmsi
 
 register = template.Library()
@@ -7,3 +8,21 @@ register = template.Library()
 @register.filter
 def sqlmmsi_to_strmmsi(txt):
     return unicode(mmsi_to_strmmsi(txt))
+
+@register.filter
+def format_user_tree(user, indentlevel=0):
+    result = u"&nbsp;"*indentlevel*8 + "<a href='%s/'>%s</a>" % (escape(user.login), escape(user.name))
+    if not user.password_hash:
+        result += " <b>Account disabled: No password</b>"
+    if user.admin_ok:
+        result +="""
+<span style="font-size:80%%">
+<a href='%s/change_password'>change password</a> - <a href='%s/delete'>delete account</a>
+</span>""" % (escape(user.login), escape(user.login))
+    result += " <br>\n"
+    for child in user.children:
+        result = result + format_user_tree(child, indentlevel+1)
+    return result
+    
+    '''
+'''
index d5999f3cd7785eb8210591cb7a1c8a68f1cae7c4..c07ee169a238d2d69108b4b4dd764bf19e413730 100644 (file)
@@ -518,7 +518,20 @@ def users(request):
     users = User.objects.all()
     for user in users:
         user.admin_ok = user.is_admin_by(request.user.id)
-    return render_to_response('users.html', {'users':users}, RequestContext(request))
+    if request.REQUEST.has_key('showtree'):
+        local_users = {}
+        for user in users:
+            user.children = []
+            local_users[user.id] = user
+        for user in users:
+            if user.father_id == None:
+                root = user
+            else:
+                local_users[user.father_id].children.append(user)
+        assert root
+        return render_to_response('users_tree.html', {'root': root, 'auser': request.user.id}, RequestContext(request))
+    else:
+        return render_to_response('users.html', {'users':users}, RequestContext(request))
 
 
 class UserEditForm(forms.Form):
@@ -647,6 +660,10 @@ def sources(request):
         'name_tiny': '14d',
         'name_long': '2 weeks',
         'seconds': 14*24*60*60
+        }, {
+        'name_tiny': '90d',
+        'name_long': '3 monthes',
+        'seconds': 90*24*60*60
         })
         
     for source in sources:
index 4c28fee74c5cbb2edc9a4306202488fba5eaf387..fbfb957c10bab364eb92127eb5adede1f3f03526 100644 (file)
@@ -19,4 +19,7 @@
 </span>
 {% endif %}
 {% endfor %}
+<br>
+<br>
+<a href="?showtree">Show tree</a>
 {% endblock %}
diff --git a/html_templates/users_tree.html b/html_templates/users_tree.html
new file mode 100644 (file)
index 0000000..7b3575b
--- /dev/null
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+{% load ais_extras %}
+
+{% block breadcrumbs %}
+{{ block.super }} &gt; <a href="/user/">user</a>
+{% endblock %}
+
+{% block content %}
+<h3>User accounts</h3>
+<a href=add>+ Create new account</a>
+<br>
+<br>
+{{ root|format_user_tree|safe }}
+<br>
+<br>
+<a href=.>Hide tree</a>
+{% endblock %}