voucher_form.code won't match voucher.code :-(
This commit is contained in:
parent
cd0df727cc
commit
8cbb1baf27
@ -1,7 +1,7 @@
|
||||
from django.urls import path
|
||||
from .views import (
|
||||
hello_world,
|
||||
VoucherVerify,
|
||||
VoucherVerifyView,
|
||||
place_detail_view,
|
||||
place_list_view,
|
||||
SignUpView,
|
||||
@ -11,9 +11,8 @@ 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('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/create/', PlaceCreateView.as_view(), name='place_create'),
|
||||
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
|
||||
|
@ -14,16 +14,31 @@ from .models import Place, PlaceImage, Voucher
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class VoucherVerify(View):
|
||||
class VoucherVerifyView(View):
|
||||
formclass = VoucherVerifyForm
|
||||
voucher_form = VoucherVerifyForm()
|
||||
success_url = reverse_lazy('signin')
|
||||
fields = ['code']
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
voucher_form = VoucherVerifyForm()
|
||||
return render(request, 'voucher-verify.html', {'voucher_form': voucher_form})
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
voucher_form = VoucherVerifyForm(request.POST)
|
||||
|
||||
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
|
||||
}
|
||||
return redirect(reverse_lazy('signup'), kwargs=kwargs_to_pass)
|
||||
else:
|
||||
return redirect(reverse_lazy('enter_voucher'))
|
||||
else:
|
||||
return redirect(reverse_lazy('enter_voucher'))
|
||||
|
||||
class SignUpView(CreateView):
|
||||
form_class = ExplorerCreationForm
|
||||
success_url = reverse_lazy('login')
|
||||
|
Loading…
Reference in New Issue
Block a user