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

41 lines
1.4 KiB
Python
Raw Normal View History

2018-12-10 13:49:15 +00:00
"""passbook Invitation administration"""
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 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
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()
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')
2018-12-10 13:49:15 +00:00
success_message = _('Successfully updated Invitation')