misc cleanup
parent
6b4aafe2b2
commit
c58e5bfece
|
@ -37,7 +37,7 @@ def _new_random(subject):
|
|||
Returns: subject_id + 'z' +
|
||||
md5 hexdigest of subject's surname, nextrun date, and a random number
|
||||
"""
|
||||
return "%dz%s" % (subject.id, md5(subject.surname + str(subject.nextrun) + hex(random.randint(1,999999))).hexdigest()[:6])
|
||||
return "%dz%s" % (subject.id, md5(bytes(subject.surname + str(subject.nextrun) + hex(random.randint(1,999999)), 'utf-8')).hexdigest()[:6])
|
||||
|
||||
|
||||
def _new_runinfo(subject, questionset):
|
||||
|
|
|
@ -38,7 +38,7 @@ def _load_template_source(template_name, template_dirs=None):
|
|||
error_msg = "Tried %s" % tried
|
||||
else:
|
||||
error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
|
||||
raise TemplateDoesNotExist, error_msg
|
||||
raise TemplateDoesNotExist(error_msg)
|
||||
|
||||
def load_template_source(template_name, template_dirs=None):
|
||||
"""Assuming the current language is German.
|
||||
|
|
|
@ -10,6 +10,17 @@ try:
|
|||
except AttributeError:
|
||||
use_session = False
|
||||
|
||||
def cmp(x, y):
|
||||
"""
|
||||
Replacement for built-in function cmp that was removed in Python 3
|
||||
|
||||
Compare the two objects x and y and return an integer according to
|
||||
the outcome. The return value is negative if x < y, zero if x == y
|
||||
and strictly positive if x > y.
|
||||
"""
|
||||
|
||||
return (x > y) - (x < y)
|
||||
|
||||
def split_numal(val):
|
||||
"""Split, for example, '1a' into (1, 'a')
|
||||
>>> split_numal("11a")
|
||||
|
|
|
@ -90,15 +90,15 @@ def redirect_to_qs(runinfo, request=None):
|
|||
# skip questionsets that don't pass
|
||||
if not questionset_satisfies_checks(runinfo.questionset, runinfo):
|
||||
|
||||
next = runinfo.questionset.next()
|
||||
nxt = next(runinfo.questionset)
|
||||
|
||||
while next and not questionset_satisfies_checks(next, runinfo):
|
||||
next = next.next()
|
||||
while nxt and not questionset_satisfies_checks(nxt, runinfo):
|
||||
nxt = next(nxt)
|
||||
|
||||
runinfo.questionset = next
|
||||
runinfo.questionset = nxt
|
||||
runinfo.save()
|
||||
|
||||
hasquestionset = bool(next)
|
||||
hasquestionset = bool(nxt)
|
||||
else:
|
||||
hasquestionset = True
|
||||
|
||||
|
@ -325,15 +325,15 @@ def questionnaire(request, runcode=None, qs=None):
|
|||
|
||||
questionset_done.send(sender=None, runinfo=runinfo, questionset=questionset)
|
||||
|
||||
next = questionset.next()
|
||||
while next and not questionset_satisfies_checks(next, runinfo):
|
||||
next = next.next()
|
||||
runinfo.questionset = next
|
||||
nxt = next(questionset)
|
||||
while nxt and not questionset_satisfies_checks(nxt, runinfo):
|
||||
nxt = next(nxt)
|
||||
runinfo.questionset = nxt
|
||||
runinfo.save()
|
||||
if use_session:
|
||||
request.session['prev_runcode'] = runinfo.random
|
||||
|
||||
if next is None: # we are finished
|
||||
if nxt is None: # we are finished
|
||||
return finish_questionnaire(request, runinfo, questionnaire)
|
||||
|
||||
commit()
|
||||
|
@ -543,19 +543,19 @@ def show_questionnaire(request, runinfo, errors={}):
|
|||
return r
|
||||
|
||||
|
||||
def set_language(request, runinfo=None, next=None):
|
||||
def set_language(request, runinfo=None, nxt=None):
|
||||
"""
|
||||
Change the language, save it to runinfo if provided, and
|
||||
redirect to the provided URL (or the last URL).
|
||||
Can also be used by a url handler, w/o runinfo & next.
|
||||
"""
|
||||
if not next:
|
||||
next = request.GET.get('next', request.POST.get('next', None))
|
||||
if not next:
|
||||
next = request.META.get('HTTP_REFERER', None)
|
||||
if not next:
|
||||
next = '/'
|
||||
response = HttpResponseRedirect(next)
|
||||
if not nxt:
|
||||
nxt = request.GET.get('next', request.POST.get('next', None))
|
||||
if not nxt:
|
||||
nxt = request.META.get('HTTP_REFERER', None)
|
||||
if not nxt:
|
||||
nxt = '/'
|
||||
response = HttpResponseRedirect(nxt)
|
||||
response['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT"
|
||||
if request.method == 'GET':
|
||||
lang_code = request.GET.get('lang', None)
|
||||
|
@ -604,7 +604,7 @@ def generate_run(request, questionnaire_id, subject_id=None, context={}):
|
|||
# str_to_hash = "".join(map(lambda i: chr(random.randint(0, 255)), range(16)))
|
||||
str_to_hash = str(uuid4())
|
||||
str_to_hash += settings.SECRET_KEY
|
||||
key = md5(str_to_hash).hexdigest()
|
||||
key = md5(bytes(str_to_hash, 'utf-8')).hexdigest()
|
||||
landing = context.get('landing', None)
|
||||
r = Run.objects.create(runid=key)
|
||||
run = RunInfo.objects.create(subject=su, random=key, run=r, questionset=qs, landing=landing)
|
||||
|
|
Loading…
Reference in New Issue