Index: trunk/quiz/templates/verb_result.html =================================================================== diff -u --- trunk/quiz/templates/verb_result.html (revision 0) +++ trunk/quiz/templates/verb_result.html (revision 8) @@ -0,0 +1,18 @@ + + +quiz verb : {{ form.verb.value }} result +
+ {% csrf_token %} + {% for field in form.visible_fields %} +
+ {{ field.errors }} +
  • {{ field.label_tag }} {{ field }}
  • + {% if field.help_text %} +

    {{ field.help_text|safe }}

    + {% endif %} +
    + {% endfor %} + +
    + + Index: trunk/quiz/templates/verb.html =================================================================== diff -u --- trunk/quiz/templates/verb.html (revision 0) +++ trunk/quiz/templates/verb.html (revision 8) @@ -0,0 +1,10 @@ + + +quiz verb : {{ form.verb.value }} +
    + {% csrf_token %} + {{ form.as_ul }} + +
    + + Index: trunk/quiz/quiz/settings.py =================================================================== diff -u -r7 -r8 --- trunk/quiz/quiz/settings.py (.../settings.py) (revision 7) +++ trunk/quiz/quiz/settings.py (.../settings.py) (revision 8) @@ -14,9 +14,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -print("BASE_DIR=", BASE_DIR) - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ Index: trunk/quiz/templates/home.html =================================================================== diff -u -r6 -r8 --- trunk/quiz/templates/home.html (.../home.html) (revision 6) +++ trunk/quiz/templates/home.html (.../home.html) (revision 8) @@ -1,8 +1,7 @@ -{% load static %} - - - Quiz - - +{% extends "base.html" %} + +{% block title %}Quiz{% endblock title %} + +{% block content %}

    Homepage

    +{% endblock content %} Index: trunk/quiz/templates/base.html =================================================================== diff -u --- trunk/quiz/templates/base.html (revision 0) +++ trunk/quiz/templates/base.html (revision 8) @@ -0,0 +1,13 @@ +{% load static %} + + + {% block title %}{% endblock title %} + + + + Home | Verb + + +{% block content %} +{% endblock content %} + Index: trunk/quiz/quizapp/urls.py =================================================================== diff -u -r6 -r8 --- trunk/quiz/quizapp/urls.py (.../urls.py) (revision 6) +++ trunk/quiz/quizapp/urls.py (.../urls.py) (revision 8) @@ -1,6 +1,8 @@ from django.urls import path -from .views import HomePageView +from .views import HomePageView, VerbQuizView, VerbQuizResultView urlpatterns = [ - path('', HomePageView.as_view(), name='home') + path('', HomePageView.as_view(), name='home'), + path('verb', VerbQuizView.as_view(), name='verb'), + path('verb_result', VerbQuizResultView.as_view(), name='verb_result'), ] Index: trunk/quiz/quizapp/views.py =================================================================== diff -u -r6 -r8 --- trunk/quiz/quizapp/views.py (.../views.py) (revision 6) +++ trunk/quiz/quizapp/views.py (.../views.py) (revision 8) @@ -1,6 +1,75 @@ from django.shortcuts import render from django.views.generic import TemplateView +from django.views.generic.edit import FormView +from django.http import HttpResponse, HttpResponseRedirect +from .forms import VerbQuizForm, VerbQuizResultForm + +VERB_DB = { + 'arise': { 'simple_past':'arose', 'past_participle':'arisen', 'translation':'survenir' }, + 'awake': { 'simple_past':'awoke', 'past_participle':'awoken', 'translation':'se reveiller' }, + 'beat': { 'simple_past':'beat', 'past_participle':'beaten', 'translation':'battre' }, + } + # Create your views here. class HomePageView(TemplateView): template_name = 'home.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + num_visits = self.request.session.get('num_visits', 0) + self.request.session['num_visits'] = num_visits + 1 + context['info'] = "visit = " + str(num_visits) + print("info=", context['info']) + return context + + +class VerbQuizView(FormView): + template_name = 'verb.html' + form_class = VerbQuizForm + success_url = '/verb' + initial = {'verb':'arise'} + + def form_valid(self, form): + print("checking if form is valid") + return super().form_valid(form) + + def get(self, request, *args, **kwargs): + form = self.form_class(initial=self.initial) + print(request.session.get('num_visits', 0)) + return render(request, self.template_name, {'form': form}) + + def post(self, request, *args, **kwargs): + form = self.form_class(request.POST) + if form.is_valid(): + # + print(form.cleaned_data) + return HttpResponseRedirect("/verb_result") + + return render(request, self.template_name, {'form': form}) + +class VerbQuizResultView(FormView): + template_name = 'verb_result.html' + form_class = VerbQuizResultForm + success_url = '/verb_result' + initial = {'verb':'arise'} + + def form_valid(self, form): + print("checking if form is valid") + return super().form_valid(form) + + + def get(self, request, *args, **kwargs): + form = self.form_class(initial=self.initial) + print(request.session.get('num_visits', 0)) + return render(request, self.template_name, {'form': form}) + + def post(self, request, *args, **kwargs): + form = self.form_class(request.POST) + if form.is_valid(): + # + print(form.cleaned_data) + return HttpResponseRedirect('/verb') + + return HttpResponseRedirect('/verb') + # return render(request, self.template_name, {'form': form}) Index: trunk/quiz/db.sqlite3 =================================================================== diff -u -r6 -r8 Binary files differ Index: trunk/quiz/quizapp/forms.py =================================================================== diff -u --- trunk/quiz/quizapp/forms.py (revision 0) +++ trunk/quiz/quizapp/forms.py (revision 8) @@ -0,0 +1,13 @@ +from django import forms + +class VerbQuizForm(forms.Form): + verb = forms.CharField(widget=forms.HiddenInput()) + simple_past = forms.CharField(label='Preterit', max_length=100) + past_participle = forms.CharField(label='Participe passe', max_length=100) + translation = forms.CharField(label='Traduction', max_length=100) + +class VerbQuizResultForm(forms.Form): + verb = forms.CharField(widget=forms.HiddenInput()) + simple_past = forms.CharField(label='Preterit', max_length=100) + past_participle = forms.CharField(label='Participe passe', max_length=100) + translation = forms.CharField(label='Traduction', max_length=100)