Skip to content
Snippets Groups Projects
Commit b56c81e4 authored by Victor Löfgren's avatar Victor Löfgren
Browse files

add: question component

parent fa8c25cd
No related branches found
No related tags found
1 merge request!110add: question component
Pipeline #42877 passed
...@@ -39,6 +39,13 @@ def get_code_claims(item_code): ...@@ -39,6 +39,13 @@ def get_code_claims(item_code):
return {"view": item_code.view_type.name, "competition_id": item_code.competition_id, "team_id": item_code.team_id} return {"view": item_code.view_type.name, "competition_id": item_code.competition_id, "team_id": item_code.team_id}
@api.route("/test")
class AuthSignup(Resource):
@protect_route(allowed_roles=["Admin"], allowed_views=["*"])
def get(self):
return "ok"
@api.route("/signup") @api.route("/signup")
class AuthSignup(Resource): class AuthSignup(Resource):
@protect_route(allowed_roles=["Admin"]) @protect_route(allowed_roles=["Admin"])
......
...@@ -18,7 +18,8 @@ component_parser_add.add_argument("h", type=int, default=1, location="json") ...@@ -18,7 +18,8 @@ component_parser_add.add_argument("h", type=int, default=1, location="json")
component_parser_add.add_argument("type_id", type=int, required=True, location="json") component_parser_add.add_argument("type_id", type=int, required=True, location="json")
component_parser_add.add_argument("view_type_id", type=int, required=True, location="json") component_parser_add.add_argument("view_type_id", type=int, required=True, location="json")
component_parser_add.add_argument("text", type=str, default=None, location="json") component_parser_add.add_argument("text", type=str, default=None, location="json")
component_parser_add.add_argument("media_id", type=str, default=None, location="json") component_parser_add.add_argument("media_id", type=int, default=None, location="json")
component_parser_add.add_argument("question_id", type=int, default=None, location="json")
component_parser_edit = reqparse.RequestParser() component_parser_edit = reqparse.RequestParser()
component_parser_edit.add_argument("x", type=str, default=sentinel, location="json") component_parser_edit.add_argument("x", type=str, default=sentinel, location="json")
...@@ -26,7 +27,8 @@ component_parser_edit.add_argument("y", type=int, default=sentinel, location="js ...@@ -26,7 +27,8 @@ component_parser_edit.add_argument("y", type=int, default=sentinel, location="js
component_parser_edit.add_argument("w", type=int, default=sentinel, location="json") component_parser_edit.add_argument("w", type=int, default=sentinel, location="json")
component_parser_edit.add_argument("h", type=int, default=sentinel, location="json") component_parser_edit.add_argument("h", type=int, default=sentinel, location="json")
component_parser_edit.add_argument("text", type=str, default=sentinel, location="json") component_parser_edit.add_argument("text", type=str, default=sentinel, location="json")
component_parser_edit.add_argument("media_id", type=str, default=sentinel, location="json") component_parser_edit.add_argument("media_id", type=int, default=sentinel, location="json")
component_parser_edit.add_argument("question_id", type=int, default=sentinel, location="json")
@api.route("/<component_id>") @api.route("/<component_id>")
......
...@@ -165,3 +165,4 @@ class ComponentSchema(BaseSchema): ...@@ -165,3 +165,4 @@ class ComponentSchema(BaseSchema):
text = fields.fields.String() text = fields.fields.String()
media = fields.Nested(MediaSchema, many=False) media = fields.Nested(MediaSchema, many=False)
question_id = fields.fields.Integer()
\ No newline at end of file
...@@ -20,6 +20,7 @@ from app.database.models import ( ...@@ -20,6 +20,7 @@ from app.database.models import (
Question, Question,
QuestionAlternative, QuestionAlternative,
QuestionAnswer, QuestionAnswer,
QuestionComponent,
QuestionType, QuestionType,
Role, Role,
Slide, Slide,
...@@ -37,6 +38,8 @@ from sqlalchemy.orm import relation ...@@ -37,6 +38,8 @@ from sqlalchemy.orm import relation
from sqlalchemy.orm.session import sessionmaker from sqlalchemy.orm.session import sessionmaker
from flask import current_app from flask import current_app
from app.database.types import ID_IMAGE_COMPONENT, ID_QUESTION_COMPONENT, ID_TEXT_COMPONENT
def db_add(item): def db_add(item):
""" """
...@@ -79,12 +82,15 @@ def component(type_id, slide_id, view_type_id, x=0, y=0, w=0, h=0, **data): ...@@ -79,12 +82,15 @@ def component(type_id, slide_id, view_type_id, x=0, y=0, w=0, h=0, **data):
w *= ratio w *= ratio
h *= ratio h *= ratio
if type_id == 1: if type_id == ID_TEXT_COMPONENT:
item = db_add(TextComponent(slide_id, type_id, view_type_id, x, y, w, h)) item = db_add(TextComponent(slide_id, type_id, view_type_id, x, y, w, h))
item.text = data.get("text") item.text = data.get("text")
elif type_id == 2: elif type_id == ID_IMAGE_COMPONENT:
item = db_add(ImageComponent(slide_id, type_id, view_type_id, x, y, w, h)) item = db_add(ImageComponent(slide_id, type_id, view_type_id, x, y, w, h))
item.media_id = data.get("media_id") item.media_id = data.get("media_id")
elif type_id == ID_QUESTION_COMPONENT:
item = db_add(QuestionComponent(slide_id, type_id, view_type_id, x, y, w, h))
item.question_id = data.get("question_id")
else: else:
abort(codes.BAD_REQUEST, f"Invalid type_id{type_id}") abort(codes.BAD_REQUEST, f"Invalid type_id{type_id}")
......
...@@ -4,6 +4,7 @@ This file contains functionality to copy and duplicate data to the database. ...@@ -4,6 +4,7 @@ This file contains functionality to copy and duplicate data to the database.
from app.database.controller import add, get, search, utils from app.database.controller import add, get, search, utils
from app.database.models import Question from app.database.models import Question
from app.database.types import ID_IMAGE_COMPONENT, ID_QUESTION_COMPONENT, ID_TEXT_COMPONENT
def _alternative(item_old, question_id): def _alternative(item_old, question_id):
...@@ -38,10 +39,12 @@ def _component(item_component, item_slide_new): ...@@ -38,10 +39,12 @@ def _component(item_component, item_slide_new):
component item to the specified slide. component item to the specified slide.
""" """
data = {} data = {}
if item_component.type_id == 1: if item_component.type_id == ID_TEXT_COMPONENT:
data["text"] = item_component.text data["text"] = item_component.text
elif item_component.type_id == 2: elif item_component.type_id == ID_IMAGE_COMPONENT:
data["media_id"] = item_component.media_id data["media_id"] = item_component.media_id
elif item_component.type_id == ID_QUESTION_COMPONENT:
data["question_id"] = item_component.question_id
add.component( add.component(
item_component.type_id, item_component.type_id,
item_slide_new.id, item_slide_new.id,
......
from app.core import bcrypt, db from app.core import bcrypt, db
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from app.database.types import ID_IMAGE_COMPONENT, ID_TEXT_COMPONENT from app.database.types import ID_IMAGE_COMPONENT, ID_QUESTION_COMPONENT, ID_TEXT_COMPONENT
STRING_SIZE = 254 STRING_SIZE = 254
...@@ -224,6 +224,13 @@ class ImageComponent(Component): ...@@ -224,6 +224,13 @@ class ImageComponent(Component):
__mapper_args__ = {"polymorphic_identity": ID_IMAGE_COMPONENT} __mapper_args__ = {"polymorphic_identity": ID_IMAGE_COMPONENT}
class QuestionComponent(Component):
question_id = db.Column(db.Integer, db.ForeignKey("question.id"), nullable=True)
# __tablename__ = None
__mapper_args__ = {"polymorphic_identity": ID_QUESTION_COMPONENT}
class Code(db.Model): class Code(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Text, unique=True) code = db.Column(db.Text, unique=True)
......
ID_TEXT_COMPONENT = 1 ID_TEXT_COMPONENT = 1
ID_IMAGE_COMPONENT = 2 ID_IMAGE_COMPONENT = 2
ID_QUESTION_COMPONENT = 3
\ No newline at end of file
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