Commit e3223f74 authored by 广宏伟's avatar 广宏伟

app users

Modify user list view
Modify user add view
parent 86ffcc97
...@@ -10,6 +10,6 @@ class UserForm(ModelForm): ...@@ -10,6 +10,6 @@ class UserForm(ModelForm):
model = User model = User
fields = [ fields = [
'username', 'name', 'email', 'groups', 'wechat', 'username', 'name', 'email', 'groups', 'wechat',
'phone', 'enable_2FA', 'role', 'comment', 'phone', 'enable_2FA', 'role', 'date_expired', 'comment',
] ]
...@@ -51,9 +51,9 @@ class UserGroup(models.Model): ...@@ -51,9 +51,9 @@ class UserGroup(models.Model):
class User(AbstractUser): class User(AbstractUser):
username = models.CharField(max_length=20, unique=True, verbose_name='用户名') username = models.CharField(max_length=20, unique=True, verbose_name='用户名', help_text='* required')
name = models.CharField(max_length=20, verbose_name='姓名') name = models.CharField(max_length=20, verbose_name='姓名', help_text='* required')
email = models.EmailField(max_length=30, unique=True, verbose_name='邮件') email = models.EmailField(max_length=30, unique=True, verbose_name='邮件', help_text='* required')
groups = models.ManyToManyField(UserGroup, verbose_name='用户组') groups = models.ManyToManyField(UserGroup, verbose_name='用户组')
avatar = models.ImageField(verbose_name='头像', blank=True) avatar = models.ImageField(verbose_name='头像', blank=True)
wechat = models.CharField(max_length=30, blank=True, verbose_name='微信') wechat = models.CharField(max_length=30, blank=True, verbose_name='微信')
...@@ -65,7 +65,7 @@ class User(AbstractUser): ...@@ -65,7 +65,7 @@ class User(AbstractUser):
public_key = models.CharField(max_length=1000, blank=True, verbose_name='公钥') public_key = models.CharField(max_length=1000, blank=True, verbose_name='公钥')
comment = models.CharField(max_length=200, blank=True, verbose_name='描述') comment = models.CharField(max_length=200, blank=True, verbose_name='描述')
created_by = models.CharField(max_length=30, default='') created_by = models.CharField(max_length=30, default='')
date_expired = models.DateTimeField(default=datetime.datetime.max) date_expired = models.DateTimeField(default=datetime.datetime.max, verbose_name='有效期')
class Meta: class Meta:
db_table = 'user' db_table = 'user'
...@@ -21,44 +21,38 @@ ...@@ -21,44 +21,38 @@
</div> </div>
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<form method="post" id="userForm" class="form-horizontal" action=""> <form method="post" id="userForm" class="form-horizontal" action="{% url 'users:user-add' %}">
{% csrf_token %} {% csrf_token %}
<h2>账户</h2> <h3>账户</h3>
{{ form.username|bootstrap_horizontal }} {{ form.username|bootstrap_horizontal }}
{{ form.name|bootstrap_horizontal }} {{ form.name|bootstrap_horizontal }}
{{ form.email|bootstrap_horizontal }} {{ form.email|bootstrap_horizontal }}
{{ form.groups|bootstrap_horizontal }} {{ form.groups|bootstrap_horizontal }}
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<h2>密码</h2> <h3>密码</h3>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">密码</label> <label class="col-sm-2 control-label">密码</label>
<div class="col-sm-8 bottom-left" > <div class="col-sm-8 controls" >
生成重置密码连接,通过邮件发送给用户 生成重置密码连接,通过邮件发送给用户
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<h2>角色安全</h2> <h3>角色安全</h3>
{{ form.role|bootstrap_horizontal }}
{{ form.date_expired|bootstrap_horizontal }}
<div class="form-group"> <div class="form-group">
<label for="email" class="col-sm-2 control-label">Email<span class="red-fonts">*</span></label> <label for="{{ form.enable_2FA.id_for_label }}" class="col-sm-2 control-label">二次验证</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="email" name="email" type="email" placeholder="username@jumpserver.org" class="form-control" {% if error %}value="{{ email }}" {% endif %}> {{ form.enable_2FA }}
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label">其它</label> <h3>信息</h3>
<div class="col-sm-2"> {{ form.phone|bootstrap_horizontal }}
<div class="checkbox i-checks"> {{ form.wechat|bootstrap_horizontal }}
<label><input type="checkbox" value="0" name="extra" >禁用 </label> {{ form.comment|bootstrap_horizontal }}
</div>
</div>
<div class="col-sm-2">
<div class="checkbox i-checks">
<label><input type="checkbox" value="1" name="extra" checked>发送邮件 </label>
</div>
</div>
</div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<div class="col-sm-4 col-sm-offset-2"> <div class="col-sm-4 col-sm-offset-2">
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
<div class="ibox-content"> <div class="ibox-content">
<div class=""> <div class="">
<a href="#" class="btn btn-sm btn-primary "> 添加用户 </a> <a href="{% url 'users:user-add' %}" class="btn btn-sm btn-primary "> 添加用户 </a>
<a id="del_btn" class="btn btn-sm btn-danger "> 删除所选 </a> <a id="del_btn" class="btn btn-sm btn-danger "> 删除所选 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search"> <form id="search_form" method="get" action="{% url 'users:user-list' %}" class="pull-right mail-search">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search"> <input type="text" class="form-control input-sm" name="keyword" placeholder="用户名或姓名" value="{{ keyword }}">
<div class="input-group-btn"> <div class="input-group-btn">
<button id='search_btn' type="submit" class="btn btn-sm btn-primary"> <button id='search_btn' type="submit" class="btn btn-sm btn-primary">
搜索 搜索
......
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
from django.urls import reverse_lazy
from django.db.models import Q
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
...@@ -12,10 +14,19 @@ class UserListView(ListView): ...@@ -12,10 +14,19 @@ class UserListView(ListView):
paginate_by = 10 paginate_by = 10
context_object_name = 'user_list' context_object_name = 'user_list'
template_name = 'users/user_list.html' template_name = 'users/user_list.html'
ordering = '-date_joined'
def get_queryset(self):
self.queryset = super(UserListView, self).get_queryset()
self.keyword = keyword = self.request.GET.get('keyword', '')
if keyword:
self.queryset = self.queryset.filter(Q(username__icontains=keyword) |
Q(name__icontains=keyword))
return self.queryset
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(UserListView, self).get_context_data(**kwargs) context = super(UserListView, self).get_context_data(**kwargs)
context.update({'path1': '用户管理', 'path2': '用户列表', 'title': '用户列表'}) context.update({'path1': '用户管理', 'path2': '用户列表', 'title': '用户列表', 'keyword': self.keyword})
return context return context
...@@ -23,4 +34,10 @@ class UserAddView(CreateView): ...@@ -23,4 +34,10 @@ class UserAddView(CreateView):
model = User model = User
form_class = UserForm form_class = UserForm
template_name = 'users/user_add.html' template_name = 'users/user_add.html'
success_url = reverse_lazy('users:user-list')
def get_context_data(self, **kwargs):
context = super(UserAddView, self).get_context_data(**kwargs)
context.update({'path1': '用户管理', 'path2': '用户添加', 'title': '用户添加'})
return context
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<type label="SET" quote="" sql="SET" length="1"/> <type label="SET" quote="" sql="SET" length="1"/>
<type label="Bit" quote="" sql="bit" length="0"/> <type label="Bit" quote="" sql="bit" length="0"/>
</group> </group>
</datatypes><table x="397" y="254" name="user"> </datatypes><table x="399" y="254" name="user">
<row name="id" null="1" autoincrement="1"> <row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -71,9 +71,12 @@ ...@@ -71,9 +71,12 @@
<row name="is_active" null="0" autoincrement="0"> <row name="is_active" null="0" autoincrement="0">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>0</default></row> <default>0</default></row>
<row name="two_factor_auth" null="1" autoincrement="0"> <row name="enable_2FA" null="1" autoincrement="0">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>0</default></row> <default>0</default></row>
<row name="secret_key_2FA" null="1" autoincrement="0">
<datatype>CHAR</datatype>
<default>NULL</default></row>
<row name="role" null="1" autoincrement="0"> <row name="role" null="1" autoincrement="0">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default><relation table="role" row="id" /> <default>NULL</default><relation table="role" row="id" />
...@@ -87,6 +90,9 @@ ...@@ -87,6 +90,9 @@
<row name="public_key" null="1" autoincrement="0"> <row name="public_key" null="1" autoincrement="0">
<datatype>VARCHAR</datatype> <datatype>VARCHAR</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="comment" null="1" autoincrement="0">
<datatype>CHAR</datatype>
<default>NULL</default></row>
<row name="date_joined" null="1" autoincrement="0"> <row name="date_joined" null="1" autoincrement="0">
<datatype>DATETIME</datatype> <datatype>DATETIME</datatype>
<default>'now()'</default></row> <default>'now()'</default></row>
...@@ -223,6 +229,10 @@ ...@@ -223,6 +229,10 @@
<row name="password" null="1" autoincrement="0"> <row name="password" null="1" autoincrement="0">
<datatype>VARCHAR</datatype> <datatype>VARCHAR</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="admin_user" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="adminuser" row="id" />
</row>
<row name="idc" null="1" autoincrement="0"> <row name="idc" null="1" autoincrement="0">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default><relation table="idc" row="id" /> <default>NULL</default><relation table="idc" row="id" />
...@@ -265,16 +275,18 @@ ...@@ -265,16 +275,18 @@
<row name="disk" null="1" autoincrement="0"> <row name="disk" null="1" autoincrement="0">
<datatype>VARCHAR</datatype> <datatype>VARCHAR</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="is_active" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<row name="comment" null="1" autoincrement="0">
<datatype>CHAR</datatype>
<default>NULL</default></row>
<row name="created_by" null="1" autoincrement="0"> <row name="created_by" null="1" autoincrement="0">
<datatype>VARCHAR</datatype> <datatype>VARCHAR</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="date_added" null="1" autoincrement="0"> <row name="date_added" null="1" autoincrement="0">
<datatype>DATETIME</datatype> <datatype>DATETIME</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="admin_user" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="adminuser" row="id" />
</row>
<key type="PRIMARY" name=""> <key type="PRIMARY" name="">
<part>id</part> <part>id</part>
</key> </key>
...@@ -359,6 +371,9 @@ ...@@ -359,6 +371,9 @@
<row name="comment" null="1" autoincrement="0"> <row name="comment" null="1" autoincrement="0">
<datatype>VARCHAR</datatype> <datatype>VARCHAR</datatype>
<default>NULL</default></row> <default>NULL</default></row>
<row name="created_by" null="1" autoincrement="0">
<datatype>VARCHAR</datatype>
<default>NULL</default></row>
<row name="date_added" null="1" autoincrement="0"> <row name="date_added" null="1" autoincrement="0">
<datatype>DATETIME</datatype> <datatype>DATETIME</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -519,7 +534,7 @@ ...@@ -519,7 +534,7 @@
<part>id</part> <part>id</part>
</key> </key>
</table> </table>
<table x="1080" y="886" name="task"> <table x="1081" y="917" name="task">
<row name="id" null="1" autoincrement="1"> <row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -623,7 +638,7 @@ ...@@ -623,7 +638,7 @@
<part>id</part> <part>id</part>
</key> </key>
</table> </table>
<table x="297" y="753" name="loginlog"> <table x="300" y="770" name="loginlog">
<row name="id" null="1" autoincrement="1"> <row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -652,7 +667,7 @@ ...@@ -652,7 +667,7 @@
<part>id</part> <part>id</part>
</key> </key>
</table> </table>
<table x="139" y="757" name="adminlog"> <table x="139" y="772" name="adminlog">
<row name="id" null="1" autoincrement="1"> <row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -678,7 +693,7 @@ ...@@ -678,7 +693,7 @@
<part>id</part> <part>id</part>
</key> </key>
</table> </table>
<table x="459" y="752" name="proxylog"> <table x="460" y="769" name="proxylog">
<row name="id" null="1" autoincrement="1"> <row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype> <datatype>INTEGER</datatype>
<default>NULL</default></row> <default>NULL</default></row>
...@@ -775,3 +790,4 @@ ...@@ -775,3 +790,4 @@
</key> </key>
</table> </table>
</sql> </sql>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment