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;
}
.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{

View File

@ -9,7 +9,7 @@
<h5 class="accountInfoName">{{user.first_name}} {{user.last_name}}</h5>
<p class="accountInfoText"><b>Email:</b> {{user.email}}</p>
<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>
</div>
{% endblock %}

View File

@ -6,8 +6,10 @@
<div class="accountInfoContainer ">
<form method="post">
<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>
<a class="returnLink" href="{% url 'account' %}">Back to dashboard</a>
<div class="linkDefault">
<a href="{% url 'account' %}">Back to dashboard</a>
</div>
</div>
{% 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="submit" value="Change name"><br><br>
</form>
<a class="returnLink" href="{% url 'account' %}">Back to dashboard</a>
<div class="linkDefault">
<a href="{% url 'account' %}">Back to dashboard</a>
</div>
</div>
{% 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">
<br>
<br>
<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>
</div>
{% endblock %}

View File

@ -18,9 +18,10 @@
<!-- 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.
</div>
<div class="doubleButton">
<div class="tripleButton">
<button><a href="/tests/{{test.id}}/show">Start</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>
<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">
<div class="resultBody">
<h5 class="resultMsg">
Quite good! All the best for next quiz!
<!-- {% if max_score == 100 %}-->
<!-- Idealnie, widzę że ten temat nie ma dla ciebie tajemnic! -->
<!-- {% elif max_score >= 75 %}-->
<!-- Bardzo dobrze, ale są jeszcze pewne braki ;)-->
<!-- {% elif max_score >= 50 %}-->
<!-- Nie jest źle, wiedziałeś więcej niż mniej-->
<!-- {% elif max_score >= 25 %}-->
<!-- Masz spore braki, powinieneś trochę więcej się pouczyć-->
<!-- {% else %}-->
<!-- Słabiutko, ale następnym razem będzie lepiej-->
<!-- {% endif %}-->
<!-- 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 %}
</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>
{# <p class="resultText">Percentage: 60%</p>#}
{# <p class="resultText">Correct answers: 3</p>#}
{# <p class="resultText">Incorrect answers: 2</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
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,

View File

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

View File

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

View File

@ -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')