Newer
Older
"""
This file contains functionality to delete data to the database.
"""
from app.database.models import Blacklist, City, Competition, Role, Slide, User
from flask_restx import abort
from sqlalchemy import exc
try:
db.session.delete(item)
db.session.commit()
except:
db.session.rollback()
abort(codes.INTERNAL_SERVER_ERROR, f"Item of type {type(item)} could not be deleted")
default(item_component)
def _slide(item_slide):
for item_question in item_slide.questions:
question(item_question)
for item_component in item_slide.components:
default(item_component)
""" Deletes slide and updates order of other slides if neccesary. """
competition_id = item_slide.competition_id
slide_order = item_slide.order
_slide(item_slide)
# Update slide order for all slides after the deleted slide
slides_in_same_competition = dbc.get.slide_list(competition_id)
for other_slide in slides_in_same_competition:
other_slide.order -= 1
db.session.commit()
def team(item_team):
""" Deletes team, its question answers and the code. """
for item_question_answer in item_team.question_answers:
question_answers(item_question_answer)
for item_code in item_team.code:
code(item_code)
default(item_team)
def question(item_question):
""" Deletes question and its alternatives and answers. """
for item_question_answer in item_question.question_answers:
question_answers(item_question_answer)
for item_alternative in item_question.alternatives:
alternatives(item_alternative)
default(item_question)
default(item_alternatives)
def question_answers(item_question_answers):
default(item_question_answers)
def competition(item_competition):
""" Deletes competition, its slides, teams and codes. """
for item_code in item_competition.codes:
code(item_code)
def code(item_code):
""" Deletes competition code. """
default(item_code)