2017-04-04 03:37:52 +00:00
|
|
|
# coding:utf-8
|
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.conf import settings
|
|
|
|
from django.urls import reverse_lazy
|
2018-01-09 15:07:53 +00:00
|
|
|
from django.views.generic import TemplateView, ListView
|
|
|
|
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
2017-04-04 03:37:52 +00:00
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.views.generic.detail import DetailView, SingleObjectMixin
|
|
|
|
|
2018-01-09 15:07:53 +00:00
|
|
|
from common.const import create_success_msg, update_success_msg
|
2017-04-04 03:37:52 +00:00
|
|
|
from .. import forms
|
2018-02-09 07:24:44 +00:00
|
|
|
from ..models import AdminUser, Node
|
2019-06-19 02:47:26 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsOrgAdmin
|
2017-04-04 03:37:52 +00:00
|
|
|
|
2018-01-09 15:07:53 +00:00
|
|
|
__all__ = [
|
|
|
|
'AdminUserCreateView', 'AdminUserDetailView',
|
|
|
|
'AdminUserDeleteView', 'AdminUserListView',
|
|
|
|
'AdminUserUpdateView', 'AdminUserAssetsView',
|
|
|
|
]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserListView(PermissionsMixin, TemplateView):
|
2017-04-04 03:37:52 +00:00
|
|
|
model = AdminUser
|
|
|
|
template_name = 'assets/admin_user_list.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Admin 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
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserCreateView(PermissionsMixin,
|
2017-04-04 03:37:52 +00:00
|
|
|
SuccessMessageMixin,
|
|
|
|
CreateView):
|
|
|
|
model = AdminUser
|
|
|
|
form_class = forms.AdminUserForm
|
|
|
|
template_name = 'assets/admin_user_create_update.html'
|
|
|
|
success_url = reverse_lazy('assets:admin-user-list')
|
2018-01-09 15:07:53 +00:00
|
|
|
success_message = create_success_msg
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Create admin user')
|
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
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView):
|
2017-04-04 03:37:52 +00:00
|
|
|
model = AdminUser
|
|
|
|
form_class = forms.AdminUserForm
|
|
|
|
template_name = 'assets/admin_user_create_update.html'
|
2018-01-09 15:07:53 +00:00
|
|
|
success_url = reverse_lazy('assets:admin-user-list')
|
|
|
|
success_message = update_success_msg
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Update admin user'),
|
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
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserDetailView(PermissionsMixin, DetailView):
|
2017-12-13 09:21:08 +00:00
|
|
|
model = AdminUser
|
2017-04-04 03:37:52 +00:00
|
|
|
template_name = 'assets/admin_user_detail.html'
|
|
|
|
context_object_name = 'admin_user'
|
2017-12-13 09:21:08 +00:00
|
|
|
object = None
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2019-07-04 08:41:25 +00:00
|
|
|
from ..utils import NodeUtil
|
|
|
|
nodes = Node.objects.all()
|
|
|
|
util = NodeUtil()
|
2017-04-04 03:37:52 +00:00
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Admin user detail'),
|
2019-07-04 08:41:25 +00:00
|
|
|
'nodes': util.get_nodes_by_queryset(queryset=nodes),
|
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
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserAssetsView(PermissionsMixin, SingleObjectMixin, ListView):
|
2018-01-12 07:43:26 +00:00
|
|
|
paginate_by = settings.DISPLAY_PER_PAGE
|
2017-12-10 16:29:25 +00:00
|
|
|
template_name = 'assets/admin_user_assets.html'
|
|
|
|
context_object_name = 'admin_user'
|
2017-12-13 09:21:08 +00:00
|
|
|
object = None
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-10 16:29:25 +00:00
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2018-07-14 16:55:05 +00:00
|
|
|
self.object = self.get_object(queryset=AdminUser.objects.all())
|
2017-12-10 16:29:25 +00:00
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2019-06-19 03:31:38 +00:00
|
|
|
self.queryset = self.object.assets.all()
|
2018-02-09 03:12:40 +00:00
|
|
|
return self.queryset
|
2017-12-10 16:29:25 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Admin user detail'),
|
2017-12-10 16:29:25 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdminUserDeleteView(PermissionsMixin, DeleteView):
|
2017-04-04 03:37:52 +00:00
|
|
|
model = AdminUser
|
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:admin-user-list')
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-04-04 03:37:52 +00:00
|
|
|
|
|
|
|
|