Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-warumkeinrust
Backend
Commits
4dd5c4d9
Commit
4dd5c4d9
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Add Linter and Black Adherence
parent
527aaa41
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.pylintrc
+2
-1
2 additions, 1 deletion
.pylintrc
unisportomat/quiz/migrations/0007_questionorder.py
+24
-6
24 additions, 6 deletions
unisportomat/quiz/migrations/0007_questionorder.py
unisportomat/quiz/models.py
+16
-5
16 additions, 5 deletions
unisportomat/quiz/models.py
with
42 additions
and
12 deletions
.pylintrc
+
2
−
1
View file @
4dd5c4d9
...
...
@@ -3,4 +3,5 @@ fail-under=10
[MESSAGES CONTROL]
disable=line-too-long,
django-not-configured
django-not-configured,
no-else-raise
\ No newline at end of file
This diff is collapsed.
Click to expand it.
unisportomat/quiz/migrations/0007_questionorder.py
+
24
−
6
View file @
4dd5c4d9
...
...
@@ -6,17 +6,35 @@ from django.db import migrations, models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
quiz
'
,
'
0006_auto_20210612_1230
'
),
(
"
quiz
"
,
"
0006_auto_20210612_1230
"
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
QuestionOrder
'
,
name
=
"
QuestionOrder
"
,
fields
=
[
(
'
id
'
,
models
.
BigAutoField
(
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
)),
(
"
id
"
,
models
.
BigAutoField
(
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
)),
],
),
]
This diff is collapsed.
Click to expand it.
unisportomat/quiz/models.py
+
16
−
5
View file @
4dd5c4d9
...
...
@@ -102,12 +102,19 @@ class QuestionOrderManager(models.Manager):
"""
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
:
raise
ValueError
(
"
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
(
f
'
{
type_of_slot
}
not in valid choice list [
"
question
"
,
"
snack
"
,
"
activity
"
]
'
)
...
...
@@ -134,12 +141,14 @@ class QuestionOrderManager(models.Manager):
return
entry
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
entry
=
self
.
get
(
order_id
=
given_order_id
)
entry
=
self
.
get
(
order_id
=
given_order_id
)
entry
.
delete
()
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
...
...
@@ -150,9 +159,11 @@ class QuestionOrderManager(models.Manager):
entry
.
save
()
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 the Question doesn't exist in the Order, we don't need to do anything
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment