2020-09-02 22:04:12 +00:00
|
|
|
"""passbook Outpost administration"""
|
2020-09-18 19:51:08 +00:00
|
|
|
from dataclasses import asdict
|
|
|
|
from typing import Any, Dict
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib.auth.mixins import (
|
|
|
|
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
|
|
|
)
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.urls import reverse_lazy
|
2020-09-11 21:21:11 +00:00
|
|
|
from django.utils.translation import gettext as _
|
2020-09-02 22:04:12 +00:00
|
|
|
from django.views.generic import ListView, UpdateView
|
|
|
|
from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
|
|
|
|
|
2020-09-25 23:56:28 +00:00
|
|
|
from passbook.admin.views.utils import (
|
|
|
|
BackSuccessUrlMixin,
|
|
|
|
DeleteMessageView,
|
2020-10-03 17:32:01 +00:00
|
|
|
SearchListMixin,
|
2020-09-25 23:56:28 +00:00
|
|
|
UserPaginateListMixin,
|
|
|
|
)
|
2020-09-02 22:04:12 +00:00
|
|
|
from passbook.lib.views import CreateAssignPermView
|
|
|
|
from passbook.outposts.forms import OutpostForm
|
2020-09-18 19:51:08 +00:00
|
|
|
from passbook.outposts.models import Outpost, OutpostConfig
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
|
2020-09-25 23:56:28 +00:00
|
|
|
class OutpostListView(
|
2020-10-03 17:32:01 +00:00
|
|
|
LoginRequiredMixin,
|
|
|
|
PermissionListMixin,
|
|
|
|
UserPaginateListMixin,
|
|
|
|
SearchListMixin,
|
|
|
|
ListView,
|
2020-09-25 23:56:28 +00:00
|
|
|
):
|
2020-09-02 22:04:12 +00:00
|
|
|
"""Show list of all outposts"""
|
|
|
|
|
|
|
|
model = Outpost
|
|
|
|
permission_required = "passbook_outposts.view_outpost"
|
|
|
|
ordering = "name"
|
|
|
|
template_name = "administration/outpost/list.html"
|
2020-10-03 17:32:01 +00:00
|
|
|
search_fields = ["name", "_config"]
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OutpostCreateView(
|
|
|
|
SuccessMessageMixin,
|
2020-09-25 23:56:28 +00:00
|
|
|
BackSuccessUrlMixin,
|
2020-09-02 22:04:12 +00:00
|
|
|
LoginRequiredMixin,
|
|
|
|
DjangoPermissionRequiredMixin,
|
|
|
|
CreateAssignPermView,
|
|
|
|
):
|
|
|
|
"""Create new Outpost"""
|
|
|
|
|
|
|
|
model = Outpost
|
|
|
|
form_class = OutpostForm
|
|
|
|
permission_required = "passbook_outposts.add_outpost"
|
|
|
|
|
|
|
|
template_name = "generic/create.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:outposts")
|
|
|
|
success_message = _("Successfully created Outpost")
|
|
|
|
|
2020-09-18 19:51:08 +00:00
|
|
|
def get_initial(self) -> Dict[str, Any]:
|
|
|
|
return {
|
|
|
|
"_config": asdict(
|
|
|
|
OutpostConfig(passbook_host=self.request.build_absolute_uri("/"))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
class OutpostUpdateView(
|
2020-09-25 23:56:28 +00:00
|
|
|
SuccessMessageMixin,
|
|
|
|
BackSuccessUrlMixin,
|
|
|
|
LoginRequiredMixin,
|
|
|
|
PermissionRequiredMixin,
|
|
|
|
UpdateView,
|
2020-09-02 22:04:12 +00:00
|
|
|
):
|
|
|
|
"""Update outpost"""
|
|
|
|
|
|
|
|
model = Outpost
|
|
|
|
form_class = OutpostForm
|
|
|
|
permission_required = "passbook_outposts.change_outpost"
|
|
|
|
|
|
|
|
template_name = "generic/update.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:outposts")
|
2020-09-19 17:03:54 +00:00
|
|
|
success_message = _("Successfully updated Outpost")
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OutpostDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView):
|
|
|
|
"""Delete outpost"""
|
|
|
|
|
|
|
|
model = Outpost
|
|
|
|
permission_required = "passbook_outposts.delete_outpost"
|
|
|
|
|
|
|
|
template_name = "generic/delete.html"
|
|
|
|
success_url = reverse_lazy("passbook_admin:outposts")
|
2020-09-19 17:03:54 +00:00
|
|
|
success_message = _("Successfully deleted Outpost")
|