<commit_before>from django.http import HttpResponse
from django.shortcuts import render

from .forms import FlagForm
from .models import Challenge


def download(req):
    response = HttpResponse(content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=myfile.zip'
    return response


def textBased(request):
    challenges = Challenge.objects.all()
    return render(request, 'challenges/textBased.html', {'challenges': challenges})


def index(request):
    challenges = Challenge.objects.all()
    return render(request, 'challenges/index.html', {'challenges': challenges})


def challenge(request, name):
    chal = Challenge.objects.get(name=name)

    if request.method == 'POST':
        form = FlagForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['flag'] == chal.name:
                pass
    else:
        form = FlagForm()

    return render(request, 'challenges/challenge.html', {'challenge': chal, 'form': form})

    '''
    path=settings.MEDIA_ROOT
    file_list =os.listdir(path)
    return render(request,'challenges/index.html', {'files': file_list})
    



def upload(request):
    if request.method == 'POST' and request.FILES['myfile']:
        myfile = request.FILES['myfile']
        fs = FileSystemStorage()
        filename = fs.save(myfile.name, myfile)
        uploaded_file_url = fs.url(filename)
        return render(request, 'challenges/upload.html', {
            'uploaded_file_url': uploaded_file_url
        })
    return render(request, 'challenges/upload.html')

def upload2(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('/jeopardy')<commit_msg>Added score adding system to challenge view<commit_after>from django.http import HttpResponse
from django.shortcuts import render

from .forms import FlagForm
from .models import Challenge


def download(req):
    response = HttpResponse(content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=myfile.zip'
    return response


def textBased(request):
    challenges = Challenge.objects.all()
    return render(request, 'challenges/textBased.html', {'challenges': challenges})


def index(request):
    challenges = Challenge.objects.all()
    return render(request, 'challenges/index.html', {'challenges': challenges})


def challenge(request, name):
    chal = Challenge.objects.get(name=name)

    if request.method == 'POST':
        form = FlagForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['flag'] == chal.name:
                request.user.userprofile.solved_challenges = chal
    else:
        form = FlagForm()

    return render(request, 'challenges/challenge.html', {'challenge': chal, 'form': form})

    '''
    path=settings.MEDIA_ROOT
    file_list =os.listdir(path)
    return render(request,'challenges/index.html', {'files': file_list})
    



def upload(request):
    if request.method == 'POST' and request.FILES['myfile']:
        myfile = request.FILES['myfile']
        fs = FileSystemStorage()
        filename = fs.save(myfile.name, myfile)
        uploaded_file_url = fs.url(filename)
        return render(request, 'challenges/upload.html', {
            'uploaded_file_url': uploaded_file_url
        })
    return render(request, 'challenges/upload.html')

def upload2(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('/jeopardy')
{'fraction_non_alphanumeric': 0.12510288065843622, 'fraction_numerical': 0.0005486968449931413, 'mean_word_length': 3.279342723004695, 'pattern_counts': {'":': 0, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7568896', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1032, 'n_words': 232}