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