diff --git a/config/settings.py b/config/settings.py index f1ba50f..c7d6522 100644 --- a/config/settings.py +++ b/config/settings.py @@ -56,6 +56,7 @@ INSTALLED_APPS = [ "django_extensions", "django_social_share", 'fontawesomefree', + "jquery", "users", "trials", diff --git a/config/urls.py b/config/urls.py index e2c4f31..b882af1 100644 --- a/config/urls.py +++ b/config/urls.py @@ -16,12 +16,14 @@ Including another URLconf from django.contrib import admin from django.urls import include from django.urls import path -from .views import home, welcome, help +from .views import home, welcome, help, hard, popular from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = [ path('', welcome, name='welcome'), path('home', home, name='home'), + path('popular', popular, name='popular'), + path('hard', hard, name='hard'), path('help', help, name='help'), path('users/', include("users.urls")), path('questions/', include("questions.urls")), diff --git a/config/views.py b/config/views.py index a6157b1..cd37137 100644 --- a/config/views.py +++ b/config/views.py @@ -2,6 +2,7 @@ from django.shortcuts import render, redirect from django.template import loader from django.contrib.auth.decorators import login_required from trials.models import Test +import operator @login_required @@ -18,6 +19,20 @@ def home(request): def help(request): return render(request, 'help.html', ) +@login_required +def popular(request): + context = {} + context['tests'] = Test.objects.filter(avg_rating__gt=0) + context['tests'] = sorted(context['tests'], key=operator.attrgetter('avg_rating'), reverse=True) + return render(request, 'popular.html', context) + +@login_required +def hard(request): + context = {} + context['tests'] = Test.objects.filter(difficulty_label__gt=0) + context['tests'] = sorted(context['tests'], key=operator.attrgetter('difficulty_label'), reverse=True) + return render(request, 'hard.html', context) + def welcome(request): return render(request, 'welcome.html') diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..0b8e7bd --- /dev/null +++ b/static/script.js @@ -0,0 +1,21 @@ +//$(function() { +// $(".newQuestionSection" ).draggable().resizable(); +//} ); + +var questionId = 1; + +$('.addQuestionButton').click(function(){ + console.log("REEEEEEEE") + // Clone extra box, and remove duplicate ids + let clone = $("#question-copy").clone().removeAttr("hidden"); + clone.id = "question"- + ++questionId; + //clone.find("*").removeAttr("id"); + clone.find("*").each(function() { + $(this).attr("id", "q" + questionId + "-" + $(this).attr("id")); + }); + clone.find("input:radio").each(function() { + $(this).attr("name", questionId); + }); + // append it to div + $('#canvas').append(clone); +}); \ No newline at end of file diff --git a/static/style.css b/static/style.css index ce253be..080d606 100644 --- a/static/style.css +++ b/static/style.css @@ -1,6 +1,6 @@ .sidenav { height: 100%; - width: 195px; + width: 215px; position: fixed; z-index: 1; top: 0; @@ -44,7 +44,7 @@ } .main { - margin-left: 190px; + margin-left: 215px; padding: 0px 40px; } @@ -515,6 +515,23 @@ background-color:#FF0B7E width: 500px; } +.newQuestionSection { + border-radius: 25px; + border: 2px solid #FF0B7E; + padding: 20px; + width: 750px; + height: 350px; +} + +.questionSectionLabelText { + font-weight: bold; + font-size: 16px; + padding-bottom: 20px; +} + +.addQuestionButton { +} + .editContainer { overflow: scroll; } diff --git a/templates/base.html b/templates/base.html index a462f5f..2a0a349 100644 --- a/templates/base.html +++ b/templates/base.html @@ -16,11 +16,14 @@
- Strona główna - Stwórz test - Twoje testy - Wyniki testów - Pomoc + Strona główna + Popularne + Trudne + Turnieje +
+ Stwórz test + Twoje testy + Wyniki testów

Kategorie

Język polski Język angielski @@ -34,13 +37,16 @@ Historia Inne

Konto

- Ustawienia - Wyloguj + Ustawienia + Pomoc + Wyloguj
- {% block content %} - {% endblock %} +
+ {% block content %} + {% endblock %} +
diff --git a/templates/category.html b/templates/category.html index 132326a..c3b75d7 100644 --- a/templates/category.html +++ b/templates/category.html @@ -32,31 +32,31 @@
Trudność: - {% if test.avg_difficulty == 0.0 %} + {% if test.difficulty_label == 0 %} - {% elif test.avg_difficulty < 20.0 %} + {% elif test.difficulty_label == 1 %} > > > > - {% elif test.avg_difficulty < 40.0 %} + {% elif test.difficulty_label == 2 %} - {% elif test.avg_difficulty < 60.0 %} + {% elif test.difficulty_label == 3 %} - {% elif test.avg_difficulty < 80.0 %} + {% elif test.difficulty_label == 4 %} diff --git a/templates/createTestNew.html b/templates/createTestNew.html new file mode 100644 index 0000000..4bdcfcb --- /dev/null +++ b/templates/createTestNew.html @@ -0,0 +1,10 @@ + + + + + $Title$ + + +$END$ + + \ No newline at end of file diff --git a/templates/hard.html b/templates/hard.html new file mode 100644 index 0000000..d95a485 --- /dev/null +++ b/templates/hard.html @@ -0,0 +1,118 @@ +{% extends "base.html" %} + +{% block title %}Główna{% endblock %} + +{% block content %} +

Najtrudniejsze testy:

+ {% for test in tests %} +
+
+ {{test.name}} + {% if test.password != "" %} + + {% endif %} +
+
+
+
Kategoria: {{test.category}}
+
Autor: {{test.get_author_name}}
+
Rozwiązania: {{test.completions}}
+
+
+
Próg zaliczenia: {{test.passing_score}}
+
Maksymalna ilość punktów: {{test.get_maxscore}}
+
Ilość pytań: {{test.question_count}}
+
+
+
+ Trudność: + {% if test.difficulty_label == 0 %} + + + + + + {% elif test.difficulty_label == 1 %} + + > + > + > + > + {% elif test.difficulty_label == 2 %} + + + + + + {% elif test.difficulty_label == 3 %} + + + + + + {% elif test.difficulty_label == 4 %} + + + + + + {% else %} + + + + + + {% endif %} +
+
+ Ocena: + {% if test.avg_rating == 0 %} + + + + + + {% elif test.avg_rating == 1 %} + + + + + + {% elif test.avg_rating == 2 %} + + + + + + {% elif test.avg_rating == 3 %} + + + + + + {% elif test.avg_rating == 4 %} + + + + + + {% else %} + + + + + + {% endif %} + (Głosy: {{test.rates_amount}}) +
+
+
+ + + + +
+
+ {% endfor %} +{% endblock %} + diff --git a/templates/home.html b/templates/home.html index f119747..d57bd6b 100644 --- a/templates/home.html +++ b/templates/home.html @@ -3,7 +3,7 @@ {% block title %}Główna{% endblock %} {% block content %} -

Rozwiąż jakiś test!

+

Najnowsze testy:

{% for test in tests %}
@@ -26,31 +26,31 @@
Trudność: - {% if test.avg_difficulty == 0.0 %} + {% if test.difficulty_label == 0 %} - {% elif test.avg_difficulty < 20.0 %} + {% elif test.difficulty_label == 1 %} > > > > - {% elif test.avg_difficulty < 40.0 %} + {% elif test.difficulty_label == 2 %} - {% elif test.avg_difficulty < 60.0 %} + {% elif test.difficulty_label == 3 %} - {% elif test.avg_difficulty < 80.0 %} + {% elif test.difficulty_label == 4 %} diff --git a/templates/popular.html b/templates/popular.html new file mode 100644 index 0000000..7c6ce28 --- /dev/null +++ b/templates/popular.html @@ -0,0 +1,118 @@ +{% extends "base.html" %} + +{% block title %}Główna{% endblock %} + +{% block content %} +

Najpopularniejsze testy:

+ {% for test in tests %} +
+
+ {{test.name}} + {% if test.password != "" %} + + {% endif %} +
+
+
+
Kategoria: {{test.category}}
+
Autor: {{test.get_author_name}}
+
Rozwiązania: {{test.completions}}
+
+
+
Próg zaliczenia: {{test.passing_score}}
+
Maksymalna ilość punktów: {{test.get_maxscore}}
+
Ilość pytań: {{test.question_count}}
+
+
+
+ Trudność: + {% if test.difficulty_label == 0 %} + + + + + + {% elif test.difficulty_label == 1 %} + + > + > + > + > + {% elif test.difficulty_label == 2 %} + + + + + + {% elif test.difficulty_label == 3 %} + + + + + + {% elif test.difficulty_label == 4 %} + + + + + + {% else %} + + + + + + {% endif %} +
+
+ Ocena: + {% if test.avg_rating == 0 %} + + + + + + {% elif test.avg_rating == 1 %} + + + + + + {% elif test.avg_rating == 2 %} + + + + + + {% elif test.avg_rating == 3 %} + + + + + + {% elif test.avg_rating == 4 %} + + + + + + {% else %} + + + + + + {% endif %} + (Głosy: {{test.rates_amount}}) +
+
+
+ + + + +
+
+ {% endfor %} +{% endblock %} + diff --git a/trials/models.py b/trials/models.py index d6c499f..56c8f4d 100644 --- a/trials/models.py +++ b/trials/models.py @@ -28,6 +28,7 @@ class Test(models.Model): total_rating = models.IntegerField(default=0) avg_rating = models.IntegerField(default=0) rates_amount = models.IntegerField(default=0) + difficulty_label = models.IntegerField(default=0) avg_difficulty = models.FloatField(default=0.0) objects = TestManager() diff --git a/trials/serializers.py b/trials/serializers.py index fa5683c..0f938ed 100644 --- a/trials/serializers.py +++ b/trials/serializers.py @@ -19,6 +19,14 @@ class TestSerializer(serializers.ModelSerializer): "questions", "visible", "category", + "created_by", + "completions", + "total_percentage_scored_by_users", + "total_rating", + "avg_rating", + "rates_amount", + "difficulty_label", + "avg_difficulty" ) def create(self, validated_data): diff --git a/trials/urls.py b/trials/urls.py index c689e6f..c563442 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -1,7 +1,7 @@ from django.urls import path from rest_framework.routers import DefaultRouter -from trials.views import TestModelViewSet, TestTemplateView, TestValidateAPIView, TestResultView, rateTest, addTest, addQuestions, myTests, solvedTests, solvedTestsDetailed, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName, editVisible, editPassword, TestPasswordTemplateView +from trials.views import TestModelViewSet, TestTemplateView, TestValidateAPIView, TestResultView, rateTest, addTest, addTest2, addQuestions, myTests, solvedTests, solvedTestsDetailed, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName, editVisible, editPassword, TestPasswordTemplateView router = DefaultRouter(trailing_slash=False) router.register("items", TestModelViewSet) diff --git a/trials/views.py b/trials/views.py index 1908b23..90efd21 100644 --- a/trials/views.py +++ b/trials/views.py @@ -18,12 +18,12 @@ from django.template import loader from django.template.loader import render_to_string, get_template from django.http import HttpRequest import requests +from django.contrib.auth.decorators import login_required - +@login_required def addTest(request): return render(request, 'createTest.html') - def is_visible(visible): if visible =="public": return True @@ -144,14 +144,14 @@ class RemoveQuestionFromExistingTest(TemplateView): Question.objects.get(id=request.POST["id"]).delete() return redirect(f'/tests/{kwargs["test_id"]}/edit') - +@login_required def myTests(request): context = {} user = request.user.id context['tests'] = Test.objects.filter(created_by=user) return render(request, 'myTests.html', context) - +@login_required def solvedTests(request): context = {} user_id = request.user.id @@ -180,7 +180,7 @@ def solvedTests(request): context['tests_lists'] = dict_with_lists_of_test_results return render(request, 'solvedTests.html', context) - +@login_required def solvedTestsDetailed(request, test_id): context = {} solved_tests = SolvedTest.objects.filter(test__id=test_id) @@ -268,12 +268,12 @@ class EditQuestionTemplateView(TemplateView): Question.objects.EditQuestion(question_id=question_id, name=description, answers=answers) return redirect(f'/tests/{test}/edit') - +@login_required def deleteTest(request, test_id): Test.objects.filter(id=test_id).delete() return redirect('myTests') - +@login_required def editVisible(request, test_id): new_visible = request.GET["visible"] if new_visible == "public": @@ -285,6 +285,7 @@ def editVisible(request, test_id): test.save() return redirect(f'/tests/{test_id}/edit') +@login_required def editName(request, test_id): new_name = request.GET["name"] test = Test.objects.get(id=test_id) @@ -292,7 +293,7 @@ def editName(request, test_id): test.save() return redirect(f'/tests/{test_id}/edit') - +@login_required def editPassword(request, test_id): new_password = request.GET["password"] test = Test.objects.get(id=test_id) @@ -300,7 +301,7 @@ def editPassword(request, test_id): test.save() return redirect(f'/tests/{test_id}/edit') - +@login_required def rateTest(request, test_id): test = Test.objects.get(id=test_id) rate = request.GET["rate"] @@ -401,6 +402,7 @@ class TestTemplateView(TemplateView): return HttpResponseRedirect(f'result') +@login_required def TestPasswordTemplateView(request, test_id): test = Test.objects.get(id=test_id) if test.password == "": @@ -411,6 +413,7 @@ def TestPasswordTemplateView(request, test_id): return render(request, 'testPassword.html') +@login_required def testView(request): permission_classes = [] template_name = settings.BASE_DIR + f"/templates/generic_test.html"