widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #17786
Re: [Merge] lp:~widelands-dev/widelands-website/quiz_captcha into lp:widelands-website
I tried about 8 times and did not manage to answer any of the questions correctly. Is this case-sensitive?
Diff comments:
>
> === added file 'quiz_captcha/fields.py'
> --- quiz_captcha/fields.py 1970-01-01 00:00:00 +0000
> +++ quiz_captcha/fields.py 2019-06-23 18:35:44 +0000
> @@ -0,0 +1,42 @@
> +from django import forms
> +from django.shortcuts import get_object_or_404
> +from django.core.exceptions import ValidationError
> +from quiz_captcha.models import Quiz
> +
> +
> +class QuizField(forms.CharField):
> + """Extendet CharField with a Quiz object."""
Extendet -> Extended
> +
> + quest = Quiz()
> +
> + def __init__(self, *args, **kwargs):
> + super(QuizField, self).__init__(
> + label=QuizField.quest.question, **kwargs)
> +
> + def init_values(self, *args, **kwargs):
> + """Set a new label and quiz for the field."""
> +
> + try:
> + if not QuizField.quest:
> + # There was no quest set yet
> + QuizField.quest = Quiz.objects.get_random()
> + else:
> + # A quest was set, exclude it
> + QuizField.quest = Quiz.objects.get_random(
> + exclude_pk=QuizField.quest.pk)
> +
> + self.label = QuizField.quest.question
> + except:
> + # No Quizz available or other errors
Quizz -> Quiz
> + # Maybe this could be better implemented by raising ValidationError
> + # but i couldn't figure it out
> + self.label = ''
> +
> + def validate(self, value):
> + # Run default validation, e.g. 'This field is required'
> + super(QuizField, self).validate(value)
> +
> + # Validate the answer against the quest object
> + if value != QuizField.quest.answer:
> + raise ValidationError(
> + 'Your answer was wrong. Please try to answer again.')
--
https://code.launchpad.net/~widelands-dev/widelands-website/quiz_captcha/+merge/369213
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/quiz_captcha into lp:widelands-website.
References