2018-12-26 23:38:42 +00:00
|
|
|
"""passbook Group administration"""
|
2019-03-08 14:49:45 +00:00
|
|
|
from django.contrib import messages
|
2019-10-10 11:01:49 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2019-12-31 11:51:16 +00:00
|
|
|
from django.contrib.auth.mixins import (
|
|
|
|
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
|
|
|
)
|
2019-03-08 14:49:45 +00:00
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.utils.translation import ugettext as _
|
2019-10-10 11:01:49 +00:00
|
|
|
from django.views.generic import DeleteView, ListView, UpdateView
|
|
|
|
from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
|
2018-12-26 23:38:42 +00:00
|
|
|
|
2019-03-08 14:49:45 +00:00
|
|
|
from passbook.core.forms.groups import GroupForm
|
2018-12-26 23:38:42 +00:00
|
|
|
from passbook.core.models import Group
|
2019-10-10 11:01:49 +00:00
|
|
|
from passbook.lib.views import CreateAssignPermView
|
2018-12-26 23:38:42 +00:00
|
|
|
|
|
|
|
|
2019-10-10 11:01:49 +00:00
|
|
|
class GroupListView(LoginRequiredMixin, PermissionListMixin, ListView):
|
2019-03-08 14:49:45 +00:00
|
|
|
"""Show list of all groups"""
|
2018-12-26 23:38:42 +00:00
|
|
|
|
|
|
|
model = Group
|
2019-12-31 11:51:16 +00:00
|
|
|
permission_required = "passbook_core.view_group"
|
|
|
|
ordering = "name"
|
2019-10-14 11:15:42 +00:00
|
|
|
paginate_by = 40
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "administration/group/list.html"
|
2019-03-08 14:49:45 +00:00
|
|
|
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
class GroupCreateView(
|
|
|
|
SuccessMessageMixin,
|
|
|
|
LoginRequiredMixin,
|
|
|
|
DjangoPermissionRequiredMixin,
|
|
|
|
CreateAssignPermView,
|
|
|
|
):
|
2019-03-08 14:49:45 +00:00
|
|
|
"""Create new Group"""
|
|
|
|
|
2019-10-10 11:01:49 +00:00
|
|
|
model = Group
|
2019-03-08 14:49:45 +00:00
|
|
|
form_class = GroupForm
|
2019-12-31 11:51:16 +00:00
|
|
|
permission_required = "passbook_core.add_group"
|
2019-11-07 16:25:36 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "generic/create.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:groups")
|
|
|
|
success_message = _("Successfully created Group")
|
2019-03-08 14:49:45 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2019-12-31 11:51:16 +00:00
|
|
|
kwargs["type"] = "Group"
|
2019-03-08 14:49:45 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
class GroupUpdateView(
|
|
|
|
SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView
|
|
|
|
):
|
2019-03-08 14:49:45 +00:00
|
|
|
"""Update group"""
|
|
|
|
|
|
|
|
model = Group
|
|
|
|
form_class = GroupForm
|
2019-12-31 11:51:16 +00:00
|
|
|
permission_required = "passbook_core.change_group"
|
2019-03-08 14:49:45 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "generic/update.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:groups")
|
|
|
|
success_message = _("Successfully updated Group")
|
2019-03-08 14:49:45 +00:00
|
|
|
|
|
|
|
|
2019-10-10 11:01:49 +00:00
|
|
|
class GroupDeleteView(SuccessMessageMixin, LoginRequiredMixin, DeleteView):
|
2019-03-08 14:49:45 +00:00
|
|
|
"""Delete group"""
|
|
|
|
|
|
|
|
model = Group
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "generic/delete.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:groups")
|
|
|
|
success_message = _("Successfully deleted Group")
|
2019-03-08 14:49:45 +00:00
|
|
|
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
|
|
messages.success(self.request, self.success_message)
|
|
|
|
return super().delete(request, *args, **kwargs)
|