add password to tests #34
@ -18,6 +18,10 @@
|
|||||||
</select>
|
</select>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
<label for="password">Hasło: </label>
|
||||||
|
<input id="password" type="text" name="password" value=""> - Jeśli test ma nie posiadać hasła pozostaw puste pole
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
<label for="category">Kategoria: </label>
|
<label for="category">Kategoria: </label>
|
||||||
<select name="category" id="category">
|
<select name="category" id="category">
|
||||||
<option value="JezykPolski">Język Polski</option>
|
<option value="JezykPolski">Język Polski</option>
|
||||||
@ -42,7 +46,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<button class="defaultButton">
|
<button class="defaultButton">
|
||||||
<a href='' onclick="this.href='questions?passing='+document.getElementById('passing').value + '&name=' +document.getElementById('name').value + '&category='+document.getElementById('category').value+'&number_of_questions='+document.getElementById('questions').value+'&visible='+document.getElementById('visible').value">Dodaj pytania</a>
|
<a href='' onclick="this.href='questions?passing='+document.getElementById('passing').value + '&name=' +document.getElementById('name').value + '&category='+document.getElementById('category').value+'&number_of_questions='+document.getElementById('questions').value+'&visible='+document.getElementById('visible').value+'&password='+document.getElementById('password').value">Dodaj pytania</a>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -97,6 +97,12 @@
|
|||||||
<button class="defaultButton">
|
<button class="defaultButton">
|
||||||
<a href='' onclick="this.href='editVisible?visible='+document.getElementById('visible').value">Zmien widzialność testu</a>
|
<a href='' onclick="this.href='editVisible?visible='+document.getElementById('visible').value">Zmien widzialność testu</a>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<label for="password"><h2>Hasło:</h2></label>
|
||||||
|
<input id="password" type="text" name="password" value="">
|
||||||
|
<button class="defaultButton">
|
||||||
|
<a href='' onclick="this.href='editPassword?password='+document.getElementById('password').value">Zmien hasło</a>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" novalidate>
|
<form method="post" novalidate>
|
||||||
{% for question in test.questions.all %}
|
{% for question in test.questions.all %}
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
<!-- <div class="mainTestDesc">-->
|
<!-- <div class="mainTestDesc">-->
|
||||||
<!-- 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>-->
|
||||||
<button><a href="/tests/{{test.id}}/show">Rozwiąż</a></button>
|
{# <button><a href="/tests/{{test.id}}/show">Rozwiąż</a></button>#}
|
||||||
|
<button><a href="/tests/{{test.id}}/password">Rozwiąż</a></button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
7
templates/testPassword.html
Normal file
7
templates/testPassword.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<form method="post" novalidate>
|
||||||
|
<label for="password"><h2>Hasło:</h2></label>
|
||||||
|
<input id="password" type="text" name="password" value="">
|
||||||
|
<div class="testContent">
|
||||||
|
<input type="submit" value="Zatwierdź">
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -21,7 +21,8 @@ class TestManager(Manager):
|
|||||||
passing_score=kwargs.get("passing_score"),
|
passing_score=kwargs.get("passing_score"),
|
||||||
category=category,
|
category=category,
|
||||||
created_by=kwargs.get("user"),
|
created_by=kwargs.get("user"),
|
||||||
visible=kwargs.get("visible")
|
visible=kwargs.get("visible"),
|
||||||
|
password=kwargs.get("password")
|
||||||
)
|
)
|
||||||
for question in questions:
|
for question in questions:
|
||||||
question_instance = Question.objects.create(
|
question_instance = Question.objects.create(
|
||||||
|
18
trials/migrations/0015_test_password.py
Normal file
18
trials/migrations/0015_test_password.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.9 on 2022-04-09 11:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('trials', '0014_auto_20220409_1224'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='test',
|
||||||
|
name='password',
|
||||||
|
field=models.CharField(default='', max_length=100),
|
||||||
|
),
|
||||||
|
]
|
@ -21,6 +21,7 @@ class Test(models.Model):
|
|||||||
related_name="tests",
|
related_name="tests",
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
|
password = models.CharField(max_length=100, default="")
|
||||||
|
|
||||||
objects = TestManager()
|
objects = TestManager()
|
||||||
|
|
||||||
|
@ -4,13 +4,14 @@ from rest_framework.routers import DefaultRouter
|
|||||||
from trials.views import TestModelViewSet
|
from trials.views import TestModelViewSet
|
||||||
from trials.views import TestTemplateView
|
from trials.views import TestTemplateView
|
||||||
from trials.views import TestValidateAPIView
|
from trials.views import TestValidateAPIView
|
||||||
from trials.views import TestResultView, addTest, addQuestions, myTests, editTest, solvedTests, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName
|
from trials.views import TestResultView, addTest, addQuestions, myTests, editTest, solvedTests, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName, editVisible, editPassword, TestPasswordTemplateView
|
||||||
|
|
||||||
router = DefaultRouter(trailing_slash=False)
|
router = DefaultRouter(trailing_slash=False)
|
||||||
router.register("items", TestModelViewSet)
|
router.register("items", TestModelViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('<int:test_id>/show', TestTemplateView.as_view()),
|
path('<int:test_id>/show', TestTemplateView.as_view()),
|
||||||
|
path('<int:test_id>/password', TestPasswordTemplateView),
|
||||||
path('<int:test_id>/mark', TestValidateAPIView.as_view()),
|
path('<int:test_id>/mark', TestValidateAPIView.as_view()),
|
||||||
path('<int:test_id>/result', TestResultView.as_view()),
|
path('<int:test_id>/result', TestResultView.as_view()),
|
||||||
path('<int:test_id>/edit', EditTestTemplateView.as_view()),
|
path('<int:test_id>/edit', EditTestTemplateView.as_view()),
|
||||||
@ -18,7 +19,8 @@ urlpatterns = [
|
|||||||
path('<int:test_id>/remove-question', RemoveQuestionFromExistingTest.as_view()),
|
path('<int:test_id>/remove-question', RemoveQuestionFromExistingTest.as_view()),
|
||||||
path('question/<int:question_id>/edit', EditQuestionTemplateView.as_view()),
|
path('question/<int:question_id>/edit', EditQuestionTemplateView.as_view()),
|
||||||
path('<int:test_id>/editName', editName, name="editName"),
|
path('<int:test_id>/editName', editName, name="editName"),
|
||||||
path('<int:test_id>/editVisible', editName, name="editVisible"),
|
path('<int:test_id>/editVisible', editVisible, name="editVisible"),
|
||||||
|
path('<int:test_id>/editPassword', editPassword, name="editPassword"),
|
||||||
path('<int:test_id>/remove', deleteTest, name="deleteTest"),
|
path('<int:test_id>/remove', deleteTest, name="deleteTest"),
|
||||||
# path('delete', deleteTest, name="deleteTest"),
|
# path('delete', deleteTest, name="deleteTest"),
|
||||||
path('add/test', addTest, name="newTest"),
|
path('add/test', addTest, name="newTest"),
|
||||||
|
@ -38,6 +38,7 @@ def addQuestions(request, **kwargs):
|
|||||||
passing = request.GET.get("passing")
|
passing = request.GET.get("passing")
|
||||||
category = request.GET.get("category")
|
category = request.GET.get("category")
|
||||||
number_of_questions = request.GET.get("number_of_questions")
|
number_of_questions = request.GET.get("number_of_questions")
|
||||||
|
password = request.GET.get("password")
|
||||||
user = request.user
|
user = request.user
|
||||||
# k = dict(request.POST)["desc"]
|
# k = dict(request.POST)["desc"]
|
||||||
questions = []
|
questions = []
|
||||||
@ -78,7 +79,7 @@ def addQuestions(request, **kwargs):
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
||||||
visible=visible)
|
visible=visible, password=password)
|
||||||
return redirect('home')
|
return redirect('home')
|
||||||
return render(request, 'addQuestions.html')
|
return render(request, 'addQuestions.html')
|
||||||
|
|
||||||
@ -258,7 +259,7 @@ def deleteTest(request, test_id):
|
|||||||
return redirect('myTests')
|
return redirect('myTests')
|
||||||
|
|
||||||
|
|
||||||
def editName(request, test_id):
|
def editVisible(request, test_id):
|
||||||
new_visible = request.GET["visible"]
|
new_visible = request.GET["visible"]
|
||||||
if new_visible == "public":
|
if new_visible == "public":
|
||||||
new_visible = True
|
new_visible = True
|
||||||
@ -269,7 +270,7 @@ def editName(request, test_id):
|
|||||||
test.save()
|
test.save()
|
||||||
return redirect(f'/tests/{test_id}/edit')
|
return redirect(f'/tests/{test_id}/edit')
|
||||||
|
|
||||||
def editVisible(request, test_id):
|
def editName(request, test_id):
|
||||||
new_name = request.GET["name"]
|
new_name = request.GET["name"]
|
||||||
test = Test.objects.get(id=test_id)
|
test = Test.objects.get(id=test_id)
|
||||||
test.name = new_name
|
test.name = new_name
|
||||||
@ -277,6 +278,14 @@ def editVisible(request, test_id):
|
|||||||
return redirect(f'/tests/{test_id}/edit')
|
return redirect(f'/tests/{test_id}/edit')
|
||||||
|
|
||||||
|
|
||||||
|
def editPassword(request, test_id):
|
||||||
|
new_password = request.GET["password"]
|
||||||
|
test = Test.objects.get(id=test_id)
|
||||||
|
test.password = new_password
|
||||||
|
test.save()
|
||||||
|
return redirect(f'/tests/{test_id}/edit')
|
||||||
|
|
||||||
|
|
||||||
class TestModelViewSet(viewsets.ModelViewSet):
|
class TestModelViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Test.objects.all()
|
queryset = Test.objects.all()
|
||||||
serializer_class = TestSerializer
|
serializer_class = TestSerializer
|
||||||
@ -346,6 +355,14 @@ class TestTemplateView(TemplateView):
|
|||||||
return HttpResponse(template.render(context))
|
return HttpResponse(template.render(context))
|
||||||
|
|
||||||
|
|
||||||
|
def TestPasswordTemplateView(request, test_id):
|
||||||
|
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')
|
||||||
|
|
||||||
|
|
||||||
def testView(request):
|
def testView(request):
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
||||||
|
Loading…
Reference in New Issue
Block a user