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):
class AssetGroupForm(forms.ModelForm):
assets = forms.ModelMultipleChoiceField(queryset=Asset.objects.all(),
widget=forms.SelectMultiple(attrs={
'class': 'select2',
'data-placeholder': _('Select assets')}))
label=_('Asset'),
required=False,
widget=forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select assets')})
)
def __init__(self, *args, **kwargs):
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):
return self.name
class Meta:
db_table = 'assetgroup'
db_table = 'asset_group'
class IDC(models.Model):
......
......@@ -2,35 +2,35 @@
{% load i18n %}
{% load common_tags %}
{% 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 %}
{% block table_head %}
<th class="text-center">
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
</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"><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>
{% endblock %}
{% block table_body %}
{% for assetgroup in assetgroups %}
{% for asset_group in asset_group_list %}
<tr class="gradeX">
<td class="text-center">
<input type="checkbox" name="checked" value="{{ assetgroup.id }}">
<input type="checkbox" name="checked" value="{{ asset_group.id }}">
</td>
<td class="text-center">
<a href="{% url 'assets:assetgroup-detail' pk=assetgroup.id %}">
{{ assetgroup.name }}
<a href="{% url 'assets:asset-group-detail' pk=asset_group.id %}">
{{ asset_group.name }}
</a>
</td>
<td class="text-center">{{ assetgroup.assets.count }}</td>
<td class="text-center">{{ assetgroup.comment }}</td>
<td class="text-center">{{ asset_group.assets.count }}</td>
<td class="text-center">{{ asset_group.comment }}</td>
<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:assetgroup-delete' pk=assetgroup.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</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:asset-group-delete' pk=asset_group.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</a>
</td>
</tr>
{% endfor %}
......@@ -55,5 +55,3 @@
</div>
</form>
{% endblock %}
{% extends 'base.html' %}
{% load i18n %}
{% block content %}
<div class="wrapper wrapper-content animated fadeInRight">
......@@ -23,7 +24,7 @@
<div class="ibox-content">
<form id="asset_form">
<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 class="col-sm-7" style="padding-left: 0px">
......
......@@ -14,14 +14,14 @@ app_name = 'assets'
urlpatterns = [
url(r'^$', views.AssetListView.as_view(), name='asset-index'),
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]+)$/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'^assetgroup$', views.AssetGroupListView.as_view(), name='assetgroup-list'),
url(r'^assetgroup/add$', views.AssetGroupAddView.as_view(), name='assetgroup-add'),
url(r'^assetgroup/(?P<pk>[0-9]+)$', views.AssetGroupDetailView.as_view(), name='assetgroup-detail'),
url(r'^assetgroup/(?P<pk>[0-9]+)/edit$', views.AssetGroupEditView.as_view(), name='assetgroup-edit'),
url(r'^assetgroup/(?P<pk>[0-9]+)/delete$', views.AssetGroupDeleteView.as_view(), name='assetgroup-delete'),
url(r'^asset-group$', views.AssetGroupListView.as_view(), name='asset-group-list'),
url(r'^asset-group/create$', views.AssetGroupCreateView.as_view(), name='asset-group-create'),
url(r'^asset-group/(?P<pk>[0-9]+)$', views.AssetGroupDetailView.as_view(), name='asset-group-detail'),
url(r'^asset-group/(?P<pk>[0-9]+)/update$', views.AssetGroupUpdateView.as_view(), name='asset-group-update'),
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)),
]
......@@ -16,18 +16,18 @@ from .forms import AssetForm, AssetGroupForm
from .utils import AdminUserRequiredMixin
class AssetAddView(CreateView):
class AssetCreateView(CreateView):
model = Asset
form_class = AssetForm
template_name = 'assets/asset_add.html'
template_name = 'assets/asset_create.html'
success_url = reverse_lazy('assets:asset-list')
def form_invalid(self, form):
print(form.errors)
return super(AssetAddView, self).form_invalid(form)
return super(AssetCreateView, self).form_invalid(form)
class AssetEditView(UpdateView):
class AssetUpdateView(UpdateView):
pass
......@@ -48,11 +48,11 @@ class AssetDetailView(DetailView):
template_name = 'assets/asset_detail.html'
class AssetGroupAddView(CreateView):
class AssetGroupCreateView(CreateView):
model = AssetGroup
form_class = AssetGroupForm
template_name = 'assets/assetgroup_add.html'
success_url = reverse_lazy('assets:assetgroup-list')
template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:asset-group-list')
def get_context_data(self, **kwargs):
context = {
......@@ -61,13 +61,17 @@ class AssetGroupAddView(CreateView):
'assets': Asset.objects.all(),
}
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):
model = AssetGroup
context_object_name = 'assetgroups'
template_name = 'assets/assetgroup_list.html'
context_object_name = 'asset_group_list'
template_name = 'assets/asset_group_list.html'
def get_context_data(self, **kwargs):
context = {
......@@ -82,11 +86,11 @@ class AssetGroupDetailView(DetailView):
pass
class AssetGroupEditView(UpdateView):
class AssetGroupUpdateView(UpdateView):
model = AssetGroup
form_class = AssetGroupForm
template_name = 'assets/assetgroup_add.html'
success_url = reverse_lazy('assets:assetgroup-list')
template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:asset-group-list')
def get_context_data(self, **kwargs):
context = {
......@@ -95,7 +99,7 @@ class AssetGroupEditView(UpdateView):
'assets': Asset.objects.all(),
}
kwargs.update(context)
return super(AssetGroupEditView, self).get_context_data(**kwargs)
return super(AssetGroupUpdateView, self).get_context_data(**kwargs)
class AssetGroupDeleteView(DeleteView):
......
......@@ -10,7 +10,7 @@
</a>
<ul class="nav nav-second-level active">
<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>
</li>
<li id="assets">
......@@ -19,7 +19,7 @@
</a>
<ul class="nav nav-second-level">
<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="admin-user"><a href="">{% trans 'Admin user' %}</a></li>
<li id="system-user"><a href="">{% trans 'System user' %}</a></li>
......
......@@ -11,7 +11,7 @@
<strong class="font-bold"> {{ request.user.name }}<span style="color: #8095a8"></span></strong>
</span>
<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>
</a>
......
......@@ -14,7 +14,7 @@ class UserLoginForm(forms.Form):
captcha = CaptchaField()
class UserAddForm(ModelForm):
class UserCreateForm(ModelForm):
class Meta:
model = User
fields = [
......
......@@ -66,7 +66,7 @@ class UserGroup(models.Model):
return self.name
class Meta:
db_table = 'usergroup'
db_table = 'user-group'
@classmethod
def initial(cls):
......
......@@ -7,7 +7,7 @@ from .models import User, UserGroup
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:
model = User
......
......@@ -2,14 +2,14 @@
{% load i18n %}
{% load common_tags %}
{% 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 %}
{% block table_head %}
<th class="text-center">
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
</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>
......@@ -17,22 +17,22 @@
{% endblock %}
{% block table_body %}
{% for usergroup in usergroup_list %}
{% for user_group in user_group_list %}
<tr class="gradeX">
<td class="text-center">
<input type="checkbox" name="checked" value="{{ usergroup.id }}">
<input type="checkbox" name="checked" value="{{ user_group.id }}">
</td>
<td class="text-center">
<a href="{% url 'users:usergroup-detail' pk=usergroup.id %}">
{{ usergroup.name }}
<a href="{% url 'users:user-group-detail' pk=user_group.id %}">
{{ user_group.name }}
</a>
</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>
<th class="text-center">{{ usergroup.comment|truncatewords:8 }}</th>
<th class="text-center">{{ user_group.comment|truncatewords:8 }}</th>
<td class="text-center">
<a href="{% url 'users:usergroup-edit' pk=usergroup.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-update' pk=user_group.id %}" class="btn btn-xs btn-info">编辑</a>
<a href="{% url 'users:user-group-delete' pk=user_group.id %}" class="btn btn-xs btn-danger del">删除</a>
</td>
</tr>
{% endfor %}
......
......@@ -2,7 +2,7 @@
{% load i18n %}
{% load common_tags %}
{% 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 %}
{% block table_head %}
......@@ -41,7 +41,7 @@
{% endif %}
</td>
<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>
</td>
</tr>
......
......@@ -54,7 +54,7 @@ class UserAddTests(TestCase):
'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['location'], reverse('users:user-list'))
......
......@@ -17,14 +17,14 @@ urlpatterns = [
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/(?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/(?P<pk>[0-9]+)/edit$', views.UserUpdateView.as_view(), name='user-edit'),
url(r'^user/create$', views.UserCreateView.as_view(), name='user-create'),
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'^usergroup$', views.UserGroupListView.as_view(), name='usergroup-list'),
url(r'^usergroup/(?P<pk>[0-9]+)$', views.UserGroupDetailView.as_view(), name='usergroup-detail'),
url(r'^usergroup/add/$', views.UserGroupAddView.as_view(), name='usergroup-add'),
url(r'^usergroup/(?P<pk>[0-9]+)/edit$', views.UserGroupUpdateView.as_view(), name='usergroup-edit'),
url(r'^usergroup/(?P<pk>[0-9]+)/delete$', views.UserGroupDeleteView.as_view(), name='usergroup-delete'),
url(r'^user-group$', views.UserGroupListView.as_view(), name='user-group-list'),
url(r'^user-group/(?P<pk>[0-9]+)$', views.UserGroupDetailView.as_view(), name='user-group-detail'),
url(r'^user-group/create$', views.UserGroupCreateView.as_view(), name='user-group-create'),
url(r'^user-group/(?P<pk>[0-9]+)/update$', views.UserGroupUpdateView.as_view(), name='user-group-update'),
url(r'^user-group/(?P<pk>[0-9]+)/delete$', views.UserGroupDeleteView.as_view(), name='user-group-delete'),
]
......@@ -32,6 +32,6 @@ urlpatterns += [
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]+)/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/(?P<pk>[0-9]+)$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='usergroup-detail-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='user-group-detail-api'),
]
......@@ -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 .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
......@@ -101,15 +101,15 @@ class UserListView(AdminUserRequiredMixin, ListView):
return context
class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
model = User
form_class = UserAddForm
template_name = 'users/user_add.html'
form_class = UserCreateForm
template_name = 'users/user_create.html'
success_url = reverse_lazy('users:user-list')
success_message = _('Create user<a href="%s">%s</a> success.')
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')})
return context
......@@ -118,7 +118,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
user.created_by = self.request.user.username or 'System'
user.save()
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):
return self.success_message % (
......@@ -130,7 +130,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
class UserUpdateView(AdminUserRequiredMixin, UpdateView):
model = User
form_class = UserUpdateForm
template_name = 'users/user_edit.html'
template_name = 'users/user_update.html'
context_object_name = 'user'
success_url = reverse_lazy('users:user-list')
......@@ -175,8 +175,8 @@ class UserDetailView(AdminUserRequiredMixin, DetailView):
class UserGroupListView(AdminUserRequiredMixin, ListView):
model = UserGroup
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
context_object_name = 'usergroup_list'
template_name = 'users/usergroup_list.html'
context_object_name = 'user_group_list'
template_name = 'users/user_group_list.html'
ordering = '-date_added'
def get_queryset(self):
......@@ -196,26 +196,26 @@ class UserGroupListView(AdminUserRequiredMixin, ListView):
return context
class UserGroupAddView(AdminUserRequiredMixin, CreateView):
class UserGroupCreateView(AdminUserRequiredMixin, CreateView):
model = UserGroup
form_class = UserGroupForm
template_name = 'users/usergroup_add.html'
success_url = reverse_lazy('users:usergroup-list')
template_name = 'users/user_group_create.html'
success_url = reverse_lazy('users:user-group-list')
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()
context.update({'app': _('Users'), 'action': _('Create usergroup'), 'users': users})
context.update({'app': _('Users'), 'action': _('Create user group'), 'users': users})
return context
def form_valid(self, form):
usergroup = form.save()
user_group = form.save()
users_id_list = self.request.POST.getlist('users', [])
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'
usergroup.users.add(*tuple(users))
usergroup.save()
return super(UserGroupAddView, self).form_valid(form)
user_group.created_by = self.request.user.username or 'Admin'
user_group.users.add(*tuple(users))
user_group.save()
return super(UserGroupCreateView, self).form_valid(form)
class UserGroupUpdateView(UpdateView):
......
......@@ -3,7 +3,7 @@
## 语言框架
1. Python 2.7 由于ansible目前不支持python3
2. Django 1.10 (最新版本)
3. Terminal Websocket使用go实现
3. Terminal Websocket使用go实现 (未来)
## Django规范
......@@ -32,7 +32,8 @@ Python方面大致的风格,我们采用pocoo的[Style Guidance](http://www.po
#### 最大行长度
按PEP8规范,Python一般限制最大79个字符, 如果有必要最多84个字符
按PEP8规范,Python一般限制最大79个字符, 但是Django的命名,url等通常比较长,
而且21世纪都是宽屏了,所以我们限制最大120字符
**补充说明: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