Commit 964825d2 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents d0ed20a4 8b6212cb
...@@ -30,7 +30,7 @@ class MathCaptcha(object): ...@@ -30,7 +30,7 @@ class MathCaptcha(object):
Simple match captcha object. Simple match captcha object.
''' '''
operators = ('+', '-', '*') operators = ('+', '-', '*')
interval = (0, 10) interval = (1, 10)
def __init__(self, question=None): def __init__(self, question=None):
if question is None: if question is None:
...@@ -42,15 +42,17 @@ class MathCaptcha(object): ...@@ -42,15 +42,17 @@ class MathCaptcha(object):
''' '''
Generates random question. Generates random question.
''' '''
operator = choice(self.operators)
first = randint(self.interval[0], self.interval[1]) first = randint(self.interval[0], self.interval[1])
second = randint(self.interval[0], self.interval[1]) second = randint(self.interval[0], self.interval[1])
# We don't want negative answers # We don't want negative answers
if second > first: if operator == '-':
first, second = second, first first += self.interval[1]
return '%d %s %d' % ( return '%d %s %d' % (
first, first,
choice(self.operators), operator,
second second
) )
...@@ -73,8 +75,14 @@ class MathCaptcha(object): ...@@ -73,8 +75,14 @@ class MathCaptcha(object):
''' '''
Validates answer. Validates answer.
''' '''
result = eval(self.question) return self.result == answer
return result == answer
@propery
def result(self):
'''
Returns result.
'''
return eval(self.question)
def checksum_question(question): def checksum_question(question):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment