2017-04-04 03:37:52 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
|
|
|
|
from django.utils.translation import ugettext as _
|
2018-01-09 15:07:53 +00:00
|
|
|
from django.views.generic import TemplateView
|
2017-07-24 14:42:01 +00:00
|
|
|
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
2017-04-04 03:37:52 +00:00
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
2018-01-09 15:07:53 +00:00
|
|
|
from django.views.generic.detail import DetailView
|
2017-04-04 03:37:52 +00:00
|
|
|
|
2018-01-09 15:07:53 +00:00
|
|
|
from common.const import create_success_msg, update_success_msg
|
2018-01-30 08:12:33 +00:00
|
|
|
from ..forms import SystemUserForm
|
2018-02-09 07:24:44 +00:00
|
|
|
from ..models import SystemUser, Node
|
2017-04-04 03:37:52 +00:00
|
|
|
from ..hands import AdminUserRequiredMixin
|
2017-07-19 23:55:24 +00:00
|
|
|
|
2017-04-04 03:37:52 +00:00
|
|
|
|
2018-01-09 15:07:53 +00:00
|
|
|
__all__ = [
|
|
|
|
'SystemUserCreateView', 'SystemUserUpdateView',
|
|
|
|
'SystemUserDetailView', 'SystemUserDeleteView',
|
|
|
|
'SystemUserAssetView', 'SystemUserListView',
|
|
|
|
]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SystemUserListView(AdminUserRequiredMixin, TemplateView):
|
|
|
|
template_name = 'assets/system_user_list.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('System user list'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-13 09:21:08 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SystemUserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
|
|
|
|
model = SystemUser
|
2017-12-11 09:08:43 +00:00
|
|
|
form_class = SystemUserForm
|
2017-04-04 03:37:52 +00:00
|
|
|
template_name = 'assets/system_user_create.html'
|
|
|
|
success_url = reverse_lazy('assets:system-user-list')
|
2018-01-09 15:07:53 +00:00
|
|
|
success_message = create_success_msg
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Create system user'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-13 09:21:08 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|
2018-01-09 15:07:53 +00:00
|
|
|
class SystemUserUpdateView(AdminUserRequiredMixin, SuccessMessageMixin, UpdateView):
|
2017-04-04 03:37:52 +00:00
|
|
|
model = SystemUser
|
2018-01-30 08:12:33 +00:00
|
|
|
form_class = SystemUserForm
|
2017-04-04 03:37:52 +00:00
|
|
|
template_name = 'assets/system_user_update.html'
|
2018-01-09 15:07:53 +00:00
|
|
|
success_url = reverse_lazy('assets:system-user-list')
|
|
|
|
success_message = update_success_msg
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Update system user')
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-13 09:21:08 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
2017-07-19 23:55:24 +00:00
|
|
|
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
class SystemUserDetailView(AdminUserRequiredMixin, DetailView):
|
|
|
|
template_name = 'assets/system_user_detail.html'
|
|
|
|
context_object_name = 'system_user'
|
|
|
|
model = SystemUser
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
2017-12-13 09:21:08 +00:00
|
|
|
'action': _('System user detail'),
|
2018-02-09 07:24:44 +00:00
|
|
|
'nodes_remain': Node.objects.exclude(systemuser=self.object)
|
2017-04-04 03:37:52 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-13 09:21:08 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SystemUserDeleteView(AdminUserRequiredMixin, DeleteView):
|
|
|
|
model = SystemUser
|
2017-12-14 13:27:14 +00:00
|
|
|
template_name = 'delete_confirm.html'
|
2017-04-04 03:37:52 +00:00
|
|
|
success_url = reverse_lazy('assets:system-user-list')
|
|
|
|
|
|
|
|
|
2017-12-11 09:08:43 +00:00
|
|
|
class SystemUserAssetView(AdminUserRequiredMixin, DetailView):
|
|
|
|
model = SystemUser
|
2017-04-04 03:37:52 +00:00
|
|
|
template_name = 'assets/system_user_asset.html'
|
|
|
|
context_object_name = 'system_user'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-05 09:57:02 +00:00
|
|
|
'app': _('assets'),
|
|
|
|
'action': _('System user asset'),
|
2017-04-04 03:37:52 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-13 09:21:08 +00:00
|
|
|
return super().get_context_data(**kwargs)
|