feature/post-test-answers #23

Merged
s470631 merged 11 commits from feature/post-test-answers into master 2022-01-22 14:19:05 +01:00
6 changed files with 36 additions and 40 deletions
Showing only changes of commit 636f1b3199 - Show all commits

View File

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

View File

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

@ -39,3 +39,4 @@ class PasswordResetConfirmShortcut:
return Response({"detail": cons.PASSWORD_HAS_BEEN_CHANGED}, status=status.HTTP_200_OK)
else:
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 rest_framework import views
from rest_framework import viewsets
@ -11,57 +12,42 @@ from django import template
from django.http import HttpResponseRedirect, HttpResponse
from django.template import loader
from django.template.loader import render_to_string, get_template
register = template.Library()
@register.filter()
def range(min=0):
return range(min)
from django.http import HttpRequest
import requests
def addTest(request):
if request.POST:
# TODO pass test meta do addQuestions view and then create 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
# Instead of context:
#request.session['questNum'] = range(1, 4)
return redirect('addQuestions')
data = request.POST
return addQuestions(request="GET", data_about_test=data)
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:
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):
queryset = Test.objects.all()
serializer_class = TestSerializer
class TestTemplateView(TemplateView):
PASSED = "passed"
FAILED = "failed"