diff --git a/categories/views.py b/categories/views.py index e83be2d..4ec28df 100644 --- a/categories/views.py +++ b/categories/views.py @@ -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) \ No newline at end of file diff --git a/config/views.py b/config/views.py index 209b7f3..a6157b1 100644 --- a/config/views.py +++ b/config/views.py @@ -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) diff --git a/templates/createTest.html b/templates/createTest.html index e412bd7..8a08049 100644 --- a/templates/createTest.html +++ b/templates/createTest.html @@ -11,8 +11,11 @@

- - + +

@@ -39,7 +42,7 @@

diff --git a/templates/editTest.html b/templates/editTest.html index 2e3c9de..f53f6d4 100644 --- a/templates/editTest.html +++ b/templates/editTest.html @@ -88,6 +88,15 @@ Zmien nazwe +
+ + +
{% for question in test.questions.all %} diff --git a/trials/managers.py b/trials/managers.py index 378fd4c..7939799 100644 --- a/trials/managers.py +++ b/trials/managers.py @@ -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( diff --git a/trials/models.py b/trials/models.py index 55a4633..5c990b1 100644 --- a/trials/models.py +++ b/trials/models.py @@ -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, diff --git a/trials/serializers.py b/trials/serializers.py index 6c00b8c..fa5683c 100644 --- a/trials/serializers.py +++ b/trials/serializers.py @@ -17,7 +17,7 @@ class TestSerializer(serializers.ModelSerializer): "name", "passing_score", "questions", - "invisible", + "visible", "category", ) diff --git a/trials/urls.py b/trials/urls.py index 529d778..f9c3adf 100644 --- a/trials/urls.py +++ b/trials/urls.py @@ -18,6 +18,7 @@ urlpatterns = [ path('/remove-question', RemoveQuestionFromExistingTest.as_view()), path('question//edit', EditQuestionTemplateView.as_view()), path('/editName', editName, name="editName"), + path('/editVisible', editName, name="editVisible"), path('/remove', deleteTest, name="deleteTest"), # path('delete', deleteTest, name="deleteTest"), path('add/test', addTest, name="newTest"), diff --git a/trials/views.py b/trials/views.py index 0f65c3c..23d7bbe 100644 --- a/trials/views.py +++ b/trials/views.py @@ -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) + Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user, + 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" \ No newline at end of file + template_name = settings.BASE_DIR + f"/templates/result.html"