Skip to content
Snippets Groups Projects
Commit 0e07d10f authored by Josef Olsson's avatar Josef Olsson
Browse files

Add functionality to copy a slide

parent dba4f2b5
No related branches found
No related tags found
1 merge request!78Resolve "Duplicate slide and competition api"
"""
This file contains functionality to copy and duplicate data to the database.
"""
from app.database.controller import add, utils
from app.database.models import Question, Slide
from flask_sqlalchemy import utils
def _question(item_question_old, slide_id):
"""
Internal function. Makes a copy of the provided question item to the
specified slide. Does not copy team, question answers or alternatives.
"""
item_question_new = add.db_add(
Question(
item_question_old.name,
item_question_old.total_score,
item_question_old.type_id,
slide_id,
)
)
# TODO: Add question alternatives
# for item_alternatives in item_question_old.alternatives:
# dbc.add.alternatives()
return item_question_new
def _component(item_component, item_slide_new):
"""
Internal function. Makes a copy of the provided
component item to the specified slide.
"""
add.component(
item_component.type_id,
item_slide_new,
item_component.data,
item_component.x,
item_component.y,
item_component.w,
item_component.h,
)
def slide(item_slide_old):
"""
Deep copies a slide to the same competition.
Does not copy team, question answers or alternatives.
"""
order = Slide.query.filter(
Slide.competition_id == item_slide_old.item_competition.id
).count() # first element has index 0
item_slide_new = add.db_add(Slide(order, item_slide_old.item_competition.id))
# Copy all fields
item_slide_new.title = item_slide_old.title
item_slide_new.body = item_slide_old.body
item_slide_new.timer = item_slide_old.timer
item_slide_new.settings = item_slide_old.settings
# TODO: Add background image
for item_component in item_slide_old.components:
_component(item_slide_new, item_component)
for item_question in item_slide_old.questions:
_question(item_question, item_slide_new.id)
utils.commit_and_refresh(item_slide_new)
return item_slide_new
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment