Building a voucher-verify form.

This commit is contained in:
Marcus Scholz 2020-08-01 19:00:11 +02:00
parent ea9b46961b
commit 9bd85aba7a
4 changed files with 34 additions and 3 deletions

View File

@ -7,6 +7,11 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import Explorer, Place, PlaceImage, Voucher from .models import Explorer, Place, PlaceImage, Voucher
class VoucherVerifyForm(forms.ModelForm):
class Meta:
model = Voucher
fields = ['code']
class ExplorerCreationForm(UserCreationForm): class ExplorerCreationForm(UserCreationForm):
class Meta: class Meta:
model = Explorer model = Explorer

View File

@ -0,0 +1,15 @@
{% extends 'global.html'%}
{% load static %}
# {% block title %}Voucher-Überprüfung{% endblock %}
{% block maincontent %}
<h2>Voucher-Überprüfung</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
{% endblock maincontent %}

View File

@ -1,6 +1,7 @@
from django.urls import path from django.urls import path
from .views import ( from .views import (
hello_world, hello_world,
VoucherVerify,
place_detail_view, place_detail_view,
place_list_view, place_list_view,
SignUpView, SignUpView,
@ -11,6 +12,8 @@ from .views import (
urlpatterns = [ urlpatterns = [
path('hello_world/', hello_world), # You know what this is :P path('hello_world/', hello_world), # You know what this is :P
path('signup/', SignUpView.as_view(), name='signup'), path('signup/', SignUpView.as_view(), name='signup'),
path('voucher/<slug:code>/', VoucherVerify.as_view(), name='voucher_verify'),
path('voucher/', VoucherVerify.as_view(), name='enter_voucher'),
path('place/<int:pk>/', place_detail_view, name='place_detail'), path('place/<int:pk>/', place_detail_view, name='place_detail'),
path('place/create/', PlaceCreateView.as_view(), name='place_create'), path('place/create/', PlaceCreateView.as_view(), name='place_create'),
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'), path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),

View File

@ -5,16 +5,24 @@
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy 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.views import View
from django.http import Http404 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 from .models import Place, PlaceImage, Voucher
# Create your views here. # 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): class SignUpView(CreateView):
form_class = ExplorerCreationForm form_class = ExplorerCreationForm
success_url = reverse_lazy('login') success_url = reverse_lazy('login')