diff --git a/static/style.css b/static/style.css index 498c2db..d4cb83d 100644 --- a/static/style.css +++ b/static/style.css @@ -63,6 +63,19 @@ padding-bottom: 20px; } +.solvedTestContainer { + border-radius: 25px; + border: 2px solid #FF0B7E; + padding: 20px; + width: 300px; + height: 200px; +} + +.solvedTestText { + font-size: 16px; + padding-bottom: 20px; +} + .mainTestMeta { font-size: 13px; padding-bottom: 15px; @@ -101,6 +114,23 @@ transform: translate(200%,0%); } +.solvedTestContainer button { + height: 30px; + width: 150px; + color: #FFF; + font-size: 17px; + background: #00916E; + cursor: pointer; + border-radius: 25px; + border: none; + outline: none; +} + +.solvedTestContainer a { + color: inherit; + text-decoration: inherit; +} + .doubleButton button{ height: 30px; @@ -115,6 +145,19 @@ transform: translate(150%,0%); } +.tripleButton button{ + color: #FFF; + background: #00916E; + font-size: 17px; + height: 30px; + width: 150px; + cursor: pointer; + border-radius: 25px; + border: none; + outline: none; + transform: translate(115%,0%); +} + .defaultButton { height: 30px; width: 150px; @@ -268,6 +311,8 @@ background-color:#FF0B7E } .resultText { + font-weight: normal; + font-size: 16px; } .accountInfoContainer{ @@ -306,13 +351,30 @@ background-color:#FF0B7E background-color: #3e8e41; } + .accountInfoContainer a{ color: inherit; text-decoration: inherit; } -.returnLink{ - color: #00916E; + +/*.defaultButton a { + color: inherit; + text-decoration: inherit; +}*/ + +.accountInfoContainer input[type=submit]{ + height: 30px; + color: #FFF; + font-size: 15px; + background: #00916E; + cursor: pointer; + border-radius: 25px; + border: none; + outline: none; + margin-top: 15px; + padding-left: 15px; + padding-right: 15px; } .testContent{ diff --git a/templates/account.html b/templates/account.html index 49233dd..b2da2b7 100644 --- a/templates/account.html +++ b/templates/account.html @@ -9,7 +9,7 @@
{{user.first_name}} {{user.last_name}}

Email: {{user.email}}


-
+

{% endblock %} diff --git a/templates/changeEmail.html b/templates/changeEmail.html index 8bb160e..bc6133a 100644 --- a/templates/changeEmail.html +++ b/templates/changeEmail.html @@ -6,8 +6,10 @@


-

+

- Back to dashboard +
+ Back to dashboard +
{% endblock %} diff --git a/templates/changeName.html b/templates/changeName.html index 72d4a45..9501a5c 100644 --- a/templates/changeName.html +++ b/templates/changeName.html @@ -9,6 +9,8 @@



- Back to dashboard +
+ Back to dashboard +
{% endblock %} diff --git a/templates/changePassword.html b/templates/changePassword.html new file mode 100644 index 0000000..fa796a1 --- /dev/null +++ b/templates/changePassword.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% block title %}Update name{% endblock %} + +{% block content %} +
+
+

+

+

+

+
+
+ Back to dashboard +
+
+{% endblock %} diff --git a/templates/createTest.html b/templates/createTest.html index 7d2ce7a..27b4d12 100644 --- a/templates/createTest.html +++ b/templates/createTest.html @@ -34,7 +34,9 @@

- Dodaj pytania + {% endblock %} diff --git a/templates/myTests.html b/templates/myTests.html index 3f1acb2..5e8e378 100644 --- a/templates/myTests.html +++ b/templates/myTests.html @@ -18,9 +18,10 @@ 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. -
+
+

diff --git a/templates/result.html b/templates/result.html index e37301d..801874a 100644 --- a/templates/result.html +++ b/templates/result.html @@ -7,23 +7,25 @@ Card image cap
- Quite good! All the best for next quiz! - - - - - - - - - - - + + {% if percentage == 100 %} + Idealnie, widzę że ten temat nie ma dla ciebie tajemnic! + {% elif percentage >= 75 %} + Bardzo dobrze, ale są jeszcze pewne braki ;) + {% elif percentage >= 50 %} + Nie jest źle, wiedziałeś więcej niż mniej + {% elif percentage >= 25 %} + Masz spore braki, powinieneś trochę więcej się pouczyć + {% else %} + Słabiutko, ale następnym razem będzie lepiej + {% endif %}
Result: {{ status }}
-
Score: {{ points }}
+
Score: {{ points }}
+
Passing Score: {{ passing }}
+
Max Score: {{ max }}
+
Percentage: {{ percentage }}
-{#

Percentage: 60%

#} {#

Correct answers: 3

#} {#

Incorrect answers: 2

#} {#

Total questions: 5

#} diff --git a/templates/solvedTests.html b/templates/solvedTests.html new file mode 100644 index 0000000..9d4fdd9 --- /dev/null +++ b/templates/solvedTests.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block title %}Home{% endblock %} + +{% block content %} +

Your history

+ {% for test in tests %} +
+
+ {{test.name}} +
+
Your score: {{test.score}}
+
Passing score: {{test.passing_score}}
+
Max score: {{test.max}}
+
Percentage: {{test.percentage}}
+ +
+
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/trials/migrations/0011_auto_20220123_1633.py b/trials/migrations/0011_auto_20220123_1633.py new file mode 100644 index 0000000..070949c --- /dev/null +++ b/trials/migrations/0011_auto_20220123_1633.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.9 on 2022-01-23 15:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('trials', '0010_test_created_by'), + ] + + operations = [ + migrations.AddField( + model_name='solvedtest', + name='max', + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name='solvedtest', + name='percentage', + field=models.IntegerField(default=0), + ), + ] diff --git a/trials/models.py b/trials/models.py index 97da03c..380b115 100644 --- a/trials/models.py +++ b/trials/models.py @@ -41,6 +41,25 @@ class Test(models.Model): points += question.points return points + def get_maxscore(self, answers): + """ + [ + { + "question": 1, + "answer": 1 + }, + { + "question": 2, + "answer": 1 + } + ] + """ + points = 0 + for answer in answers: + question = self.questions.get(id=answer["question"]) + points += question.points + return points + def name_and_passing_score(self): return { "name": self.name, @@ -50,6 +69,8 @@ class Test(models.Model): class SolvedTest(models.Model): score = models.IntegerField(default=0) + max = models.IntegerField(default=0) + percentage = models.IntegerField(default=0) user = models.ForeignKey( "users.User", null=True, diff --git a/trials/views.py b/trials/views.py index 9cb7b1a..928e845 100644 --- a/trials/views.py +++ b/trials/views.py @@ -53,15 +53,27 @@ def solvedTests(request): formatted_tests.append({ "name": solved_test.test.name_and_passing_score()["name"], "passing_score": solved_test.test.name_and_passing_score()["passing_score"], - "score": solved_test.score + "score": solved_test.score, + "max": solved_test.max, + "percentage": solved_test.percentage }) context['tests'] = formatted_tests - return render(request, 'myTests.html', context) + return render(request, 'solvedTests.html', context) def editTest(request): - pass - # TODO + if request.POST: + # TODO here + # firstName = request.POST.get("firstName") + # lastName = request.POST.get("lastName") + # + # u = request.user + # u.first_name = firstName + # u.last_name = lastName + # u.save() + return redirect('myTests') + return render(request, 'editTest.html') + class EditTestTemplateView(TemplateView): PASSED = "passed" @@ -144,6 +156,9 @@ class TestTemplateView(TemplateView): def get_score(self, test: Test, answers): return test.get_score(answers) + def get_maxscore(self, test: Test, answers): + return test.get_maxscore(answers) + def formatted_responses(self, unformatted_json): formatted_response = list() for question, answer in unformatted_json.items(): @@ -158,13 +173,19 @@ class TestTemplateView(TemplateView): 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)) + max = self.get_maxscore(test, self.formatted_responses(request.POST)) status = score >= test.passing_score context = { "status": self.PASSED.get(status, self.UNKNOWN), - "points": score + "points": score, + "max": max, + "passing": test.passing_score, + "percentage": int(score/max * 100) } SolvedTest.objects.create( score=score, + max=max, + percentage=int(score/max * 100), user=request.user, test=test ) diff --git a/users/urls.py b/users/urls.py index 40f2b6d..6e3340d 100644 --- a/users/urls.py +++ b/users/urls.py @@ -4,7 +4,7 @@ from django.urls import path from users.views import UserModelViewSet from rest_framework_simplejwt.views import TokenObtainPairView from rest_framework_simplejwt.views import TokenRefreshView -from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success, account, changeEmail, changeName +from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success, account, changeEmail, changeName, changePassword router = DefaultRouter(trailing_slash=False) @@ -25,6 +25,7 @@ urlpatterns = [ path("password/reset/confirm", UserPasswordResetConfirmView.as_view(), name="resetPasswordConfirm"), path("email/change", changeEmail, name='changeEmail'), path("name/change", changeName, name='changeName'), + path("password/change", changePassword, name='changePassword'), path("account", account, name='account') ] diff --git a/users/views.py b/users/views.py index e40141d..c81617a 100644 --- a/users/views.py +++ b/users/views.py @@ -152,3 +152,18 @@ def changeName(request): u.save() return redirect('account') return render(request, 'changeName.html') + + +@login_required +def changePassword(request): + if request.POST: + oldPassword = request.POST.get("oldPassword") + newPassword = request.POST.get("newPassword") + repeatPassword = request.POST.get("repeatPassword") + + # u = request.user + # u.first_name = firstName + # u.last_name = lastName + # u.save() + return redirect('account') + return render(request, 'changePassword.html')