test visibility
This commit is contained in:
parent
181877a70d
commit
d9ad2c2f9d
@ -16,5 +16,5 @@ class CategoryModelViewSet(viewsets.ModelViewSet):
|
||||
def category(request, category_name):
|
||||
context = {}
|
||||
context['name'] = category_name
|
||||
context['tests'] = Test.objects.filter(category=category_name, invisible=False)
|
||||
context['tests'] = Test.objects.filter(category=category_name, visible=True)
|
||||
return render(request, 'category.html', context)
|
@ -10,7 +10,7 @@ def home(request):
|
||||
# TODO replace
|
||||
#context['tests'] = Test.objects.filter(owner=request.user)
|
||||
#context['tests'] = Test.objects.all
|
||||
context['tests'] = Test.objects.filter(invisible=False)
|
||||
context['tests'] = Test.objects.filter(visible=True)
|
||||
return render(request, 'home.html', context)
|
||||
|
||||
|
||||
|
@ -11,8 +11,11 @@
|
||||
<input id="name" type="text" name="name" value="Nowy test">
|
||||
<br>
|
||||
<br>
|
||||
<label for="invisible">Prywatny</label>
|
||||
<input type="checkbox" id="invisible" name="invisible" value="True">
|
||||
<label for="visible">Widzialność: </label>
|
||||
<select name="visible" id="visible">
|
||||
<option value="public">Publiczny</option>
|
||||
<option value="private">Prywatny</option>
|
||||
</select>
|
||||
<br>
|
||||
<br>
|
||||
<label for="category">Kategoria: </label>
|
||||
@ -39,7 +42,7 @@
|
||||
<br>
|
||||
<br>
|
||||
<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">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">Dodaj pytania</a>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -88,6 +88,15 @@
|
||||
<a href='' onclick="this.href='editName?name='+document.getElementById('name').value">Zmien nazwe</a>
|
||||
</button>
|
||||
</div>
|
||||
<label for="actual_visible">Aktualna widzialność: {% if test.visible %}Publiczny{% else %}Prywatny{% endif %}</label><br>
|
||||
<label for="visible">Widzialność: </label>
|
||||
<select name="visible" id="visible">
|
||||
<option value="public">Publiczny</option>
|
||||
<option value="private">Prywatny</option>
|
||||
</select>
|
||||
<button class="defaultButton">
|
||||
<a href='' onclick="this.href='editVisible?visible='+document.getElementById('visible').value">Zmien widzialność testu</a>
|
||||
</button>
|
||||
</div>
|
||||
<form method="post" novalidate>
|
||||
{% for question in test.questions.all %}
|
||||
|
@ -20,7 +20,8 @@ class TestManager(Manager):
|
||||
name=kwargs.get("name"),
|
||||
passing_score=kwargs.get("passing_score"),
|
||||
category=category,
|
||||
created_by=kwargs.get("user")
|
||||
created_by=kwargs.get("user"),
|
||||
visible=kwargs.get("visible")
|
||||
)
|
||||
for question in questions:
|
||||
question_instance = Question.objects.create(
|
||||
|
@ -14,7 +14,7 @@ class Test(models.Model):
|
||||
# related_name="tests"
|
||||
# )
|
||||
category = models.CharField(max_length=100)
|
||||
invisible = models.BooleanField(default=False)
|
||||
visible = models.BooleanField(default=True)
|
||||
created_by = models.ForeignKey(
|
||||
"users.User",
|
||||
null=True,
|
||||
|
@ -17,7 +17,7 @@ class TestSerializer(serializers.ModelSerializer):
|
||||
"name",
|
||||
"passing_score",
|
||||
"questions",
|
||||
"invisible",
|
||||
"visible",
|
||||
"category",
|
||||
)
|
||||
|
||||
|
@ -18,6 +18,7 @@ urlpatterns = [
|
||||
path('<int:test_id>/remove-question', RemoveQuestionFromExistingTest.as_view()),
|
||||
path('question/<int:question_id>/edit', EditQuestionTemplateView.as_view()),
|
||||
path('<int:test_id>/editName', editName, name="editName"),
|
||||
path('<int:test_id>/editVisible', editName, name="editVisible"),
|
||||
path('<int:test_id>/remove', deleteTest, name="deleteTest"),
|
||||
# path('delete', deleteTest, name="deleteTest"),
|
||||
path('add/test', addTest, name="newTest"),
|
||||
|
@ -24,10 +24,17 @@ def addTest(request):
|
||||
return render(request, 'createTest.html')
|
||||
|
||||
|
||||
def is_visible(visible):
|
||||
if visible =="public":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def addQuestions(request, **kwargs):
|
||||
if request.POST:
|
||||
name = request.GET.get("name")
|
||||
invisible = request.GET.get("invisible")
|
||||
visible = is_visible(request.GET.get("visible"))
|
||||
passing = request.GET.get("passing")
|
||||
category = request.GET.get("category")
|
||||
number_of_questions = request.GET.get("number_of_questions")
|
||||
@ -70,12 +77,8 @@ def addQuestions(request, **kwargs):
|
||||
answer4
|
||||
]
|
||||
})
|
||||
if invisible == "True":
|
||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
||||
invisible=True)
|
||||
else:
|
||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
||||
invisible=False)
|
||||
visible=visible)
|
||||
return redirect('home')
|
||||
return render(request, 'addQuestions.html')
|
||||
|
||||
@ -119,7 +122,8 @@ class AddQuestionToExistingTest(TemplateView):
|
||||
]
|
||||
})
|
||||
description = dict(request.POST)["desc"][0]
|
||||
Question.objects.addQuestionToExistingTest(name=description, answers=answers, test=Test.objects.get(id=kwargs["test_id"]))
|
||||
Question.objects.addQuestionToExistingTest(name=description, answers=answers,
|
||||
test=Test.objects.get(id=kwargs["test_id"]))
|
||||
return redirect(f'/tests/{kwargs["test_id"]}/edit')
|
||||
|
||||
|
||||
@ -140,7 +144,6 @@ class RemoveQuestionFromExistingTest(TemplateView):
|
||||
return redirect(f'/tests/{kwargs["test_id"]}/edit')
|
||||
|
||||
|
||||
|
||||
def myTests(request):
|
||||
context = {}
|
||||
user = request.user.id
|
||||
@ -180,7 +183,6 @@ def editTest(request):
|
||||
|
||||
|
||||
class EditTestTemplateView(TemplateView):
|
||||
|
||||
template_name = settings.BASE_DIR + f"/templates/editTest.html"
|
||||
|
||||
def get_queryset(self):
|
||||
@ -253,7 +255,19 @@ def deleteTest(request, test_id):
|
||||
Test.objects.filter(id=test_id).delete()
|
||||
return redirect('myTests')
|
||||
|
||||
|
||||
def editName(request, test_id):
|
||||
new_visible = request.GET["visible"]
|
||||
if new_visible == "public":
|
||||
new_visible = True
|
||||
else:
|
||||
new_visible = False
|
||||
test = Test.objects.get(id=test_id)
|
||||
test.visible = new_visible
|
||||
test.save()
|
||||
return redirect(f'/tests/{test_id}/edit')
|
||||
|
||||
def editVisible(request, test_id):
|
||||
new_name = request.GET["name"]
|
||||
test = Test.objects.get(id=test_id)
|
||||
test.name = new_name
|
||||
@ -316,12 +330,12 @@ class TestTemplateView(TemplateView):
|
||||
"points": score,
|
||||
"max": max,
|
||||
"passing": test.passing_score,
|
||||
"percentage": int(score/max * 100)
|
||||
"percentage": int(score / max * 100)
|
||||
}
|
||||
SolvedTest.objects.create(
|
||||
score=score,
|
||||
max=max,
|
||||
percentage=int(score/max * 100),
|
||||
percentage=int(score / max * 100),
|
||||
user=request.user,
|
||||
test=test
|
||||
)
|
||||
@ -329,6 +343,7 @@ class TestTemplateView(TemplateView):
|
||||
template = get_template(template_name)
|
||||
return HttpResponse(template.render(context))
|
||||
|
||||
|
||||
def testView(request):
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
||||
@ -373,6 +388,7 @@ class TestValidateAPIView(views.APIView):
|
||||
"points": score
|
||||
})
|
||||
|
||||
|
||||
class TestResultView(TemplateView):
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/result.html"
|
Loading…
Reference in New Issue
Block a user