I want to write a website that gives elementary math tasks to its visitors, quite similar to this: http://jsfiddle.net/r4QTQ/
In contrast to the JS example my idea is for the visitor to finish all tasks first, then press a button "check answers" and have all answers marked with a smiley if answer is right or the correct result if visitor's answer is wrong. To this - if I'm right - it's necessary to redirect the visitor's answers and the task-list to a different view. Also I want to use Django templates and CBviews.
I have this view for setting up the math tasks - view.py:
class Plus_im_10erPageView(TemplateView):
form_class = AnswerForm
template_name = 'plus_im_10er.html'
success_html = 'plus_im_10er_check.html'
def tasks(self):
# make a list of math tasks here
return task_list
def get_context_data(self, **kwargs):
context = super(Plus_im_10erPageView, self).get_context_data(**kwargs)
task_list = self.tasks()
context['tasks'] = task_list
self.context = context
return context
def post(self, request):
form = AnswerForm(request.POST)
if form.is_valid():
answers = form.cleaned_data
print(answers)
return render(request, self.success_html, {'answers': answers}
The AnswerForm is a collection of 10 CharFields like this - forms.py:
class AnswerForm(forms.Form):
answer_1 = forms.CharField(label='answer', required=False)
answer_2 = forms.CharField(label='answer', ...
...
Next is the template - plus_im_10er.html:
{% extends 'base.html' %}
{% block content %}
<ul>
<form method="POST">{% csrf_token %}
{% for task in tasks %}
<li>{{ task.0 }} + {{ task.1 }} =
<input type="text" size=2 name="answer_list"
onkeypress="return event.charCode >= 48 && event.charCode <=57">{{ answer }}
</input>
</li>
{% endfor %}
</br>
</br>
<input type="button" onclick="location.href='/plus_im_10er_check/';"
value="Check answers">
</input>
</ul>
{% endblock content %}
This works so far.
What I cannot figure out is how to continue. My idea is to write a second view called Plus_im_10er_checkPageView and a second template called plus_im_10er_check.html but whatever I tried didn't get me anywhere. I spare you my attempts. How would you tackle this?

