Commit 02b5483d authored by ibuler's avatar ibuler

Update add->create edit->update and assetgrou->asset-grou etc format

parent b8c10a03
...@@ -22,9 +22,11 @@ class AssetForm(forms.ModelForm): ...@@ -22,9 +22,11 @@ class AssetForm(forms.ModelForm):
class AssetGroupForm(forms.ModelForm): class AssetGroupForm(forms.ModelForm):
assets = forms.ModelMultipleChoiceField(queryset=Asset.objects.all(), assets = forms.ModelMultipleChoiceField(queryset=Asset.objects.all(),
widget=forms.SelectMultiple(attrs={ label=_('Asset'),
'class': 'select2', required=False,
'data-placeholder': _('Select assets')})) widget=forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select assets')})
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if kwargs.get('instance'): if kwargs.get('instance'):
......
This diff is collapsed.
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-21 09:57
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assets', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='asset',
name='cabinet_pos',
field=models.IntegerField(blank=True, max_length=4, verbose_name='\u673a\u5668\u4f4d\u7f6e'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-21 09:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assets', '0002_auto_20160821_1757'),
]
operations = [
migrations.AlterField(
model_name='asset',
name='cabinet_pos',
field=models.IntegerField(blank=True, max_length=4, null=True, verbose_name='\u673a\u5668\u4f4d\u7f6e'),
),
]
...@@ -14,7 +14,7 @@ class AssetGroup(models.Model): ...@@ -14,7 +14,7 @@ class AssetGroup(models.Model):
return self.name return self.name
class Meta: class Meta:
db_table = 'assetgroup' db_table = 'asset_group'
class IDC(models.Model): class IDC(models.Model):
......
...@@ -2,35 +2,35 @@ ...@@ -2,35 +2,35 @@
{% load i18n %} {% load i18n %}
{% load common_tags %} {% load common_tags %}
{% block content_left_head %} {% block content_left_head %}
<a href="{% url 'assets:assetgroup-add' %}" class="btn btn-sm btn-primary "> {% trans "Create asset group" %} </a> <a href="{% url 'assets:asset-group-create' %}" class="btn btn-sm btn-primary "> {% trans "Create asset group" %} </a>
{% endblock %} {% endblock %}
{% block table_head %} {% block table_head %}
<th class="text-center"> <th class="text-center">
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')"> <input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
</th> </th>
<th class="text-center"><a href="{% url 'assets:assetgroup-list' %}?sort=name">{% trans 'Name' %}</a></th> <th class="text-center"><a href="{% url 'assets:asset-group-list' %}?sort=name">{% trans 'Name' %}</a></th>
<th class="text-center">{% trans 'Asset num' %}</th> <th class="text-center">{% trans 'Asset num' %}</th>
<th class="text-center"><a href="{% url 'assets:assetgroup-list' %}?sort=date_expired">{% trans 'Comment' %}</a></th> <th class="text-center"><a href="{% url 'assets:asset-group-list' %}?sort=date_expired">{% trans 'Comment' %}</a></th>
<th class="text-center"></th> <th class="text-center"></th>
{% endblock %} {% endblock %}
{% block table_body %} {% block table_body %}
{% for assetgroup in assetgroups %} {% for asset_group in asset_group_list %}
<tr class="gradeX"> <tr class="gradeX">
<td class="text-center"> <td class="text-center">
<input type="checkbox" name="checked" value="{{ assetgroup.id }}"> <input type="checkbox" name="checked" value="{{ asset_group.id }}">
</td> </td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'assets:assetgroup-detail' pk=assetgroup.id %}"> <a href="{% url 'assets:asset-group-detail' pk=asset_group.id %}">
{{ assetgroup.name }} {{ asset_group.name }}
</a> </a>
</td> </td>
<td class="text-center">{{ assetgroup.assets.count }}</td> <td class="text-center">{{ asset_group.assets.count }}</td>
<td class="text-center">{{ assetgroup.comment }}</td> <td class="text-center">{{ asset_group.comment }}</td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'assets:assetgroup-edit' pk=assetgroup.id %}" class="btn btn-xs btn-info">{% trans 'Edit' %}</a> <a href="{% url 'assets:asset-group-update' pk=asset_group.id %}" class="btn btn-xs btn-info">{% trans 'Edit' %}</a>
<a href="{% url 'assets:assetgroup-delete' pk=assetgroup.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</a> <a href="{% url 'assets:asset-group-delete' pk=asset_group.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
...@@ -55,5 +55,3 @@ ...@@ -55,5 +55,3 @@
</div> </div>
</form> </form>
{% endblock %} {% endblock %}
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% block content %} {% block content %}
<div class="wrapper wrapper-content animated fadeInRight"> <div class="wrapper wrapper-content animated fadeInRight">
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
<div class="ibox-content"> <div class="ibox-content">
<form id="asset_form"> <form id="asset_form">
<div class="col-sm-1" style="padding-left: 0"> <div class="col-sm-1" style="padding-left: 0">
<a href="{% url 'assets:asset-add' %}" class="btn btn-sm btn-primary "> 添加资产 </a> <a href="{% url 'assets:asset-create' %}" class="btn btn-sm btn-primary "> {% trans 'Create asset' %}</a>
</div> </div>
<div class="col-sm-7" style="padding-left: 0px"> <div class="col-sm-7" style="padding-left: 0px">
......
...@@ -14,14 +14,14 @@ app_name = 'assets' ...@@ -14,14 +14,14 @@ app_name = 'assets'
urlpatterns = [ urlpatterns = [
url(r'^$', views.AssetListView.as_view(), name='asset-index'), url(r'^$', views.AssetListView.as_view(), name='asset-index'),
url(r'^asset$', views.AssetListView.as_view(), name='asset-list'), url(r'^asset$', views.AssetListView.as_view(), name='asset-list'),
url(r'^asset/add$', views.AssetAddView.as_view(), name='asset-add'), url(r'^asset/create$', views.AssetCreateView.as_view(), name='asset-create'),
url(r'^asset/(?P<pk>[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'), url(r'^asset/(?P<pk>[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'),
url(r'^asset/(?P<pk>[0-9]+)$/edit', views.AssetEditView.as_view(), name='asset-edit'), url(r'^asset/(?P<pk>[0-9]+)$/update', views.AssetUpdateView.as_view(), name='asset-update'),
url(r'^asset/(?P<pk>[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'), url(r'^asset/(?P<pk>[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'),
url(r'^assetgroup$', views.AssetGroupListView.as_view(), name='assetgroup-list'), url(r'^asset-group$', views.AssetGroupListView.as_view(), name='asset-group-list'),
url(r'^assetgroup/add$', views.AssetGroupAddView.as_view(), name='assetgroup-add'), url(r'^asset-group/create$', views.AssetGroupCreateView.as_view(), name='asset-group-create'),
url(r'^assetgroup/(?P<pk>[0-9]+)$', views.AssetGroupDetailView.as_view(), name='assetgroup-detail'), url(r'^asset-group/(?P<pk>[0-9]+)$', views.AssetGroupDetailView.as_view(), name='asset-group-detail'),
url(r'^assetgroup/(?P<pk>[0-9]+)/edit$', views.AssetGroupEditView.as_view(), name='assetgroup-edit'), url(r'^asset-group/(?P<pk>[0-9]+)/update$', views.AssetGroupUpdateView.as_view(), name='asset-group-update'),
url(r'^assetgroup/(?P<pk>[0-9]+)/delete$', views.AssetGroupDeleteView.as_view(), name='assetgroup-delete'), url(r'^asset-group/(?P<pk>[0-9]+)/delete$', views.AssetGroupDeleteView.as_view(), name='asset-group-delete'),
# url(r'^api/v1.0/', include(router.urls)), # url(r'^api/v1.0/', include(router.urls)),
] ]
...@@ -16,18 +16,18 @@ from .forms import AssetForm, AssetGroupForm ...@@ -16,18 +16,18 @@ from .forms import AssetForm, AssetGroupForm
from .utils import AdminUserRequiredMixin from .utils import AdminUserRequiredMixin
class AssetAddView(CreateView): class AssetCreateView(CreateView):
model = Asset model = Asset
form_class = AssetForm form_class = AssetForm
template_name = 'assets/asset_add.html' template_name = 'assets/asset_create.html'
success_url = reverse_lazy('assets:asset-list') success_url = reverse_lazy('assets:asset-list')
def form_invalid(self, form): def form_invalid(self, form):
print(form.errors) print(form.errors)
return super(AssetAddView, self).form_invalid(form) return super(AssetCreateView, self).form_invalid(form)
class AssetEditView(UpdateView): class AssetUpdateView(UpdateView):
pass pass
...@@ -48,11 +48,11 @@ class AssetDetailView(DetailView): ...@@ -48,11 +48,11 @@ class AssetDetailView(DetailView):
template_name = 'assets/asset_detail.html' template_name = 'assets/asset_detail.html'
class AssetGroupAddView(CreateView): class AssetGroupCreateView(CreateView):
model = AssetGroup model = AssetGroup
form_class = AssetGroupForm form_class = AssetGroupForm
template_name = 'assets/assetgroup_add.html' template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:assetgroup-list') success_url = reverse_lazy('assets:asset-group-list')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
...@@ -61,13 +61,17 @@ class AssetGroupAddView(CreateView): ...@@ -61,13 +61,17 @@ class AssetGroupAddView(CreateView):
'assets': Asset.objects.all(), 'assets': Asset.objects.all(),
} }
kwargs.update(context) kwargs.update(context)
return super(AssetGroupAddView, self).get_context_data(**kwargs) return super(AssetGroupCreateView, self).get_context_data(**kwargs)
def form_valid(self, form):
print(form.data)
return super(AssetGroupCreateView, self).form_valid(form)
class AssetGroupListView(ListView): class AssetGroupListView(ListView):
model = AssetGroup model = AssetGroup
context_object_name = 'assetgroups' context_object_name = 'asset_group_list'
template_name = 'assets/assetgroup_list.html' template_name = 'assets/asset_group_list.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
...@@ -82,11 +86,11 @@ class AssetGroupDetailView(DetailView): ...@@ -82,11 +86,11 @@ class AssetGroupDetailView(DetailView):
pass pass
class AssetGroupEditView(UpdateView): class AssetGroupUpdateView(UpdateView):
model = AssetGroup model = AssetGroup
form_class = AssetGroupForm form_class = AssetGroupForm
template_name = 'assets/assetgroup_add.html' template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:assetgroup-list') success_url = reverse_lazy('assets:asset-group-list')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
...@@ -95,7 +99,7 @@ class AssetGroupEditView(UpdateView): ...@@ -95,7 +99,7 @@ class AssetGroupEditView(UpdateView):
'assets': Asset.objects.all(), 'assets': Asset.objects.all(),
} }
kwargs.update(context) kwargs.update(context)
return super(AssetGroupEditView, self).get_context_data(**kwargs) return super(AssetGroupUpdateView, self).get_context_data(**kwargs)
class AssetGroupDeleteView(DeleteView): class AssetGroupDeleteView(DeleteView):
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</a> </a>
<ul class="nav nav-second-level active"> <ul class="nav nav-second-level active">
<li id="user"><a href="{% url 'users:user-list' %}">{% trans 'User' %}</a></li> <li id="user"><a href="{% url 'users:user-list' %}">{% trans 'User' %}</a></li>
<li id="usergroup"><a href="{% url 'users:usergroup-list' %}">{% trans 'User group' %}</a></li> <li id="user-group"><a href="{% url 'users:user-group-list' %}">{% trans 'User group' %}</a></li>
</ul> </ul>
</li> </li>
<li id="assets"> <li id="assets">
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</a> </a>
<ul class="nav nav-second-level"> <ul class="nav nav-second-level">
<li id="asset"><a href="{% url 'assets:asset-list' %}">{% trans 'Asset' %}</a></li> <li id="asset"><a href="{% url 'assets:asset-list' %}">{% trans 'Asset' %}</a></li>
<li id="assetgroup"><a href="{% url 'assets:assetgroup-list' %}">{% trans 'Asset group' %}</a></li> <li id="asset-group"><a href="{% url 'assets:asset-group-list' %}">{% trans 'Asset group' %}</a></li>
<li id="idc"><a href="">{% trans 'IDC' %}</a></li> <li id="idc"><a href="">{% trans 'IDC' %}</a></li>
<li id="admin-user"><a href="">{% trans 'Admin user' %}</a></li> <li id="admin-user"><a href="">{% trans 'Admin user' %}</a></li>
<li id="system-user"><a href="">{% trans 'System user' %}</a></li> <li id="system-user"><a href="">{% trans 'System user' %}</a></li>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<strong class="font-bold"> {{ request.user.name }}<span style="color: #8095a8"></span></strong> <strong class="font-bold"> {{ request.user.name }}<span style="color: #8095a8"></span></strong>
</span> </span>
<span class="text-muted text-xs block"> <span class="text-muted text-xs block">
{{ request.user.get_role_display | default:"{% trans 'User' %}" }}<b class="caret"></b> {{ request.user.get_role_display | default:_('User') }}<b class="caret"></b>
</span> </span>
</span> </span>
</a> </a>
......
...@@ -14,7 +14,7 @@ class UserLoginForm(forms.Form): ...@@ -14,7 +14,7 @@ class UserLoginForm(forms.Form):
captcha = CaptchaField() captcha = CaptchaField()
class UserAddForm(ModelForm): class UserCreateForm(ModelForm):
class Meta: class Meta:
model = User model = User
fields = [ fields = [
......
...@@ -66,7 +66,7 @@ class UserGroup(models.Model): ...@@ -66,7 +66,7 @@ class UserGroup(models.Model):
return self.name return self.name
class Meta: class Meta:
db_table = 'usergroup' db_table = 'user-group'
@classmethod @classmethod
def initial(cls): def initial(cls):
......
...@@ -7,7 +7,7 @@ from .models import User, UserGroup ...@@ -7,7 +7,7 @@ from .models import User, UserGroup
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):
groups = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='users:usergroup-detail-api') groups = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='users:user-group-detail-api')
class Meta: class Meta:
model = User model = User
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
{% load i18n %} {% load i18n %}
{% load common_tags %} {% load common_tags %}
{% block content_left_head %} {% block content_left_head %}
<a href="{% url 'users:usergroup-add' %}" class="btn btn-sm btn-primary "> 添加用户组 </a> <a href="{% url 'users:user-group-create' %}" class="btn btn-sm btn-primary "> 添加用户组 </a>
{% endblock %} {% endblock %}
{% block table_head %} {% block table_head %}
<th class="text-center"> <th class="text-center">
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')"> <input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
</th> </th>
<th class="text-center"><a href="{% url 'users:usergroup-list' %}?sort=name">名称</a></th> <th class="text-center"><a href="{% url 'users:user-group-list' %}?sort=name">名称</a></th>
<th class="text-center">用户数量</th> <th class="text-center">用户数量</th>
<th class="text-center">资产数量</th> <th class="text-center">资产数量</th>
<th class="text-center">描述</th> <th class="text-center">描述</th>
...@@ -17,22 +17,22 @@ ...@@ -17,22 +17,22 @@
{% endblock %} {% endblock %}
{% block table_body %} {% block table_body %}
{% for usergroup in usergroup_list %} {% for user_group in user_group_list %}
<tr class="gradeX"> <tr class="gradeX">
<td class="text-center"> <td class="text-center">
<input type="checkbox" name="checked" value="{{ usergroup.id }}"> <input type="checkbox" name="checked" value="{{ user_group.id }}">
</td> </td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'users:usergroup-detail' pk=usergroup.id %}"> <a href="{% url 'users:user-group-detail' pk=user_group.id %}">
{{ usergroup.name }} {{ user_group.name }}
</a> </a>
</td> </td>
<td class="text-center">{{ usergroup.users.all|length }}</td> <td class="text-center">{{ user_group.users.all|length }}</td>
<td class="text-center">数量</td> <td class="text-center">数量</td>
<th class="text-center">{{ usergroup.comment|truncatewords:8 }}</th> <th class="text-center">{{ user_group.comment|truncatewords:8 }}</th>
<td class="text-center"> <td class="text-center">
<a href="{% url 'users:usergroup-edit' pk=usergroup.id %}" class="btn btn-xs btn-info">编辑</a> <a href="{% url 'users:user-group-update' pk=user_group.id %}" class="btn btn-xs btn-info">编辑</a>
<a href="{% url 'users:usergroup-delete' pk=usergroup.id %}" class="btn btn-xs btn-danger del">删除</a> <a href="{% url 'users:user-group-delete' pk=user_group.id %}" class="btn btn-xs btn-danger del">删除</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% load i18n %} {% load i18n %}
{% load common_tags %} {% load common_tags %}
{% block content_left_head %} {% block content_left_head %}
<a href="{% url 'users:user-add' %}" class="btn btn-sm btn-primary "> {% trans "Create user" %} </a> <a href="{% url 'users:user-create' %}" class="btn btn-sm btn-primary "> {% trans "Create user" %} </a>
{% endblock %} {% endblock %}
{% block table_head %} {% block table_head %}
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
{% endif %} {% endif %}
</td> </td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'users:user-edit' pk=user.id %}" class="btn btn-xs btn-info">{% trans 'Edit' %}</a> <a href="{% url 'users:user-update' pk=user.id %}" class="btn btn-xs btn-info">{% trans 'Edit' %}</a>
<a href="{% url 'users:user-delete' pk=user.id %}" class="btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}">{% trans 'Delete' %}</a> <a href="{% url 'users:user-delete' pk=user.id %}" class="btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}">{% trans 'Delete' %}</a>
</td> </td>
</tr> </tr>
......
...@@ -54,7 +54,7 @@ class UserAddTests(TestCase): ...@@ -54,7 +54,7 @@ class UserAddTests(TestCase):
'date_expired': '2086-08-06 19:12:22', 'date_expired': '2086-08-06 19:12:22',
} }
response = self.client.post(reverse('users:user-add'), data) response = self.client.post(reverse('users:user-create'), data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], reverse('users:user-list')) self.assertEqual(response['location'], reverse('users:user-list'))
......
...@@ -17,14 +17,14 @@ urlpatterns = [ ...@@ -17,14 +17,14 @@ urlpatterns = [
url(r'^password/reset/success$', views.UserResetPasswordSuccessView.as_view(), name='reset-password-success'), url(r'^password/reset/success$', views.UserResetPasswordSuccessView.as_view(), name='reset-password-success'),
url(r'^user$', views.UserListView.as_view(), name='user-list'), url(r'^user$', views.UserListView.as_view(), name='user-list'),
url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'), url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/add$', views.UserAddView.as_view(), name='user-add'), url(r'^user/create$', views.UserCreateView.as_view(), name='user-create'),
url(r'^user/(?P<pk>[0-9]+)/edit$', views.UserUpdateView.as_view(), name='user-edit'), url(r'^user/(?P<pk>[0-9]+)/update$', views.UserUpdateView.as_view(), name='user-update'),
url(r'^user/(?P<pk>[0-9]+)/delete$', views.UserDeleteView.as_view(), name='user-delete'), url(r'^user/(?P<pk>[0-9]+)/delete$', views.UserDeleteView.as_view(), name='user-delete'),
url(r'^usergroup$', views.UserGroupListView.as_view(), name='usergroup-list'), url(r'^user-group$', views.UserGroupListView.as_view(), name='user-group-list'),
url(r'^usergroup/(?P<pk>[0-9]+)$', views.UserGroupDetailView.as_view(), name='usergroup-detail'), url(r'^user-group/(?P<pk>[0-9]+)$', views.UserGroupDetailView.as_view(), name='user-group-detail'),
url(r'^usergroup/add/$', views.UserGroupAddView.as_view(), name='usergroup-add'), url(r'^user-group/create$', views.UserGroupCreateView.as_view(), name='user-group-create'),
url(r'^usergroup/(?P<pk>[0-9]+)/edit$', views.UserGroupUpdateView.as_view(), name='usergroup-edit'), url(r'^user-group/(?P<pk>[0-9]+)/update$', views.UserGroupUpdateView.as_view(), name='user-group-update'),
url(r'^usergroup/(?P<pk>[0-9]+)/delete$', views.UserGroupDeleteView.as_view(), name='usergroup-delete'), url(r'^user-group/(?P<pk>[0-9]+)/delete$', views.UserGroupDeleteView.as_view(), name='user-group-delete'),
] ]
...@@ -32,6 +32,6 @@ urlpatterns += [ ...@@ -32,6 +32,6 @@ urlpatterns += [
url(r'^v1/users$', api.UserListAddApi.as_view(), name='user-list-api'), url(r'^v1/users$', api.UserListAddApi.as_view(), name='user-list-api'),
url(r'^v1/users/(?P<pk>[0-9]+)$', api.UserDetailDeleteUpdateApi.as_view(), name='user-detail-api'), url(r'^v1/users/(?P<pk>[0-9]+)$', api.UserDetailDeleteUpdateApi.as_view(), name='user-detail-api'),
url(r'^v1/users/(?P<pk>[0-9]+)/active$', api.UserActiveApi.as_view(), name='user-active-api'), url(r'^v1/users/(?P<pk>[0-9]+)/active$', api.UserActiveApi.as_view(), name='user-active-api'),
url(r'^v1/usergroups$', api.UserGroupListAddApi.as_view(), name='usergroup-list-api'), url(r'^v1/usergroups$', api.UserGroupListAddApi.as_view(), name='user-group-list-api'),
url(r'^v1/usergroups/(?P<pk>[0-9]+)$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='usergroup-detail-api'), url(r'^v1/usergroups/(?P<pk>[0-9]+)$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='user-group-detail-api'),
] ]
...@@ -20,7 +20,7 @@ from django.contrib.auth import views as auth_view, authenticate, login, logout ...@@ -20,7 +20,7 @@ from django.contrib.auth import views as auth_view, authenticate, login, logout
from common.utils import get_object_or_none from common.utils import get_object_or_none
from .models import User, UserGroup from .models import User, UserGroup
from .forms import UserAddForm, UserUpdateForm, UserGroupForm, UserLoginForm from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm
from .utils import AdminUserRequiredMixin, ssh_key_gen, user_add_success_next, send_reset_password_mail from .utils import AdminUserRequiredMixin, ssh_key_gen, user_add_success_next, send_reset_password_mail
...@@ -101,15 +101,15 @@ class UserListView(AdminUserRequiredMixin, ListView): ...@@ -101,15 +101,15 @@ class UserListView(AdminUserRequiredMixin, ListView):
return context return context
class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView): class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
model = User model = User
form_class = UserAddForm form_class = UserCreateForm
template_name = 'users/user_add.html' template_name = 'users/user_create.html'
success_url = reverse_lazy('users:user-list') success_url = reverse_lazy('users:user-list')
success_message = _('Create user<a href="%s">%s</a> success.') success_message = _('Create user<a href="%s">%s</a> success.')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(UserAddView, self).get_context_data(**kwargs) context = super(UserCreateView, self).get_context_data(**kwargs)
context.update({'app': _('Users'), 'action': _('Create user')}) context.update({'app': _('Users'), 'action': _('Create user')})
return context return context
...@@ -118,7 +118,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView): ...@@ -118,7 +118,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
user.created_by = self.request.user.username or 'System' user.created_by = self.request.user.username or 'System'
user.save() user.save()
user_add_success_next(user) user_add_success_next(user)
return super(UserAddView, self).form_valid(form) return super(UserCreateView, self).form_valid(form)
def get_success_message(self, cleaned_data): def get_success_message(self, cleaned_data):
return self.success_message % ( return self.success_message % (
...@@ -130,7 +130,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView): ...@@ -130,7 +130,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
class UserUpdateView(AdminUserRequiredMixin, UpdateView): class UserUpdateView(AdminUserRequiredMixin, UpdateView):
model = User model = User
form_class = UserUpdateForm form_class = UserUpdateForm
template_name = 'users/user_edit.html' template_name = 'users/user_update.html'
context_object_name = 'user' context_object_name = 'user'
success_url = reverse_lazy('users:user-list') success_url = reverse_lazy('users:user-list')
...@@ -175,8 +175,8 @@ class UserDetailView(AdminUserRequiredMixin, DetailView): ...@@ -175,8 +175,8 @@ class UserDetailView(AdminUserRequiredMixin, DetailView):
class UserGroupListView(AdminUserRequiredMixin, ListView): class UserGroupListView(AdminUserRequiredMixin, ListView):
model = UserGroup model = UserGroup
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
context_object_name = 'usergroup_list' context_object_name = 'user_group_list'
template_name = 'users/usergroup_list.html' template_name = 'users/user_group_list.html'
ordering = '-date_added' ordering = '-date_added'
def get_queryset(self): def get_queryset(self):
...@@ -196,26 +196,26 @@ class UserGroupListView(AdminUserRequiredMixin, ListView): ...@@ -196,26 +196,26 @@ class UserGroupListView(AdminUserRequiredMixin, ListView):
return context return context
class UserGroupAddView(AdminUserRequiredMixin, CreateView): class UserGroupCreateView(AdminUserRequiredMixin, CreateView):
model = UserGroup model = UserGroup
form_class = UserGroupForm form_class = UserGroupForm
template_name = 'users/usergroup_add.html' template_name = 'users/user_group_create.html'
success_url = reverse_lazy('users:usergroup-list') success_url = reverse_lazy('users:user-group-list')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(UserGroupAddView, self).get_context_data(**kwargs) context = super(UserGroupCreateView, self).get_context_data(**kwargs)
users = User.objects.all() users = User.objects.all()
context.update({'app': _('Users'), 'action': _('Create usergroup'), 'users': users}) context.update({'app': _('Users'), 'action': _('Create user group'), 'users': users})
return context return context
def form_valid(self, form): def form_valid(self, form):
usergroup = form.save() user_group = form.save()
users_id_list = self.request.POST.getlist('users', []) users_id_list = self.request.POST.getlist('users', [])
users = [get_object_or_404(User, id=user_id) for user_id in users_id_list] users = [get_object_or_404(User, id=user_id) for user_id in users_id_list]
usergroup.created_by = self.request.user.username or 'Admin' user_group.created_by = self.request.user.username or 'Admin'
usergroup.users.add(*tuple(users)) user_group.users.add(*tuple(users))
usergroup.save() user_group.save()
return super(UserGroupAddView, self).form_valid(form) return super(UserGroupCreateView, self).form_valid(form)
class UserGroupUpdateView(UpdateView): class UserGroupUpdateView(UpdateView):
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## 语言框架 ## 语言框架
1. Python 2.7 由于ansible目前不支持python3 1. Python 2.7 由于ansible目前不支持python3
2. Django 1.10 (最新版本) 2. Django 1.10 (最新版本)
3. Terminal Websocket使用go实现 3. Terminal Websocket使用go实现 (未来)
## Django规范 ## Django规范
...@@ -32,7 +32,8 @@ Python方面大致的风格,我们采用pocoo的[Style Guidance](http://www.po ...@@ -32,7 +32,8 @@ Python方面大致的风格,我们采用pocoo的[Style Guidance](http://www.po
#### 最大行长度 #### 最大行长度
按PEP8规范,Python一般限制最大79个字符, 如果有必要最多84个字符 按PEP8规范,Python一般限制最大79个字符, 但是Django的命名,url等通常比较长,
而且21世纪都是宽屏了,所以我们限制最大120字符
**补充说明:HTML代码不受此规范约束。** **补充说明:HTML代码不受此规范约束。**
......
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