From cc425116a1a4af018c45c1d08b25eafc85e15eca Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 22 Jan 2015 22:12:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=E5=B1=95?= =?UTF-8?q?=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