<commit_before># -*- coding: utf-8 -*-

from django.contrib.auth.decorators import login_required

from core.common import prtr

from levels.models import Level, Score, Attempt

from django.http import HttpResponseRedirect, Http404

@login_required
def index(request):
	c = {}
	try:
		end_level = Level.objects.latest('pk')
	except Level.DoesNotExist:
		raise Http404


	from core.models import Config
	try:
		config = Config.objects.get(pk=1)
	except Config.DoesNotExist:
		raise Http404
	c['config'] = config
	if not config.active:
		return prtr ("closed.html", c, request)

	user = request.user

	try:
		score = Score.objects.get(user=user)
	except:
		score = Score(user=user, max_level=0)

	
	if score.max_level == end_level.pk:
		return HttpResponseRedirect('/done/')

	level = score.max_level + 1
	level = Level.objects.get(pk=level)

	if request.method == "POST":
		answer = unicode(request.POST['answer']).upper()
		attempt = Attempt (user=user, level=level, answer=answer)
		if not level.multianswer:
			if answer == unicode(level.answer).upper():
				score.max_level += 1
				score.save()
				attempt.correct = True
				attempt.save ()
				return HttpResponseRedirect('/')
			else:
				attempt.correct = False
				attempt.save ()
				c['error'] = 'Feil svar! Prøv igjen :-D'
		else:
			for level_answer in unicode(level.answer).split('||'):
				if answer == unicode(level_answer).upper():
					score.max_level += 1
					score.save()
					attempt.correct = True
					attempt.save ()
					return HttpResponseRedirect('/')
			c['error'] = 'Feil svar! Prøv igjen :-D'
			attempt.correct = False
			attempt.save ()
			
	c['level'] = level

	return prtr("levels.html", c, request)

@login_required
def done(request):
	c = {}

	try:
		score = Score.objects.get(user=request.user)
	except:
		return HttpResponseRedirect('/')
		

	end_level = Level.objects.latest('pk')
	if score.max_level == end_level.pk:
			score = Score.objects.get(user=request.user)
			c['score'] = score

			return prtr ("done.html", c, request)
	else:
		return HttpResponseRedirect('/')<commit_msg>removed unicode casting, as python3 is utf-8 only<commit_after># -*- coding: utf-8 -*-

from django.contrib.auth.decorators import login_required

from core.common import prtr

from levels.models import Level, Score, Attempt

from django.http import HttpResponseRedirect, Http404

@login_required
def index(request):
    c = {}
    try:
        end_level = Level.objects.latest('pk')
    except Level.DoesNotExist:
        raise Http404


    from core.models import Config
    try:
        config = Config.objects.get(pk=1)
    except Config.DoesNotExist:
        raise Http404
    c['config'] = config
    if not config.active:
        return prtr ("closed.html", c, request)

    user = request.user

    try:
        score = Score.objects.get(user=user)
    except:
        score = Score(user=user, max_level=0)

    
    if score.max_level == end_level.pk:
        return HttpResponseRedirect('/done/')

    level = score.max_level + 1
    level = Level.objects.get(pk=level)

    if request.method == "POST":
        answer = request.POST['answer'].upper()
        attempt = Attempt (user=user, level=level, answer=answer)
        if not level.multianswer:
            if answer == level.answer.upper():
                score.max_level += 1
                score.save()
                attempt.correct = True
                attempt.save ()
                return HttpResponseRedirect('/')
            else:
                attempt.correct = False
                attempt.save ()
                c['error'] = 'Feil svar! Prøv igjen :-D'
        else:
            for level_answer in level.answer.split('||'):
                if answer == level_answer.upper():
                    score.max_level += 1
                    score.save()
                    attempt.correct = True
                    attempt.save ()
                    return HttpResponseRedirect('/')
            c['error'] = 'Feil svar! Prøv igjen :-D'
            attempt.correct = False
            attempt.save ()
            
    c['level'] = level

    return prtr("levels.html", c, request)

@login_required
def done(request):
    c = {}

    try:
        score = Score.objects.get(user=request.user)
    except:
        return HttpResponseRedirect('/')
        

    end_level = Level.objects.latest('pk')
    if score.max_level == end_level.pk:
            score = Score.objects.get(user=request.user)
            c['score'] = score

            return prtr ("done.html", c, request)
    else:
        return HttpResponseRedirect('/')
{'fraction_non_alphanumeric': 0.12382821015914541, 'fraction_numerical': 0.00697623719206453, 'mean_word_length': 2.4548192771084336, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '604080', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1362, 'n_words': 336}