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/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 9fdf12e..aa730a6 100644
--- a/config/views.py
+++ b/config/views.py
@@ -7,12 +7,16 @@ 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)
+@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 4317c4c..498c2db 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,6 +1,6 @@
.sidenav {
height: 100%;
- width: 160px;
+ width: 195px;
position: fixed;
z-index: 1;
top: 0;
@@ -8,6 +8,7 @@
background-color: #FF0B7E;
overflow-x: :hidden;
padding-top: 20px;
+ overflow-y: scroll;
}
.sidenav a {
@@ -38,7 +39,7 @@
}
.main {
- margin-left: 160px;
+ margin-left: 190px;
padding: 0px 40px;
}
@@ -66,6 +67,25 @@
font-size: 13px;
padding-bottom: 15px;
color: #808080;
+ /*transform: translate(150%,0%);*/
+ width:100%;
+ text-align:center;
+}
+
+.left {
+ float:left;
+ width: 175px;
+}
+
+.center {
+ display: inline-block;
+ margin:0 auto;
+ width: 175px;
+}
+
+.right {
+ float:right;
+ width: 175px;
}
.mainTestContainer button {
@@ -81,6 +101,37 @@
transform: translate(200%,0%);
}
+
+.doubleButton 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%);
+}
+
+.defaultButton {
+ height: 30px;
+ width: 150px;
+ color: #FFF;
+ font-size: 17px;
+ background: #00916E;
+ cursor: pointer;
+ border-radius: 25px;
+ border: none;
+ outline: none;
+}
+
+.defaultButton a {
+ color: inherit;
+ text-decoration: inherit;
+}
+
.mainTestContainer a {
color: inherit;
text-decoration: inherit;
@@ -88,6 +139,7 @@
.mainTestDesc{
padding-bottom: 15px;
+ text-align: center;
}
.mainTestQuest {
@@ -263,14 +315,57 @@ background-color:#FF0B7E
color: #00916E;
}
+.testContent{
+ padding-top: 15px;
+ padding-bottom: 15px;
+ padding-left: 20px;
+}
+
.testContent input[type=submit]{
height: 30px;
+ width: 150px;
color: #FFF;
- font-size: 15px;
+ font-size: 17px;
background: #00916E;
cursor: pointer;
border-radius: 25px;
border: none;
outline: none;
- margin-top: 15px;
+}
+
+.linkDefault {
+ padding-top: 15px;
+}
+
+.linkDefault a {
+ color: #00916E;
+ text-decoration: none;
+}
+
+.newContainer input[type=submit]{
+ height: 30px;
+ width: 150px;
+ color: #FFF;
+ font-size: 17px;
+ background: #00916E;
+ cursor: pointer;
+ 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/addQuestions.html b/templates/addQuestions.html
new file mode 100644
index 0000000..76db180
--- /dev/null
+++ b/templates/addQuestions.html
@@ -0,0 +1,48 @@
+{% extends "base.html" %}
+{% load filters %}
+{% load rest_framework %}
+
+
+{% block title %}New Test{% endblock %}
+
+{% block content %}
+
+
+
+{% endblock %}
+
diff --git a/templates/base.html b/templates/base.html
index 63d4e80..1b71b5f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -12,9 +12,11 @@
- 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}}
-
Start
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 %}
+
+
+
+{% endblock %}
+
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 %}
+
+{% endblock %}
+
diff --git a/templates/generic_test.html b/templates/generic_test.html
index b8e9ddc..654091e 100644
--- a/templates/generic_test.html
+++ b/templates/generic_test.html
@@ -23,32 +23,31 @@
{% endblock %}
{% block content %}
-
+
-
-
-{# #}
-
{% endblock %}
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 }}
-
-
-
-
-
-
-
-{% for question in test.questions.all %}
-
-
- {{ question.description }}
-
-
-
- {% for answer in question.answers.all %}
-
-
- {{ answer.description }}
-
- {% endfor %}
-
-
-{% endfor %}
-
-
-
-
-
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 %}
+
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}}
-
Start
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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Don't have an account?
Sign Up
-
-
-
-
-
-
-
-
-
\ 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
+
{% endblock %}
diff --git a/templates/myTests.html b/templates/myTests.html
new file mode 100644
index 0000000..3f1acb2
--- /dev/null
+++ b/templates/myTests.html
@@ -0,0 +1,29 @@
+{% extends "base.html" %}
+
+{% block title %}My Tests{% endblock %}
+
+{% block content %}
+ Check your tests
+ {% for test in tests %}
+
+
+ {{test.name}}
+
+
+
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.
+
+
+
+
+ {% endfor %}
+{% endblock %}
+
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 @@
-
Quite good! All the best for next quiz!
+
+ Quite good! All the best for next quiz!
+
+
+
+
+
+
+
+
+
+
+
+
Result: {{ status }}
Score: {{ points }}
-
Home
+
Home
{#
Percentage: 60%
#}
{#
Correct answers: 3
#}
{#
Incorrect answers: 2
#}
diff --git a/tools/templatetags/__init__.py b/tools/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templatetags/filters.py b/tools/templatetags/filters.py
new file mode 100644
index 0000000..1e67d58
--- /dev/null
+++ b/tools/templatetags/filters.py
@@ -0,0 +1,6 @@
+from django import template
+register = template.Library()
+
+@register.filter(name='times')
+def times(number):
+ return range(number)
\ No newline at end of file
diff --git a/tools/tools.py b/tools/tools.py
index 4341193..a44e920 100644
--- a/tools/tools.py
+++ b/tools/tools.py
@@ -38,4 +38,5 @@ class PasswordResetConfirmShortcut:
if serializer.is_valid():
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)
\ No newline at end of file
+ return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
diff --git a/trials/urls.py b/trials/urls.py
index b93d8f6..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
+from trials.views import TestResultView, addTest, addQuestions, myTests, editTest, solvedTests, EditTestTemplateView
router = DefaultRouter(trailing_slash=False)
router.register("items", TestModelViewSet)
@@ -12,7 +12,12 @@ 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('/edit', EditTestTemplateView.as_view()),
+ path('add/test', addTest, name="newTest"),
+ path('add/questions', addQuestions, name="addQuestions"),
+ path('my', myTests, name="myTests"),
+ path('solved', solvedTests, name="solvedTests")
]
urlpatterns += router.urls
diff --git a/trials/views.py b/trials/views.py
index f613231..a99c76c 100644
--- a/trials/views.py
+++ b/trials/views.py
@@ -1,3 +1,4 @@
+import requests
from django.views.generic import TemplateView
from rest_framework import views
from rest_framework import viewsets
@@ -6,15 +7,118 @@ 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
+from django.http import HttpRequest
+import requests
+
+
+def addTest(request):
+ if request.POST:
+ data = request.POST
+ return addQuestions(request="GET", data_about_test=data)
+ return render(request, 'createTest.html')
+
+
+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
+
+
+
+
+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 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
+
+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()
serializer_class = TestSerializer
+
class TestTemplateView(TemplateView):
PASSED = "passed"
FAILED = "failed"