From 1c4e733e78dc2382effd862a3051f1b3398e3d8b Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Mon, 17 Jan 2022 16:31:09 +0100 Subject: [PATCH 1/7] Add test template --- templates/addQuestions.html | 46 ++++++++++++++++++++++++++++++++++++ templates/base.html | 2 +- templates/createTest.html | 41 ++++++++++++++++++++++++++++++++ trials/urls.py | 6 +++-- trials/views.py | 47 +++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 templates/addQuestions.html create mode 100644 templates/createTest.html diff --git a/templates/addQuestions.html b/templates/addQuestions.html new file mode 100644 index 0000000..958807c --- /dev/null +++ b/templates/addQuestions.html @@ -0,0 +1,46 @@ +{% extends "base.html" %} +{% load rest_framework %} + +{% block title %}New Test{% endblock %} + +{% block content %} +
+
+

Add questions

+ {% for i in 1|range:4 %} +

Question {{i}}

+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ {% endfor %} + +
+
+{% endblock %} + diff --git a/templates/base.html b/templates/base.html index 63d4e80..f509421 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,7 +13,7 @@
Home - Create test + Create test Your tests

Categories

Język polski diff --git a/templates/createTest.html b/templates/createTest.html new file mode 100644 index 0000000..93e5bb5 --- /dev/null +++ b/templates/createTest.html @@ -0,0 +1,41 @@ +{% extends "base.html" %} +{% load rest_framework %} + +{% block title %}New Test{% endblock %} + +{% block content %} +
+
+

Create test

+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+{% endblock %} + diff --git a/trials/urls.py b/trials/urls.py index b93d8f6..44f50d6 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -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('/show', TestTemplateView.as_view()), path('/mark', TestValidateAPIView.as_view()), - path('/result', TestResultView.as_view()) + path('/result', TestResultView.as_view()), + path('add/test', addTest, name="newTest"), + path('add/questions', addQuestions, name="addQuestions") ] urlpatterns += router.urls diff --git a/trials/views.py b/trials/views.py index 9535f98..9505f0c 100644 --- a/trials/views.py +++ b/trials/views.py @@ -7,6 +7,53 @@ from trials.models import Test from trials.serializers import TestSerializer from django.conf import settings from django.http import HttpResponseRedirect +from django.shortcuts import render, redirect +from django import 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): -- 2.20.1 From 7ae5d8135da112295d69f2ca268c9f3976769143 Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Mon, 17 Jan 2022 17:38:53 +0100 Subject: [PATCH 2/7] Your tests page but html and css are the worst languages --- config/views.py | 7 +++---- static/style.css | 14 ++++++++++++++ templates/base.html | 2 +- templates/myTests.html | 30 ++++++++++++++++++++++++++++++ trials/urls.py | 6 ++++-- trials/views.py | 13 +++++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 templates/myTests.html diff --git a/config/views.py b/config/views.py index 9fdf12e..30925e4 100644 --- a/config/views.py +++ b/config/views.py @@ -7,11 +7,10 @@ from trials.models import Test @login_required def home(request): context = {} + # TODO replace + #context['tests'] = Test.objects.filter(owner=request.user) context['tests'] = Test.objects.all - # context = { - # 'latest_question_list': latest_question_list, - # } - return render(request, 'home.html', context) + return render(request, 'myTests.html', context) def welcome(request): diff --git a/static/style.css b/static/style.css index 4317c4c..6c44bfd 100644 --- a/static/style.css +++ b/static/style.css @@ -81,6 +81,20 @@ transform: translate(200%,0%); } + +.mainTestContainerDoubleButton button{ + height: 30px; + width: 150px; + color: #FFF; + font-size: 17px; + background: #00916E; + cursor: pointer; + border-radius: 25px; + border: none; + outline: none; + transform: translate(150%,0%); +} + .mainTestContainer a { color: inherit; text-decoration: inherit; diff --git a/templates/base.html b/templates/base.html index f509421..9638cdc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -14,7 +14,7 @@
Home Create test - Your tests + Your tests

Categories

Język polski Język angielski diff --git a/templates/myTests.html b/templates/myTests.html new file mode 100644 index 0000000..92e9166 --- /dev/null +++ b/templates/myTests.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} + +{% block title %}My Tests{% endblock %} + +{% block content %} +

Check your tests

+ {% for test in tests %} +
+
+ {{test.name}} +
+
+ Category: {{test.category}} +
+
+ + 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}} / Questions: {{test.questions|length}} +
+
+ + +
+
+
+ {% endfor %} +{% endblock %} + diff --git a/trials/urls.py b/trials/urls.py index 44f50d6..074c09a 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -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, addTest, addQuestions +from trials.views import TestResultView, addTest, addQuestions, myTests, editTest router = DefaultRouter(trailing_slash=False) router.register("items", TestModelViewSet) @@ -13,8 +13,10 @@ urlpatterns = [ path('/show', TestTemplateView.as_view()), path('/mark', TestValidateAPIView.as_view()), path('/result', TestResultView.as_view()), + path('/edit', editTest), path('add/test', addTest, name="newTest"), - path('add/questions', addQuestions, name="addQuestions") + path('add/questions', addQuestions, name="addQuestions"), + path('mytests', myTests, name="myTests") ] urlpatterns += router.urls diff --git a/trials/views.py b/trials/views.py index 77edc95..f9250c3 100644 --- a/trials/views.py +++ b/trials/views.py @@ -58,6 +58,19 @@ def addQuestions(request): return render(request, 'addQuestions.html') +def myTests(request): + context = {} + # context['tests']=Test.objects.filter(category=request.user) + context['tests']=Test.objects.filter(category="Matematyka") + #context['tests'] = Test.objects.all + return render(request, 'myTests.html', context) + + +def editTest(request): + pass + # TODO + + class TestModelViewSet(viewsets.ModelViewSet): queryset = Test.objects.all() serializer_class = TestSerializer -- 2.20.1 From 636f1b31999a4f910c8b9314fb5a9d0b21e003ac Mon Sep 17 00:00:00 2001 From: Hubert Jankowski Date: Mon, 17 Jan 2022 18:50:08 +0100 Subject: [PATCH 3/7] Added possibility to complete tests --- config/settings.py | 3 +- templates/addQuestions.html | 6 ++-- tools/templatetags/__init__.py | 0 tools/templatetags/filters.py | 6 ++++ tools/tools.py | 3 +- trials/views.py | 58 +++++++++++++--------------------- 6 files changed, 36 insertions(+), 40 deletions(-) create mode 100644 tools/templatetags/__init__.py create mode 100644 tools/templatetags/filters.py diff --git a/config/settings.py b/config/settings.py index fef4f84..2ff59c6 100644 --- a/config/settings.py +++ b/config/settings.py @@ -59,7 +59,8 @@ INSTALLED_APPS = [ "trials", "answers", "questions", - "categories" + "categories", + "tools" ] # AUTHENTICATION_BACKENDS = ['config.authh.SettingsBackend'] MIDDLEWARE = [ diff --git a/templates/addQuestions.html b/templates/addQuestions.html index 958807c..423dc09 100644 --- a/templates/addQuestions.html +++ b/templates/addQuestions.html @@ -1,13 +1,15 @@ {% extends "base.html" %} +{% load filters %} {% load rest_framework %} + {% block title %}New Test{% endblock %} {% block content %}

Add questions

- {% for i in 1|range:4 %} + {% for i in number_of_questions|times %}

Question {{i}}

@@ -29,7 +31,7 @@

- +

- + +
{% endblock %} diff --git a/templates/base.html b/templates/base.html index 9638cdc..c1e0e46 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,9 +12,10 @@
- Home + Home Create test Your tests + Solved tests

Categories

Język polski Język angielski diff --git a/templates/category.html b/templates/category.html index 3e16106..0aa43e5 100644 --- a/templates/category.html +++ b/templates/category.html @@ -10,15 +10,14 @@ {{test.name}}
- Category: {{test.category}} +
Category: {{test.category}}
+
Passing score: {{test.passing_score}}
+
Questions: {{test.questions|length}}
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}} -

diff --git a/templates/generic_test.html b/templates/generic_test.html index b8e9ddc..91bef0e 100644 --- a/templates/generic_test.html +++ b/templates/generic_test.html @@ -23,14 +23,14 @@ {% endblock %} {% block content %} -
+
-
+
{{ test.name }}
{% for question in test.questions.all %} -
+
{{ question.description }}
@@ -45,9 +45,9 @@ {% endfor %}
- - -{# #} +
+ +
diff --git a/templates/generic_test_2.html b/templates/generic_test_2.html deleted file mode 100644 index 0a815ae..0000000 --- a/templates/generic_test_2.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - {{ 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 c7fa024..0d99d6e 100644 --- a/templates/home.html +++ b/templates/home.html @@ -10,15 +10,14 @@ {{test.name}}
- Category: {{test.category}} +
Category: {{test.category}}
+
Passing score: {{test.passing_score}}
+
Questions: {{test.questions|length}}
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}} / Questions: {{test.questions|length}} -

diff --git a/templates/login.html b/templates/login.html index 60ab399..616a453 100644 --- a/templates/login.html +++ b/templates/login.html @@ -16,6 +16,9 @@

{% endfor %} + {% endblock %} diff --git a/templates/login_old.html b/templates/login_old.html deleted file mode 100644 index fcc6db3..0000000 --- a/templates/login_old.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - Login - - - - - - - - - -
-
-
-
- - -

LOGIN

-
-
-
- {% csrf_token %} -
-
- -
- -
-
-
- -
- -
- - -
- -
- -
- - -
-
-
-
- - - \ No newline at end of file diff --git a/templates/logout.html b/templates/logout.html index 7bcd00e..b44b84a 100644 --- a/templates/logout.html +++ b/templates/logout.html @@ -4,6 +4,8 @@ {% block content %}

You have been logged out successfully

- Home +
+ Continue +
{% endblock %} diff --git a/templates/myTests.html b/templates/myTests.html index 92e9166..3f1acb2 100644 --- a/templates/myTests.html +++ b/templates/myTests.html @@ -10,16 +10,15 @@ {{test.name}}
- Category: {{test.category}} +
Category: {{test.category}}
+
Passing score: {{test.passing_score}}
+
Questions: {{test.questions|length}}
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}} / Questions: {{test.questions|length}} -
-
+ diff --git a/templates/result.html b/templates/result.html index 450e9c4..e37301d 100644 --- a/templates/result.html +++ b/templates/result.html @@ -6,10 +6,23 @@
Card image cap
-
Quite good! All the best for next quiz!
+
+ Quite good! All the best for next quiz! + + + + + + + + + + + +
Result: {{ status }}
Score: {{ points }}
- Home + {#

Percentage: 60%

#} {#

Correct answers: 3

#} {#

Incorrect answers: 2

#} diff --git a/trials/urls.py b/trials/urls.py index 074c09a..14615fc 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -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, addTest, addQuestions, myTests, editTest +from trials.views import TestResultView, addTest, addQuestions, myTests, editTest, solvedTests router = DefaultRouter(trailing_slash=False) router.register("items", TestModelViewSet) @@ -16,7 +16,8 @@ urlpatterns = [ path('/edit', editTest), path('add/test', addTest, name="newTest"), path('add/questions', addQuestions, name="addQuestions"), - path('mytests', myTests, name="myTests") + path('my', myTests, name="myTests"), + path('solved', solvedTests, name="solvedTests") ] urlpatterns += router.urls diff --git a/trials/views.py b/trials/views.py index f0ba7a2..1ec78d3 100644 --- a/trials/views.py +++ b/trials/views.py @@ -51,6 +51,15 @@ def myTests(request): return render(request, 'myTests.html', context) +def solvedTests(request): + # TODO implementation + context = {} + # context['tests']=Test.objects.filter(category=request.user) + context['tests']=Test.objects.filter(category="Matematyka") + #context['tests'] = Test.objects.all + return render(request, 'myTests.html', context) + + def editTest(request): pass # TODO -- 2.20.1 From a702c351635c92a60f615bf6b0b343a5998af832 Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Wed, 19 Jan 2022 21:17:45 +0100 Subject: [PATCH 5/7] Frontend hotfix --- config/urls.py | 3 ++- config/views.py | 5 +++++ static/style.css | 4 ++-- templates/base.html | 1 + templates/help.html | 8 ++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 templates/help.html diff --git a/config/urls.py b/config/urls.py index 9268279..dadb7c1 100644 --- a/config/urls.py +++ b/config/urls.py @@ -16,11 +16,12 @@ Including another URLconf from django.contrib import admin from django.urls import include from django.urls import path -from .views import home, welcome +from .views import home, welcome, help urlpatterns = [ path('', welcome, name='welcome'), path('home', home, name='home'), + path('help', help, name='help'), path('users/', include("users.urls")), path('questions/', include("questions.urls")), path('answers/', include("answers.urls")), diff --git a/config/views.py b/config/views.py index 75e35df..aa730a6 100644 --- a/config/views.py +++ b/config/views.py @@ -13,5 +13,10 @@ def home(request): return render(request, 'home.html', context) +@login_required +def help(request): + return render(request, 'help.html', ) + + def welcome(request): return render(request, 'welcome.html') diff --git a/static/style.css b/static/style.css index 7427ddd..d205180 100644 --- a/static/style.css +++ b/static/style.css @@ -1,6 +1,6 @@ .sidenav { height: 100%; - width: 175px; + width: 195px; position: fixed; z-index: 1; top: 0; @@ -39,7 +39,7 @@ } .main { - margin-left: 160px; + margin-left: 190px; padding: 0px 40px; } diff --git a/templates/base.html b/templates/base.html index c1e0e46..1b71b5f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -16,6 +16,7 @@ Create test Your tests Solved tests + Help

Categories

Język polski Język angielski diff --git a/templates/help.html b/templates/help.html new file mode 100644 index 0000000..9ed1056 --- /dev/null +++ b/templates/help.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Help{% endblock %} + +{% block content %} +

In the future, there will be an app manual here

+{% endblock %} + -- 2.20.1 From 350d0719f59de5963ed5b92ad7498b29ae19bd6b Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Fri, 21 Jan 2022 17:25:50 +0100 Subject: [PATCH 6/7] Test view fix --- static/style.css | 1 + templates/generic_test.html | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/static/style.css b/static/style.css index d205180..6b42677 100644 --- a/static/style.css +++ b/static/style.css @@ -316,6 +316,7 @@ background-color:#FF0B7E } .testContent{ + padding-top: 15px; padding-bottom: 15px; padding-left: 20px; } diff --git a/templates/generic_test.html b/templates/generic_test.html index 91bef0e..654091e 100644 --- a/templates/generic_test.html +++ b/templates/generic_test.html @@ -28,27 +28,26 @@
{{ test.name }}
- {% for question in test.questions.all %} - -
- {{ question.description }} -
-
- {% for answer in question.answers.all %} - + {% for question in test.questions.all %} +
+ {{ question.description }} +
+
+ {% for answer in question.answers.all %} + + {% endfor %} +
{% endfor %} -
+
+ +
+ +
- {% endfor %} -
-
- -
-
{% endblock %} -- 2.20.1 From 33317a84d241b3dad3bd263a6e15ab17aa3b4d11 Mon Sep 17 00:00:00 2001 From: Piotr Kopycki Date: Fri, 21 Jan 2022 18:34:46 +0100 Subject: [PATCH 7/7] Edit test page --- static/style.css | 16 ++++++++++++++ templates/editTest.html | 48 ++++++++++++++++++++++++++++++++++++++++ trials/urls.py | 4 ++-- trials/views.py | 49 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 templates/editTest.html diff --git a/static/style.css b/static/style.css index 6b42677..498c2db 100644 --- a/static/style.css +++ b/static/style.css @@ -352,4 +352,20 @@ background-color:#FF0B7E border-radius: 25px; border: none; outline: none; +} + +.editContainer { + overflow: scroll; +} + +.editContainerLine { + padding: 10px 0px 10px 0px; +} + +.editContainerSection { + padding-bottom: 15px; +} + +.editContainerSection h2 { + display: inline; } \ No newline at end of file diff --git a/templates/editTest.html b/templates/editTest.html new file mode 100644 index 0000000..59ba99a --- /dev/null +++ b/templates/editTest.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} +{% load rest_framework %} + +{% block title %}{{ test.name }} - Edit{% endblock %} + +{% block additional_head %} + +{% endblock %} + +{% block content %} +
+
+
+
+ + +
+
+ {% for question in test.questions.all %} +
+
+ + +
+ {% for answer in question.answers.all %} +
+ + +
+ {% endfor %} +
+ + +
+
+ {% endfor %} +
+ +
+
+
+{% endblock %} + diff --git a/trials/urls.py b/trials/urls.py index 14615fc..ba2ca97 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -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, addTest, addQuestions, myTests, editTest, solvedTests +from trials.views import TestResultView, addTest, addQuestions, myTests, editTest, solvedTests, EditTestTemplateView router = DefaultRouter(trailing_slash=False) router.register("items", TestModelViewSet) @@ -13,7 +13,7 @@ urlpatterns = [ path('/show', TestTemplateView.as_view()), path('/mark', TestValidateAPIView.as_view()), path('/result', TestResultView.as_view()), - path('/edit', editTest), + path('/edit', EditTestTemplateView.as_view()), path('add/test', addTest, name="newTest"), path('add/questions', addQuestions, name="addQuestions"), path('my', myTests, name="myTests"), diff --git a/trials/views.py b/trials/views.py index 1ec78d3..a99c76c 100644 --- a/trials/views.py +++ b/trials/views.py @@ -64,6 +64,55 @@ def editTest(request): pass # TODO +class EditTestTemplateView(TemplateView): + PASSED = "passed" + FAILED = "failed" + UNKNOWN = "unknown" + + PASSED = { + True: PASSED, + False: FAILED + } + + permission_classes = [] + template_name = settings.BASE_DIR + f"/templates/editTest.html" + test_id = None + + def get_queryset(self): + return Test.objects.all() + + def get_context_data(self, test_id, **kwargs): + self.test_id = test_id + context = super().get_context_data(**kwargs) + context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first() + return context + + def get_score(self, test: Test, answers): + return test.get_score(answers) + + def formatted_responses(self, unformatted_json): + formatted_response = list() + for question, answer in unformatted_json.items(): + formatted_response.append( + { + "question": question, + "answer": answer + } + ) + return formatted_response + + def post(self, request, *args, **kwargs): + test = Test.objects.get(id=kwargs.get("test_id")) + score = self.get_score(test, self.formatted_responses(request.POST)) + status = score >= test.passing_score + context = { + "status": self.PASSED.get(status, self.UNKNOWN), + "points": score + } + template_name = "result.html" + template = get_template(template_name) + return HttpResponse(template.render(context)) + class TestModelViewSet(viewsets.ModelViewSet): queryset = Test.objects.all() -- 2.20.1