Merge branch 'feature/post-test-answers' of https://git.wmi.amu.edu.pl/s470629/SOITA into feature/post-test-answers
This commit is contained in:
commit
ecad16aa81
46
templates/addQuestions.html
Normal file
46
templates/addQuestions.html
Normal file
@ -0,0 +1,46 @@
|
||||
{% extends "base.html" %}
|
||||
{% 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 %}
|
||||
<h2>Question {{i}}</h2>
|
||||
<label for="desc">Description: </label>
|
||||
<input id="desc" type="text" name="desc">
|
||||
<br>
|
||||
<br>
|
||||
<label for="ans1">Answer 1: </label>
|
||||
<input id="ans1" type="text" name="ans1">
|
||||
<br>
|
||||
<br>
|
||||
<label for="ans2">Answer 2: </label>
|
||||
<input id="ans2" type="text" name="ans2">
|
||||
<br>
|
||||
<br>
|
||||
<label for="ans3">Answer 3: </label>
|
||||
<input id="ans3" type="text" name="ans3">
|
||||
<br>
|
||||
<br>
|
||||
<label for="ans4">Answer 4: </label>
|
||||
<input id="ans4" type="text" name="ans4">
|
||||
<br>
|
||||
<br>
|
||||
<label for="category">Category: </label>
|
||||
<select name="category" id="category">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
</select>
|
||||
<br>
|
||||
<br>
|
||||
{% endfor %}
|
||||
<input type="submit" value="Add questions">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<body>
|
||||
<div class="sidenav">
|
||||
<a href="/home">Home</a>
|
||||
<a href="/test/create">Create test</a>
|
||||
<a href="{% url 'newTest' %}">Create test</a>
|
||||
<a href="/users/tests">Your tests</a>
|
||||
<p>Categories</p>
|
||||
<a href="/category/JezykPolski">Język polski</a>
|
||||
|
41
templates/createTest.html
Normal file
41
templates/createTest.html
Normal file
@ -0,0 +1,41 @@
|
||||
{% extends "base.html" %}
|
||||
{% load rest_framework %}
|
||||
|
||||
{% block title %}New Test{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="newContainer">
|
||||
<form method="post">
|
||||
<h1>Create test</h1>
|
||||
<label for="name">Name: </label>
|
||||
<input id="name" type="text" name="name" value="New test">
|
||||
<br>
|
||||
<br>
|
||||
<label for="category">Category: </label>
|
||||
<select name="category" id="category">
|
||||
<option value="JezykPolski">Język Polski</option>
|
||||
<option value="JezykAngielski">Język Angielski</option>
|
||||
<option value="JezykNiemiecki">Język Niemiecki</option>
|
||||
<option value="Matematyka">Matematyka</option>
|
||||
<option value="Informatyka">Informatyka</option>
|
||||
<option value="Fizyka">Fizyka</option>
|
||||
<option value="Chemia">Chemia</option>
|
||||
<option value="Biologia">Biologia</option>
|
||||
<option value="Geografia">Geografia</option>
|
||||
<option value="Historia">Historia</option>
|
||||
</select>
|
||||
<br>
|
||||
<br>
|
||||
<label for="questions">Number of questions: </label>
|
||||
<input id="questions" type="number" name="questions" value="10">
|
||||
<br>
|
||||
<br>
|
||||
<label for="passing">Passing score: </label>
|
||||
<input id="passing" type="number" name="passing" value="5">
|
||||
<br>
|
||||
<br>
|
||||
<input type="submit" value="Add questions">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -4,7 +4,7 @@ from rest_framework.routers import DefaultRouter
|
||||
from trials.views import TestModelViewSet
|
||||
from trials.views import TestTemplateView
|
||||
from trials.views import TestValidateAPIView
|
||||
from trials.views import TestResultView
|
||||
from trials.views import TestResultView, addTest, addQuestions
|
||||
|
||||
router = DefaultRouter(trailing_slash=False)
|
||||
router.register("items", TestModelViewSet)
|
||||
@ -12,7 +12,9 @@ router.register("items", TestModelViewSet)
|
||||
urlpatterns = [
|
||||
path('<int:test_id>/show', TestTemplateView.as_view()),
|
||||
path('<int:test_id>/mark', TestValidateAPIView.as_view()),
|
||||
path('<int:test_id>/result', TestResultView.as_view())
|
||||
path('<int:test_id>/result', TestResultView.as_view()),
|
||||
path('add/test', addTest, name="newTest"),
|
||||
path('add/questions', addQuestions, name="addQuestions")
|
||||
]
|
||||
|
||||
urlpatterns += router.urls
|
||||
|
@ -6,10 +6,57 @@ from rest_framework.response import Response
|
||||
from trials.models import Test
|
||||
from trials.serializers import TestSerializer
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render, redirect
|
||||
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)
|
||||
|
||||
|
||||
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')
|
||||
return render(request, 'createTest.html')
|
||||
|
||||
|
||||
def addQuestions(request):
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user