From 89c2b8d49c1fe89a9cfed245b5e0d865a3fee8eb Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 10 Dec 2018 14:13:18 +0100 Subject: [PATCH] admin: add invite administration --- .../admin/templates/administration/base.html | 3 ++ .../templates/administration/invite/list.html | 39 +++++++++++++++++ passbook/admin/urls.py | 9 +++- passbook/admin/views/invites.py | 43 +++++++++++++++++++ passbook/core/forms/invites.py | 14 ++++++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 passbook/admin/templates/administration/invite/list.html create mode 100644 passbook/admin/views/invites.py create mode 100644 passbook/core/forms/invites.py diff --git a/passbook/admin/templates/administration/base.html b/passbook/admin/templates/administration/base.html index 1352cabe8..47ab8ef42 100644 --- a/passbook/admin/templates/administration/base.html +++ b/passbook/admin/templates/administration/base.html @@ -20,6 +20,9 @@
  • {% trans 'Rules' %}
  • +
  • + {% trans 'Invites' %} +
  • {% trans 'Users' %}
  • diff --git a/passbook/admin/templates/administration/invite/list.html b/passbook/admin/templates/administration/invite/list.html new file mode 100644 index 000000000..cda490430 --- /dev/null +++ b/passbook/admin/templates/administration/invite/list.html @@ -0,0 +1,39 @@ +{% extends "administration/base.html" %} + +{% load i18n %} +{% load utils %} + +{% block title %} +{% title %} +{% endblock %} + +{% block content %} +
    +

    {% trans "Invites" %}

    + + {% trans 'Create...' %} + +
    + + + + + + + + + + {% for invite in object_list %} + + + + + + {% endfor %} + +
    {% trans 'Name' %}{% trans 'Provider' %}
    {{ invite.name }}{{ invite.provider }} + {% trans 'Edit' %} + {% trans 'Delete' %} +
    +
    +{% endblock %} diff --git a/passbook/admin/urls.py b/passbook/admin/urls.py index f1ad1023f..a0953e3ab 100644 --- a/passbook/admin/urls.py +++ b/passbook/admin/urls.py @@ -1,8 +1,8 @@ """passbook URL Configuration""" from django.urls import path -from passbook.admin.views import (applications, overview, providers, rules, - sources) +from passbook.admin.views import (applications, invites, overview, providers, + rules, sources) urlpatterns = [ path('', overview.AdministrationOverviewView.as_view(), name='overview'), @@ -34,5 +34,10 @@ urlpatterns = [ providers.ProviderUpdateView.as_view(), name='provider-update'), path('providers//delete/', providers.ProviderDeleteView.as_view(), name='provider-delete'), + # Invites + path('invites/', invites.InviteListView.as_view(), name='invites'), + path('invites/create/', invites.InviteCreateView.as_view(), name='invite-create'), + path('invites//update/', invites.InviteUpdateView.as_view(), name='invite-update'), + path('invites//delete/', invites.InviteDeleteView.as_view(), name='invite-delete'), # path('api/v1/', include('passbook.admin.api.v1.urls')) ] diff --git a/passbook/admin/views/invites.py b/passbook/admin/views/invites.py new file mode 100644 index 000000000..3992d2b28 --- /dev/null +++ b/passbook/admin/views/invites.py @@ -0,0 +1,43 @@ +"""passbook Invite administration""" +from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy +from django.utils.translation import ugettext as _ +from django.views.generic import CreateView, DeleteView, ListView, UpdateView + +from passbook.admin.mixins import AdminRequiredMixin +from passbook.core.forms.invites import InviteForm +from passbook.core.models import Invite + + +class InviteListView(AdminRequiredMixin, ListView): + """Show list of all invites""" + + model = Invite + template_name = 'administration/invite/list.html' + + +class InviteCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView): + """Create new Invite""" + + template_name = 'generic/create.html' + success_url = reverse_lazy('passbook_admin:invites') + success_message = _('Successfully created Invite') + form_class = InviteForm + + +class InviteUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView): + """Update invite""" + + model = Invite + template_name = 'generic/update.html' + success_url = reverse_lazy('passbook_admin:invites') + success_message = _('Successfully updated Invite') + form_class = InviteForm + +class InviteDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): + """Delete invite""" + + model = Invite + template_name = 'generic/delete.html' + success_url = reverse_lazy('passbook_admin:invites') + success_message = _('Successfully updated Invite') diff --git a/passbook/core/forms/invites.py b/passbook/core/forms/invites.py new file mode 100644 index 000000000..4f0aa275d --- /dev/null +++ b/passbook/core/forms/invites.py @@ -0,0 +1,14 @@ +"""passbook core invite form""" + +from django import forms + +from passbook.core.models import Invite + + +class InviteForm(forms.ModelForm): + """InviteForm""" + + class Meta: + + model = Invite + fields = '__all__'