Some random changes

This commit is contained in:
Piotr Kopycki 2022-01-12 10:50:34 +01:00
parent 723e36c36a
commit 1655ffa088
8 changed files with 154 additions and 31 deletions

View File

@ -192,3 +192,28 @@ input[type=checkbox]{
}
background-color:#FF0B7E
.resultContainer{
border-radius: 25px;
border: 2px solid #FF0B7E;
padding: 20px;
width: 800px;
height: 1000px;
padding-bottom: 15px;
}
.resultImage{
}
.resultMsg {
font-weight: bold;
font-size: 24px;
}
.resultScore {
font-weight: bold;
font-size: 20px;
}
.resultText {
}

View File

@ -38,6 +38,8 @@
<!-- </style>-->
<title>SOITA | {% block title %}{% endblock %}</title>
<meta name="description" content="{% block description %}{% endblock %}">
{% block additional_head %}
{% endblock %}
</head>
<body>

View File

@ -1,8 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% extends "base.html" %}
{% block title %}{{ test.name }}{% endblock %}
{% block additional_head %}
<meta charset="UTF-8">
<title>{{ test.name }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
@ -18,31 +19,31 @@
}
</style>
</head>
<body>
<div class="card">
<div class="card-body test_body">
<div class="card-header test_title">
{{ test.name }}
{% endblock %}
{% block content %}
<div class="card">
<div class="card-body test_body">
<div class="card-header test_title">
{{ test.name }}
</div>
{% for question in test.questions.all %}
<div class="question_title">
{{ question.description }}
</div>
<div class="list-group">
{% for answer in question.answers.all %}
<label class="list-group-item">
<input class="form-check-input me-1" type="radio" name={{ question.id }} value="">
{{ answer.description }}
</label>
{% endfor %}
</div>
{% endfor %}
</div>
{% for question in test.questions.all %}
<div class="question_title">
{{ question.description }}
</div>
{% endblock %}
<div class="list-group">
{% for answer in question.answers.all %}
<label class="list-group-item">
<input class="form-check-input me-1" type="radio" name={{ question.id }} value="">
{{ answer.description }}
</label>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ test.name }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
.test_title {
font-size: 40px;
}
.test_body {
width: 50%;
}
.question_title {
font-size: 20px;
}
</style>
</head>
<body>
<div class="card">
<div class="card-body test_body">
<div class="card-header test_title">
{{ test.name }}
</div>
{% for question in test.questions.all %}
<div class="question_title">
{{ question.description }}
</div>
<div class="list-group">
{% for answer in question.answers.all %}
<label class="list-group-item">
<input class="form-check-input me-1" type="radio" name={{ question.id }} value="">
{{ answer.description }}
</label>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</body>
</html>

View File

@ -17,7 +17,7 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus volutpat scelerisque tortor, id sodales leo finibus id. Vivamus id viverra nunc, ac faucibus metus. Nulla a mauris imperdiet sapien lobortis dapibus. Quisque ornare posuere pulvinar.
</div>
<div class="mainTestMeta">
Passing score: {{test.passing_score}}
Passing score: {{test.passing_score}} / Questions: {{test.questions|length}}
</div>
<button><a href="/tests/{{test.id}}/show">Start</a></button>
</div>

19
templates/result.html Normal file
View File

@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block title %}Test result{% endblock %}
{% block content %}
<div class="resultContainer ">
<img class="resultImage" src="http://kmit.in/emagazine/wp-content/uploads/2018/02/karnataka-results.jpg" alt="Card image cap">
<div class="resultBody">
<h5 class="resultMsg">Quite good! All the best for next quiz!</h5>
<h5 class="resultScore">Score: 3</h5>
<p class="resultText">Percentage: 60%</p>
<p class="resultText">Correct answers: 3</p>
<p class="resultText">Incorrect answers: 2</p>
<p class="resultText">Total questions: 5</p>
</div>
</div>
{% endblock %}

View File

@ -4,13 +4,15 @@ 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
router = DefaultRouter(trailing_slash=False)
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>/mark', TestValidateAPIView.as_view()),
path('<int:test_id>/result', TestResultView.as_view())
]
urlpatterns += router.urls

View File

@ -27,6 +27,28 @@ class TestTemplateView(TemplateView):
return context
def testView(request):
permission_classes = []
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
context = {}
if request.POST:
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
else:
context["test"] = Test.objects.all().filter(id=test_id).prefetch_related("questions__answers").first()
return render(request, 'generic_test.html', context)
class TestValidateAPIView(views.APIView):
PASSED = "passed"
FAILED = "failed"
@ -48,3 +70,7 @@ class TestValidateAPIView(views.APIView):
"status": self.PASSED.get(status, self.UNKNOWN),
"points": score
})
class TestResultView(TemplateView):
permission_classes = []
template_name = settings.BASE_DIR + f"/templates/result.html"