Frontend update

This commit is contained in:
Piotr Kopycki 2022-01-23 17:10:05 +01:00
parent f9faf604b3
commit e76027bfd1
14 changed files with 217 additions and 28 deletions

View File

@ -63,6 +63,19 @@
padding-bottom: 20px; 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 { .mainTestMeta {
font-size: 13px; font-size: 13px;
padding-bottom: 15px; padding-bottom: 15px;
@ -101,6 +114,23 @@
transform: translate(200%,0%); 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{ .doubleButton button{
height: 30px; height: 30px;
@ -115,6 +145,19 @@
transform: translate(150%,0%); 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 { .defaultButton {
height: 30px; height: 30px;
width: 150px; width: 150px;
@ -268,6 +311,8 @@ background-color:#FF0B7E
} }
.resultText { .resultText {
font-weight: normal;
font-size: 16px;
} }
.accountInfoContainer{ .accountInfoContainer{
@ -306,13 +351,30 @@ background-color:#FF0B7E
background-color: #3e8e41; background-color: #3e8e41;
} }
.accountInfoContainer a{ .accountInfoContainer a{
color: inherit; color: inherit;
text-decoration: 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{ .testContent{

View File

@ -9,7 +9,7 @@
<h5 class="accountInfoName">{{user.first_name}} {{user.last_name}}</h5> <h5 class="accountInfoName">{{user.first_name}} {{user.last_name}}</h5>
<p class="accountInfoText"><b>Email:</b> {{user.email}}</p> <p class="accountInfoText"><b>Email:</b> {{user.email}}</p>
<button><a href="{% url 'changeEmail' %}">Change email</a></button><br> <button><a href="{% url 'changeEmail' %}">Change email</a></button><br>
<button><a href="{% url 'resetPassword' %}">Change password</a></button><br> <button><a href="{% url 'changePassword' %}">Change password</a></button><br>
<button><a href="{% url 'changeName' %}">Change name</a></button><br> <button><a href="{% url 'changeName' %}">Change name</a></button><br>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -6,8 +6,10 @@
<div class="accountInfoContainer "> <div class="accountInfoContainer ">
<form method="post"> <form method="post">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" required><br><br> <input type="email" id="email" name="email" class="form-control" placeholder="Email" required><br><br>
<input type="submit" value="Change name"><br><br> <input type="submit" value="Change email"><br><br>
</form> </form>
<a class="returnLink" href="{% url 'account' %}">Back to dashboard</a> <div class="linkDefault">
<a href="{% url 'account' %}">Back to dashboard</a>
</div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -9,6 +9,8 @@
<input type="text" id="lastName" name="lastName" class="form-control" placeholder="First Name" required><br><br> <input type="text" id="lastName" name="lastName" class="form-control" placeholder="First Name" required><br><br>
<input type="submit" value="Change name"><br><br> <input type="submit" value="Change name"><br><br>
</form> </form>
<a class="returnLink" href="{% url 'account' %}">Back to dashboard</a> <div class="linkDefault">
<a href="{% url 'account' %}">Back to dashboard</a>
</div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block title %}Update name{% endblock %}
{% block content %}
<div class="accountInfoContainer ">
<form method="post">
<input type="password" id="oldPassword" name="oldPassword" class="form-control" placeholder="Old password" required><br><br>
<input type="password" id="newPassword" name="newPassword" class="form-control" placeholder="New password" required><br><br>
<input type="password" id="repeatPassword" name="repeatPassword" class="form-control" placeholder="Repeat password" required><br><br>
<input type="submit" value="Change password"><br><br>
</form>
<div class="linkDefault">
<a href="{% url 'account' %}">Back to dashboard</a>
</div>
</div>
{% endblock %}

View File

@ -34,7 +34,9 @@
<input id="passing" type="number" name="passing" value="5"> <input id="passing" type="number" name="passing" value="5">
<br> <br>
<br> <br>
<a href='' onclick="this.href='questions?passing='+document.getElementById('passing').value + '&name=' +document.getElementById('name').value + '&catgory='+document.getElementById('category').value+'&number_of_questions='+document.getElementById('questions').value">Dodaj pytania</a> <button class="defaultButton">
<a href='' onclick="this.href='questions?passing='+document.getElementById('passing').value + '&name=' +document.getElementById('name').value + '&catgory='+document.getElementById('category').value+'&number_of_questions='+document.getElementById('questions').value">Dodaj pytania</a>
</button>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -18,9 +18,10 @@
<!-- TODO 250 words limit--> <!-- TODO 250 words limit-->
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. 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.
</div> </div>
<div class="doubleButton"> <div class="tripleButton">
<button><a href="/tests/{{test.id}}/show">Start</a></button> <button><a href="/tests/{{test.id}}/show">Start</a></button>
<button><a href="/tests/{{test.id}}/edit">Edit</a></button> <button><a href="/tests/{{test.id}}/edit">Edit</a></button>
<button style="background:#FF0000;"><a href="/tests/{{test.id}}/edit">Delete</a></button>
</div> </div>
</div> </div>
<br> <br>

View File

@ -7,23 +7,25 @@
<img class="resultImage" src="http://kmit.in/emagazine/wp-content/uploads/2018/02/karnataka-results.jpg" alt="Card image cap"> <img class="resultImage" src="http://kmit.in/emagazine/wp-content/uploads/2018/02/karnataka-results.jpg" alt="Card image cap">
<div class="resultBody"> <div class="resultBody">
<h5 class="resultMsg"> <h5 class="resultMsg">
Quite good! All the best for next quiz! <!-- Quite good! All the best for next quiz!-->
<!-- {% if max_score == 100 %}--> {% if percentage == 100 %}
<!-- Idealnie, widzę że ten temat nie ma dla ciebie tajemnic! --> Idealnie, widzę że ten temat nie ma dla ciebie tajemnic!
<!-- {% elif max_score >= 75 %}--> {% elif percentage >= 75 %}
<!-- Bardzo dobrze, ale są jeszcze pewne braki ;)--> Bardzo dobrze, ale są jeszcze pewne braki ;)
<!-- {% elif max_score >= 50 %}--> {% elif percentage >= 50 %}
<!-- Nie jest źle, wiedziałeś więcej niż mniej--> Nie jest źle, wiedziałeś więcej niż mniej
<!-- {% elif max_score >= 25 %}--> {% elif percentage >= 25 %}
<!-- Masz spore braki, powinieneś trochę więcej się pouczyć--> Masz spore braki, powinieneś trochę więcej się pouczyć
<!-- {% else %}--> {% else %}
<!-- Słabiutko, ale następnym razem będzie lepiej--> Słabiutko, ale następnym razem będzie lepiej
<!-- {% endif %}--> {% endif %}
</h5> </h5>
<h5 class="resultScore">Result: {{ status }}</h5> <h5 class="resultScore">Result: {{ status }}</h5>
<h5 class="resultScore">Score: {{ points }}</h5> <h5 class="resultText">Score: {{ points }}</h5>
<h5 class="resultText">Passing Score: {{ passing }}</h5>
<h5 class="resultText">Max Score: {{ max }}</h5>
<h5 class="resultText">Percentage: {{ percentage }}</h5>
<button class="defaultButton"><a href="{% url 'home' %}">Home</a></button> <button class="defaultButton"><a href="{% url 'home' %}">Home</a></button>
{# <p class="resultText">Percentage: 60%</p>#}
{# <p class="resultText">Correct answers: 3</p>#} {# <p class="resultText">Correct answers: 3</p>#}
{# <p class="resultText">Incorrect answers: 2</p>#} {# <p class="resultText">Incorrect answers: 2</p>#}
{# <p class="resultText">Total questions: 5</p>#} {# <p class="resultText">Total questions: 5</p>#}

View File

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<h1>Your history</h1>
{% for test in tests %}
<div class="solvedTestContainer">
<div class="mainTestName">
{{test.name}}
</div>
<div class="solvedTestText">Your score: {{test.score}}</div>
<div class="solvedTestText">Passing score: {{test.passing_score}}</div>
<div class="solvedTestText">Max score: {{test.max}}</div>
<div class="solvedTestText">Percentage: {{test.percentage}}</div>
<!-- <button><a href="/tests/{{test.id}}/show">Try again</a></button>-->
</div>
<br>
{% endfor %}
{% endblock %}

View File

@ -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),
),
]

View File

@ -41,6 +41,25 @@ class Test(models.Model):
points += question.points points += question.points
return 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): def name_and_passing_score(self):
return { return {
"name": self.name, "name": self.name,
@ -50,6 +69,8 @@ class Test(models.Model):
class SolvedTest(models.Model): class SolvedTest(models.Model):
score = models.IntegerField(default=0) score = models.IntegerField(default=0)
max = models.IntegerField(default=0)
percentage = models.IntegerField(default=0)
user = models.ForeignKey( user = models.ForeignKey(
"users.User", "users.User",
null=True, null=True,

View File

@ -53,15 +53,27 @@ def solvedTests(request):
formatted_tests.append({ formatted_tests.append({
"name": solved_test.test.name_and_passing_score()["name"], "name": solved_test.test.name_and_passing_score()["name"],
"passing_score": solved_test.test.name_and_passing_score()["passing_score"], "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 context['tests'] = formatted_tests
return render(request, 'myTests.html', context) return render(request, 'solvedTests.html', context)
def editTest(request): def editTest(request):
pass if request.POST:
# TODO # 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): class EditTestTemplateView(TemplateView):
PASSED = "passed" PASSED = "passed"
@ -144,6 +156,9 @@ class TestTemplateView(TemplateView):
def get_score(self, test: Test, answers): def get_score(self, test: Test, answers):
return test.get_score(answers) return test.get_score(answers)
def get_maxscore(self, test: Test, answers):
return test.get_maxscore(answers)
def formatted_responses(self, unformatted_json): def formatted_responses(self, unformatted_json):
formatted_response = list() formatted_response = list()
for question, answer in unformatted_json.items(): for question, answer in unformatted_json.items():
@ -158,13 +173,19 @@ class TestTemplateView(TemplateView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
test = Test.objects.get(id=kwargs.get("test_id")) test = Test.objects.get(id=kwargs.get("test_id"))
score = self.get_score(test, self.formatted_responses(request.POST)) 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 status = score >= test.passing_score
context = { context = {
"status": self.PASSED.get(status, self.UNKNOWN), "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( SolvedTest.objects.create(
score=score, score=score,
max=max,
percentage=int(score/max * 100),
user=request.user, user=request.user,
test=test test=test
) )

View File

@ -4,7 +4,7 @@ from django.urls import path
from users.views import UserModelViewSet from users.views import UserModelViewSet
from rest_framework_simplejwt.views import TokenObtainPairView from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.views import TokenRefreshView 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) router = DefaultRouter(trailing_slash=False)
@ -25,6 +25,7 @@ urlpatterns = [
path("password/reset/confirm", UserPasswordResetConfirmView.as_view(), name="resetPasswordConfirm"), path("password/reset/confirm", UserPasswordResetConfirmView.as_view(), name="resetPasswordConfirm"),
path("email/change", changeEmail, name='changeEmail'), path("email/change", changeEmail, name='changeEmail'),
path("name/change", changeName, name='changeName'), path("name/change", changeName, name='changeName'),
path("password/change", changePassword, name='changePassword'),
path("account", account, name='account') path("account", account, name='account')
] ]

View File

@ -152,3 +152,18 @@ def changeName(request):
u.save() u.save()
return redirect('account') return redirect('account')
return render(request, 'changeName.html') 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')