feature/visibility #32

Merged
s470631 merged 3 commits from feature/visibility into master 2022-04-09 13:04:09 +02:00
8 changed files with 52 additions and 3 deletions
Showing only changes of commit 181877a70d - Show all commits

View File

@ -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)
context['tests'] = Test.objects.filter(category=category_name, invisible=False)
return render(request, 'category.html', context)

View File

@ -9,7 +9,8 @@ def home(request):
context = {}
# TODO replace
#context['tests'] = Test.objects.filter(owner=request.user)
context['tests'] = Test.objects.all
#context['tests'] = Test.objects.all
context['tests'] = Test.objects.filter(invisible=False)
return render(request, 'home.html', context)

View File

@ -11,6 +11,10 @@
<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">
<br>
<br>
<label for="category">Kategoria: </label>
<select name="category" id="category">
<option value="JezykPolski">Język Polski</option>

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2022-03-30 19:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('trials', '0011_auto_20220123_1633'),
]
operations = [
migrations.AddField(
model_name='test',
name='unvisible',
field=models.BooleanField(default=False),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2022-03-30 20:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('trials', '0012_test_unvisible'),
]
operations = [
migrations.RenameField(
model_name='test',
old_name='unvisible',
new_name='invisible',
),
]

View File

@ -14,6 +14,7 @@ class Test(models.Model):
# related_name="tests"
# )
category = models.CharField(max_length=100)
invisible = models.BooleanField(default=False)
created_by = models.ForeignKey(
"users.User",
null=True,

View File

@ -17,6 +17,7 @@ class TestSerializer(serializers.ModelSerializer):
"name",
"passing_score",
"questions",
"invisible",
"category",
)

View File

@ -27,6 +27,7 @@ def addTest(request):
def addQuestions(request, **kwargs):
if request.POST:
name = request.GET.get("name")
invisible = request.GET.get("invisible")
passing = request.GET.get("passing")
category = request.GET.get("category")
number_of_questions = request.GET.get("number_of_questions")
@ -69,7 +70,12 @@ def addQuestions(request, **kwargs):
answer4
]
})
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user)
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)
return redirect('home')
return render(request, 'addQuestions.html')