Skip to content
Snippets Groups Projects
Commit e4568658 authored by borzechof99's avatar borzechof99 :whale2:
Browse files

Add Linter and Black Adherence

parent 450675e8
No related branches found
No related tags found
No related merge requests found
...@@ -9,3 +9,4 @@ disable=line-too-long, ...@@ -9,3 +9,4 @@ disable=line-too-long,
abstract-method, abstract-method,
arguments-differ, arguments-differ,
invalid-name invalid-name
no-else-raise
...@@ -6,17 +6,35 @@ from django.db import migrations, models ...@@ -6,17 +6,35 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('quiz', '0006_auto_20210612_1230'), ("quiz", "0006_auto_20210612_1230"),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='QuestionOrder', name="QuestionOrder",
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('order_id', models.IntegerField(null=True)), "id",
('type_of_slot', models.TextField(choices=[('question', 'question'), ('snack', 'snack'), ('activity', 'activity')], default='snack')), models.BigAutoField(
('question_id', models.IntegerField(default=-1)), auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("order_id", models.IntegerField(null=True)),
(
"type_of_slot",
models.TextField(
choices=[
("question", "question"),
("snack", "snack"),
("activity", "activity"),
],
default="snack",
),
),
("question_id", models.IntegerField(default=-1)),
], ],
), ),
] ]
...@@ -189,12 +189,19 @@ class QuestionOrderManager(models.Manager): ...@@ -189,12 +189,19 @@ class QuestionOrderManager(models.Manager):
""" """
def create_entry_at_end(self, type_of_slot, question_id=None): def create_entry_at_end(self, type_of_slot, question_id=None):
"""
Creates a new OrderEntry at the end of the current Order (so the object gets given the highest order_id)
"""
if type_of_slot == "question" and question_id is None: if type_of_slot == "question" and question_id is None:
raise ValueError( raise ValueError(
"A Question ID must be given if the Type of the Slot is Question" "A Question ID must be given if the Type of the Slot is Question"
) )
elif type_of_slot not in ["question", "snack", "activity"]: elif type_of_slot not in [
"question",
"snack",
"activity",
]:
raise ValueError( raise ValueError(
f'{type_of_slot} not in valid choice list ["question", "snack", "activity"]' f'{type_of_slot} not in valid choice list ["question", "snack", "activity"]'
) )
...@@ -221,12 +228,14 @@ class QuestionOrderManager(models.Manager): ...@@ -221,12 +228,14 @@ class QuestionOrderManager(models.Manager):
return entry return entry
def delete_entry(self, given_order_id): def delete_entry(self, given_order_id):
"""
Delete an Entry in the QuestionOrder Database and decrement every object that had a larger order_id than the one deleted
"""
# Delete must be called on an instance, not a queryset # Delete must be called on an instance, not a queryset
entry = self.get(order_id = given_order_id) entry = self.get(order_id=given_order_id)
entry.delete() entry.delete()
larger_entries = self.filter(order_id__gte=given_order_id) larger_entries = self.filter(order_id__gte=given_order_id)
# The Primary Key of an Object cannot be changed, really, instead a new Object is created when the PK changes # The Primary Key of an Object cannot be changed, really, instead a new Object is created when the PK changes
...@@ -237,9 +246,11 @@ class QuestionOrderManager(models.Manager): ...@@ -237,9 +246,11 @@ class QuestionOrderManager(models.Manager):
entry.save() entry.save()
def delete_entry_by_question_id(self, given_question_id): def delete_entry_by_question_id(self, given_question_id):
"""
Delete an Entry in the QuestionOrder DB by the Question_ID
"""
queryset = self.filter(question_id=given_question_id)
queryset = self.filter(question_id = given_question_id)
if queryset.count() == 0: if queryset.count() == 0:
# If the Question doesn't exist in the Order, we don't need to do anything # If the Question doesn't exist in the Order, we don't need to do anything
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment