From cc425116a1a4af018c45c1d08b25eafc85e15eca Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:12:41 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/views.py | 19 +++- templates/base.html | 2 +- templates/juser/user_list.html | 157 ++++++++++++++++++-------------- templates/juser/user_list2.html | 80 ++++++++++++++++ 4 files changed, 184 insertions(+), 74 deletions(-) create mode 100644 templates/juser/user_list2.html diff --git a/juser/views.py b/juser/views.py index 31b838293..e9f208071 100644 --- a/juser/views.py +++ b/juser/views.py @@ -19,7 +19,7 @@ from juser.models import UserGroup, User from connect import PyCrypt, KEY from connect import BASE_DIR from connect import CONF - +from django.core.paginator import Paginator, EmptyPage, InvalidPage CRYPTOR = PyCrypt(KEY) LDAP_ENABLE = CONF.getint('ldap', 'ldap_enable') @@ -107,6 +107,7 @@ class LDAPMgmt(): except ldap.LDAPError, e: print e + def gen_sha512(salt, password): return crypt.crypt(password, '$6$%s$' % salt) @@ -153,13 +154,25 @@ def group_list(request): def user_list(request): user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} header_title, path1, path2 = '查看用户 | Add User', 'juser', 'user_list' - users = User.objects.all() - return render_to_response('juser/user_list.html', locals()) + users = contact_list = User.objects.all() + p = paginator = Paginator(contact_list, 5) + + try: + page = int(request.GET.get('page', '1')) + except ValueError: + page = 1 + + try: + contacts = paginator.page(page) + except (EmptyPage, InvalidPage): + contacts = paginator.page(paginator.num_pages) + return render_to_response('juser/user_list2.html', locals()) def db_add_user(**kwargs): groups_post = kwargs.pop('groups') user = User(**kwargs) + group_select = [] for group_id in groups_post: group = UserGroup.objects.filter(id=group_id) group_select.extend(group) diff --git a/templates/base.html b/templates/base.html index 2d98803e7..8eb5d6e1e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -14,7 +14,7 @@ - +
{% include 'nav.html' %} diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index 9c30bb01f..aebe9810b 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -1,80 +1,97 @@ {% extends 'base.html' %} {% load mytags %} - {% block content %} - {% include 'nav_cat_bar.html' %} -
-
-
-
-
-
用户信息 show user info.
- +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
查看用户 show user info.
+ -
-
- - - - - - - - - - - - - - - {% for user in users %} - - - - - - - - - - - {% endfor %} - -
-
- -
-
ID用户名姓名属组角色Email激活
-
- -
-
{{ user.id }}{{ user.username }}{{ user.name }}{{ user.username|groups_str }}{{ user.id|get_role }}{{ user.email }}{{ user.is_active }}
-
-
- - -
-
-
+
+ +
+ + + + + + + + + + + + + + + + {% for user in users %} + + + + + + + + + + + + {% endfor %} + +
ID用户名姓名属组角色Email激活
{{ user.id }} {{ user.username }} {{ user.name }} {{ user.username|groups_str }}{{ user.id|get_role }}{{ user.email }}{{ user.is_active }} + 详情 + 编辑 + 删除 +
+ +
    + {% if contacts.has_previous %} +
  • «
  • + {% endif %} + + {% for page in p.page_range %} + {% ifequal offset1 page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% if contacts.has_next %} +
  • »
  • + {% endif %} +
+
+ + + {% endblock %} \ No newline at end of file diff --git a/templates/juser/user_list2.html b/templates/juser/user_list2.html new file mode 100644 index 000000000..9c30bb01f --- /dev/null +++ b/templates/juser/user_list2.html @@ -0,0 +1,80 @@ +{% extends 'base.html' %} +{% load mytags %} + +{% block content %} + {% include 'nav_cat_bar.html' %} +
+
+
+
+
+
用户信息 show user info.
+ +
+
+
+ + + + + + + + + + + + + + + {% for user in users %} + + + + + + + + + + + {% endfor %} + +
+
+ +
+
ID用户名姓名属组角色Email激活
+
+ +
+
{{ user.id }}{{ user.username }}{{ user.name }}{{ user.username|groups_str }}{{ user.id|get_role }}{{ user.email }}{{ user.is_active }}
+
+
+ + +
+
+
+
+
+
+
+
+{% endblock %} \ No newline at end of file From 984a04972fb76230b35184fa0267fe2edf88be9a Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:14:21 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juser/views.py b/juser/views.py index e9f208071..5f1691449 100644 --- a/juser/views.py +++ b/juser/views.py @@ -166,7 +166,7 @@ def user_list(request): contacts = paginator.page(page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) - return render_to_response('juser/user_list2.html', locals()) + return render_to_response('juser/user_list.html', locals()) def db_add_user(**kwargs): From 9dc7e953c9b9d5e92a308265d1be484ff2839bff Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:16:32 +0800 Subject: [PATCH 03/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/user_list.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index aebe9810b..baa49717a 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -36,6 +36,7 @@ + From cc72d599652d9c81c7a2ce3f352782df278c73f4 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:26:13 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/templatetags/mytags.py | 8 ++++++++ juser/views.py | 6 +++--- templates/juser/user_list.html | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 86f978571..4c4045254 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -38,3 +38,11 @@ def groups_str(username): @register.filter(name='get_item') def get_item(dictionary, key): return dictionary.get(key) + + +@register.filter(name='bool2str') +def bool2str(value): + if value: + return u'是' + else: + return u'否' \ No newline at end of file diff --git a/juser/views.py b/juser/views.py index 5f1691449..236cf68a7 100644 --- a/juser/views.py +++ b/juser/views.py @@ -153,9 +153,9 @@ def group_list(request): def user_list(request): user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} - header_title, path1, path2 = '查看用户 | Add User', 'juser', 'user_list' - users = contact_list = User.objects.all() - p = paginator = Paginator(contact_list, 5) + header_title, path1, path2 = '查看用户 | Show User', 'juser', 'user_list' + users = contact_list = User.objects.all().order_by('id') + p = paginator = Paginator(contact_list, 10) try: page = int(request.GET.get('page', '1')) diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index baa49717a..e14f80f4a 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -44,6 +44,7 @@ + @@ -56,7 +57,7 @@ - +
ID 用户名 姓名角色 Email 激活操作
{{ user.username|groups_str }} {{ user.id|get_role }} {{ user.email }}{{ user.is_active }}{{ user.is_active|bool2str }} 详情 编辑 From 4f25124d92df3585fbfd6e189ffdb81a025e83b9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:46:48 +0800 Subject: [PATCH 05/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/user_list.html | 49 ++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index e14f80f4a..af93ecdbe 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -67,23 +67,38 @@ {% endfor %}
- -
    - {% if contacts.has_previous %} -
  • «
  • - {% endif %} - - {% for page in p.page_range %} - {% ifequal offset1 page %} -
  • {{ page }}
  • - {% else %} -
  • {{ page }}
  • - {% endifequal %} - {% endfor %} - {% if contacts.has_next %} -
  • »
  • - {% endif %} -
+
+
+
Showing 1 to 25 of 57 entries
+
+
+
+
    + {% if contacts.has_previous %} + + {% for page in p.page_range %} + {% ifequal offset1 page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% if contacts.has_next %} + +
+
+
+
From 3cf352ee56b65689ac142d52f1133320ca936ebb Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:49:34 +0800 Subject: [PATCH 06/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/user_list.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index af93ecdbe..dd8301b4a 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -76,11 +76,13 @@
    {% if contacts.has_previous %} {% else %} + {% endif %} {% for page in p.page_range %} {% ifequal offset1 page %}
  • {{ page }}
  • @@ -90,11 +92,13 @@ {% endfor %} {% if contacts.has_next %} {% else %} {% endif %} - Next -
From 8543e885b739e2186480554d51b7409140cf9e3d Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 23:04:59 +0800 Subject: [PATCH 07/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/user_list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index dd8301b4a..208f3939e 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -73,7 +73,7 @@
-
    +
      {% if contacts.has_previous %}