Added possibility to complete tests

This commit is contained in:
Hubert Jankowski 2022-01-17 18:50:08 +01:00
parent ecad16aa81
commit 636f1b3199
6 changed files with 36 additions and 40 deletions

View File

@ -59,7 +59,8 @@ INSTALLED_APPS = [
"trials", "trials",
"answers", "answers",
"questions", "questions",
"categories" "categories",
"tools"
] ]
# AUTHENTICATION_BACKENDS = ['config.authh.SettingsBackend'] # AUTHENTICATION_BACKENDS = ['config.authh.SettingsBackend']
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -1,13 +1,15 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load filters %}
{% load rest_framework %} {% load rest_framework %}
{% block title %}New Test{% endblock %} {% block title %}New Test{% endblock %}
{% block content %} {% block content %}
<div class="newContainer"> <div class="newContainer">
<form method="post"> <form method="post">
<h1>Add questions</h1> <h1>Add questions</h1>
{% for i in 1|range:4 %} {% for i in number_of_questions|times %}
<h2>Question {{i}}</h2> <h2>Question {{i}}</h2>
<label for="desc">Description: </label> <label for="desc">Description: </label>
<input id="desc" type="text" name="desc"> <input id="desc" type="text" name="desc">
@ -29,7 +31,7 @@
<input id="ans4" type="text" name="ans4"> <input id="ans4" type="text" name="ans4">
<br> <br>
<br> <br>
<label for="category">Category: </label> <label for="category">correct: </label>
<select name="category" id="category"> <select name="category" id="category">
<option value="1">1</option> <option value="1">1</option>
<option value="2">2</option> <option value="2">2</option>

View File

View File

@ -0,0 +1,6 @@
from django import template
register = template.Library()
@register.filter(name='times')
def times(number):
return range(number)

View File

@ -38,4 +38,5 @@ class PasswordResetConfirmShortcut:
if serializer.is_valid(): if serializer.is_valid():
return Response({"detail": cons.PASSWORD_HAS_BEEN_CHANGED}, status=status.HTTP_200_OK) return Response({"detail": cons.PASSWORD_HAS_BEEN_CHANGED}, status=status.HTTP_200_OK)
else: else:
return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)

View File

@ -1,3 +1,4 @@
import requests
from django.views.generic import TemplateView from django.views.generic import TemplateView
from rest_framework import views from rest_framework import views
from rest_framework import viewsets from rest_framework import viewsets
@ -11,57 +12,42 @@ from django import template
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.template import loader from django.template import loader
from django.template.loader import render_to_string, get_template from django.template.loader import render_to_string, get_template
from django.http import HttpRequest
register = template.Library() import requests
@register.filter()
def range(min=0):
return range(min)
def addTest(request): def addTest(request):
if request.POST: if request.POST:
# TODO pass test meta do addQuestions view and then create object? data = request.POST
# form = RegistrationForm(request.POST) return addQuestions(request="GET", data_about_test=data)
# if form.is_valid():
# User.objects.create(
# email=form.cleaned_data["email"],
# first_name=form.cleaned_data["first_name"],
# last_name=form.cleaned_data["last_name"],
# password=form.cleaned_data["password1"]
# )
# return redirect('register_success')
# else:
# context['registration_form'] = form
# Instead of context:
#request.session['questNum'] = range(1, 4)
return redirect('addQuestions')
return render(request, 'createTest.html') return render(request, 'createTest.html')
def addQuestions(request): def addQuestions(request, data_about_test):
number_of_question = 0
if request == "GET":
for key, value in data_about_test.items():
if key == "questions":
number_of_question = int(value)
context = {
"number_of_questions": number_of_question
}
template_name = "addQuestions.html"
template = get_template(template_name)
return HttpResponse(template.render(context))
# return render(response, 'addQuestions.html')
if request.POST: if request.POST:
pass pass
# TODO create test object?
# form = RegistrationForm(request.POST)
# if form.is_valid():
# User.objects.create(
# email=form.cleaned_data["email"],
# first_name=form.cleaned_data["first_name"],
# last_name=form.cleaned_data["last_name"],
# password=form.cleaned_data["password1"]
# )
# return redirect('register_success')
# else:
# context['registration_form'] = form
return render(request, 'addQuestions.html')
class TestModelViewSet(viewsets.ModelViewSet): class TestModelViewSet(viewsets.ModelViewSet):
queryset = Test.objects.all() queryset = Test.objects.all()
serializer_class = TestSerializer serializer_class = TestSerializer
class TestTemplateView(TemplateView): class TestTemplateView(TemplateView):
PASSED = "passed" PASSED = "passed"
FAILED = "failed" FAILED = "failed"