diff --git a/config/settings.py b/config/settings.py index 2ff59c6..fb0204c 100644 --- a/config/settings.py +++ b/config/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ "rest_framework", "rest_framework_simplejwt", "django_extensions", + "django_social_share", "users", "trials", diff --git a/templates/result.html b/templates/result.html index 788f32e..aec8b7b 100644 --- a/templates/result.html +++ b/templates/result.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load social_share %} {% block title %}Test result{% endblock %} @@ -26,11 +27,13 @@
Maksymalny wynik: {{ max }}
Wynik procentowy: {{ percentage }}%
-{#

Correct answers: 3

#} -{#

Incorrect answers: 2

#} -{#

Total questions: 5

#} - + {% if password == "" %} + Udostępnij: + {% post_to_facebook object_or_url "Post to Facebook!" %} + {% post_to_linkedin object_or_url %} + {% endif %} + {% endblock %} diff --git a/trials/views.py b/trials/views.py index 367b717..a799360 100644 --- a/trials/views.py +++ b/trials/views.py @@ -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): + test = Test.objects.get(id=test_id) + if test.password == "": + return redirect(f'/tests/{test_id}/show') if request.POST: - test = Test.objects.get(id=test_id) if request.POST["password"] == test.password: return redirect(f'/tests/{test_id}/show') return render(request, 'testPassword.html')