From 9bd85aba7acb7713b16e7b7c3a29370e71feea28 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sat, 1 Aug 2020 19:00:11 +0200 Subject: [PATCH] Building a voucher-verify form. --- lostplaces/lostplaces_app/forms.py | 5 +++++ .../lostplaces_app/templates/voucher-verify.html | 15 +++++++++++++++ lostplaces/lostplaces_app/urls.py | 3 +++ lostplaces/lostplaces_app/views.py | 14 +++++++++++--- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 lostplaces/lostplaces_app/templates/voucher-verify.html diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index 6c78036..d545711 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -7,6 +7,11 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import Explorer, Place, PlaceImage, Voucher +class VoucherVerifyForm(forms.ModelForm): + class Meta: + model = Voucher + fields = ['code'] + class ExplorerCreationForm(UserCreationForm): class Meta: model = Explorer diff --git a/lostplaces/lostplaces_app/templates/voucher-verify.html b/lostplaces/lostplaces_app/templates/voucher-verify.html new file mode 100644 index 0000000..b316ff3 --- /dev/null +++ b/lostplaces/lostplaces_app/templates/voucher-verify.html @@ -0,0 +1,15 @@ +{% extends 'global.html'%} +{% load static %} + +# {% block title %}Voucher-Überprüfung{% endblock %} + +{% block maincontent %} + +

Voucher-Überprüfung

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock maincontent %} \ No newline at end of file diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py index de6fd79..4e6fc00 100644 --- a/lostplaces/lostplaces_app/urls.py +++ b/lostplaces/lostplaces_app/urls.py @@ -1,6 +1,7 @@ from django.urls import path from .views import ( hello_world, + VoucherVerify, place_detail_view, place_list_view, SignUpView, @@ -11,6 +12,8 @@ from .views import ( urlpatterns = [ path('hello_world/', hello_world), # You know what this is :P path('signup/', SignUpView.as_view(), name='signup'), + path('voucher//', VoucherVerify.as_view(), name='voucher_verify'), + path('voucher/', VoucherVerify.as_view(), name='enter_voucher'), path('place//', place_detail_view, name='place_detail'), path('place/create/', PlaceCreateView.as_view(), name='place_create'), path('place/update//', PlaceUpdateView.as_view(), name='place_edit'), diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 00b03b2..53c9239 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -5,16 +5,24 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy -from django.views.generic.edit import CreateView +from django.views.generic.edit import CreateView, UpdateView from django.views import View from django.http import Http404 -from django.views.generic.edit import UpdateView -from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm +from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm, VoucherVerifyForm from .models import Place, PlaceImage, Voucher # Create your views here. +class VoucherVerify(View): + formclass = VoucherVerifyForm + voucher_form = VoucherVerifyForm() + success_url = reverse_lazy('signin') + fields = ['code'] + + def get(self, request, *args, **kwargs): + return render(request, 'voucher-verify.html') + class SignUpView(CreateView): form_class = ExplorerCreationForm success_url = reverse_lazy('login')