This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/admin/views/invitations.py

55 lines
1.9 KiB
Python
Raw Normal View History

2018-12-10 13:49:15 +00:00
"""passbook Invitation administration"""
from django.contrib import messages
2018-12-10 13:13:18 +00:00
from django.contrib.messages.views import SuccessMessageMixin
2018-12-10 13:49:15 +00:00
from django.http import HttpResponseRedirect
2018-12-10 13:13:18 +00:00
from django.urls import reverse_lazy
from django.utils.translation import ugettext as _
2018-12-10 13:49:15 +00:00
from django.views.generic import CreateView, DeleteView, ListView
2018-12-10 13:13:18 +00:00
from passbook.admin.mixins import AdminRequiredMixin
2018-12-10 13:49:15 +00:00
from passbook.core.forms.invitations import InvitationForm
from passbook.core.models import Invitation
2018-12-10 15:54:28 +00:00
from passbook.core.signals import invitation_created
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
class InvitationListView(AdminRequiredMixin, ListView):
2018-12-10 13:21:42 +00:00
"""Show list of all invitations"""
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
model = Invitation
2018-12-10 13:21:42 +00:00
template_name = 'administration/invitation/list.html'
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
class InvitationCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Invitation"""
2018-12-10 13:13:18 +00:00
template_name = 'generic/create.html'
2018-12-10 13:21:42 +00:00
success_url = reverse_lazy('passbook_admin:invitations')
2018-12-10 13:49:15 +00:00
success_message = _('Successfully created Invitation')
form_class = InvitationForm
2018-12-10 13:13:18 +00:00
def get_context_data(self, **kwargs):
kwargs['type'] = 'Invitation'
return super().get_context_data(**kwargs)
2018-12-10 13:49:15 +00:00
def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
2018-12-10 15:54:28 +00:00
invitation_created.send(
sender=self,
request=self.request,
invitation=obj)
2018-12-10 13:49:15 +00:00
return HttpResponseRedirect(self.success_url)
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
class InvitationDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView):
2018-12-10 13:21:42 +00:00
"""Delete invitation"""
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
model = Invitation
2018-12-10 13:13:18 +00:00
template_name = 'generic/delete.html'
2018-12-10 13:21:42 +00:00
success_url = reverse_lazy('passbook_admin:invitations')
success_message = _('Successfully deleted Invitation')
def delete(self, request, *args, **kwargs):
messages.success(self.request, self.success_message)
return super().delete(request, *args, **kwargs)