From 1655ffa088a5db5c2284205615ffdb57aa9a525a Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Wed, 12 Jan 2022 10:50:34 +0100 Subject: [PATCH] Some random changes --- static/style.css | 25 +++++++++++++++ templates/base.html | 2 ++ templates/generic_test.html | 59 ++++++++++++++++++----------------- templates/generic_test_2.html | 48 ++++++++++++++++++++++++++++ templates/home.html | 2 +- templates/result.html | 19 +++++++++++ trials/urls.py | 4 ++- trials/views.py | 26 +++++++++++++++ 8 files changed, 154 insertions(+), 31 deletions(-) create mode 100644 templates/generic_test_2.html create mode 100644 templates/result.html diff --git a/static/style.css b/static/style.css index 8c9ce00..04edfc7 100644 --- a/static/style.css +++ b/static/style.css @@ -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 { +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index da8c1ab..42a0d6e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -38,6 +38,8 @@ SOITA | {% block title %}{% endblock %} + {% block additional_head %} + {% endblock %} diff --git a/templates/generic_test.html b/templates/generic_test.html index 0a815ae..0976f95 100644 --- a/templates/generic_test.html +++ b/templates/generic_test.html @@ -1,8 +1,9 @@ - - - +{% extends "base.html" %} + +{% block title %}{{ test.name }}{% endblock %} + +{% block additional_head %} - {{ test.name }} - - -
-
-
- {{ test.name }} +{% endblock %} + +{% block content %} +
+
+
+ {{ test.name }} +
+ {% for question in test.questions.all %} + +
+ {{ question.description }} +
+ +
+ {% for answer in question.answers.all %} + + {% endfor %} +
+ + {% endfor %}
-{% for question in test.questions.all %} - -
- {{ question.description }}
+{% endblock %} -
- {% for answer in question.answers.all %} - - {% endfor %} -
- -{% endfor %} -
-
- - - diff --git a/templates/generic_test_2.html b/templates/generic_test_2.html new file mode 100644 index 0000000..0a815ae --- /dev/null +++ b/templates/generic_test_2.html @@ -0,0 +1,48 @@ + + + + + {{ test.name }} + + + + +
+
+
+ {{ test.name }} +
+{% for question in test.questions.all %} + +
+ {{ question.description }} +
+ +
+ {% for answer in question.answers.all %} + + {% endfor %} +
+ +{% endfor %} +
+
+ + + diff --git a/templates/home.html b/templates/home.html index f39b49c..c7fa024 100644 --- a/templates/home.html +++ b/templates/home.html @@ -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.
- Passing score: {{test.passing_score}} + Passing score: {{test.passing_score}} / Questions: {{test.questions|length}}
diff --git a/templates/result.html b/templates/result.html new file mode 100644 index 0000000..36c26c6 --- /dev/null +++ b/templates/result.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block title %}Test result{% endblock %} + +{% block content %} +
+ Card image cap +
+
Quite good! All the best for next quiz!
+
Score: 3
+ +

Percentage: 60%

+

Correct answers: 3

+

Incorrect answers: 2

+

Total questions: 5

+
+
+{% endblock %} + diff --git a/trials/urls.py b/trials/urls.py index b2139f5..b93d8f6 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -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('/show', TestTemplateView.as_view()), - path('/mark', TestValidateAPIView.as_view()) + path('/mark', TestValidateAPIView.as_view()), + path('/result', TestResultView.as_view()) ] urlpatterns += router.urls diff --git a/trials/views.py b/trials/views.py index 4a47e5d..66a9420 100644 --- a/trials/views.py +++ b/trials/views.py @@ -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" \ No newline at end of file