Add social sharing

This commit is contained in:
Hubert Jankowski 2022-04-10 15:52:28 +02:00
parent 6b02a0bc94
commit 1c2d51c627
3 changed files with 14 additions and 7 deletions

View File

@ -54,6 +54,7 @@ INSTALLED_APPS = [
"rest_framework",
"rest_framework_simplejwt",
"django_extensions",
"django_social_share",
"users",
"trials",

View File

@ -1,4 +1,5 @@
{% extends "base.html" %}
{% load social_share %}
{% block title %}Test result{% endblock %}
@ -26,11 +27,13 @@
<h5 class="resultText">Maksymalny wynik: {{ max }}</h5>
<h5 class="resultText">Wynik procentowy: {{ percentage }}%</h5>
<button class="defaultButton"><a href="{% url 'home' %}">Strona główna</a></button>
{# <p class="resultText">Correct answers: 3</p>#}
{# <p class="resultText">Incorrect answers: 2</p>#}
{# <p class="resultText">Total questions: 5</p>#}
{% if password == "" %}
Udostępnij:
{% post_to_facebook object_or_url "Post to Facebook!" %}
{% post_to_linkedin object_or_url %}
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -341,7 +341,8 @@ class TestTemplateView(TemplateView):
"points": score,
"max": max,
"passing": test.passing_score,
"percentage": int(score / max * 100)
"percentage": int(score / max * 100),
"password": test.password
}
SolvedTest.objects.create(
score=score,
@ -352,12 +353,14 @@ class TestTemplateView(TemplateView):
)
template_name = "result.html"
template = get_template(template_name)
return HttpResponse(template.render(context))
return HttpResponse(template.render(context, request))
def TestPasswordTemplateView(request, test_id):
if request.POST:
test = Test.objects.get(id=test_id)
if test.password == "":
return redirect(f'/tests/{test_id}/show')
if request.POST:
if request.POST["password"] == test.password:
return redirect(f'/tests/{test_id}/show')
return render(request, 'testPassword.html')