Added input field to the signup form and removed crap.
This commit is contained in:
parent
8cbb1baf27
commit
57c0889c4e
@ -7,15 +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
|
||||||
fields = ('username', 'email')
|
fields = ('username', 'email')
|
||||||
|
voucher = forms.CharField(max_length=10)
|
||||||
|
|
||||||
class ExplorerChangeForm(UserChangeForm):
|
class ExplorerChangeForm(UserChangeForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from .views import (
|
from .views import (
|
||||||
hello_world,
|
hello_world,
|
||||||
VoucherVerifyView,
|
|
||||||
place_detail_view,
|
place_detail_view,
|
||||||
place_list_view,
|
place_list_view,
|
||||||
SignUpView,
|
SignUpView,
|
||||||
@ -11,7 +10,6 @@ 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('voucher/', VoucherVerifyView.as_view(), name='enter_voucher'),
|
|
||||||
path('signup/', SignUpView.as_view(), name='signup'),
|
path('signup/', SignUpView.as_view(), name='signup'),
|
||||||
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'),
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
''' Django views. '''
|
''' Django views. '''
|
||||||
|
|
||||||
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, UpdateView
|
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 .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm, VoucherVerifyForm
|
from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm
|
||||||
from .models import Place, PlaceImage, Voucher
|
from .models import Place, PlaceImage, Voucher
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
'''
|
||||||
class VoucherVerifyView(View):
|
class VoucherVerifyView(View):
|
||||||
formclass = VoucherVerifyForm
|
formclass = VoucherVerifyForm
|
||||||
fields = ['code']
|
fields = ['code']
|
||||||
@ -23,12 +23,11 @@ class VoucherVerifyView(View):
|
|||||||
return render(request, 'voucher-verify.html', {'voucher_form': voucher_form})
|
return render(request, 'voucher-verify.html', {'voucher_form': voucher_form})
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
voucher_form = VoucherVerifyForm(request.POST)
|
voucher_form = VoucherVerifyForm(request.POST)
|
||||||
|
print(voucher_form.values('code'))
|
||||||
if voucher_form.is_valid():
|
if voucher_form.is_valid():
|
||||||
# Compare voucher from form with available vouchers in Voucher.
|
# Compare voucher from form with available vouchers in Voucher.
|
||||||
for voucher in Voucher.objects.all():
|
for voucher in Voucher.objects.all():
|
||||||
print(voucher.code)
|
|
||||||
if voucher.code == voucher_form.cleaned_data.get('code'):
|
if voucher.code == voucher_form.cleaned_data.get('code'):
|
||||||
kwargs_to_pass = {
|
kwargs_to_pass = {
|
||||||
'voucher_pk': voucher.pk
|
'voucher_pk': voucher.pk
|
||||||
@ -38,6 +37,7 @@ class VoucherVerifyView(View):
|
|||||||
return redirect(reverse_lazy('enter_voucher'))
|
return redirect(reverse_lazy('enter_voucher'))
|
||||||
else:
|
else:
|
||||||
return redirect(reverse_lazy('enter_voucher'))
|
return redirect(reverse_lazy('enter_voucher'))
|
||||||
|
'''
|
||||||
|
|
||||||
class SignUpView(CreateView):
|
class SignUpView(CreateView):
|
||||||
form_class = ExplorerCreationForm
|
form_class = ExplorerCreationForm
|
||||||
|
Loading…
Reference in New Issue
Block a user