Skip to content
Snippets Groups Projects
Commit 6c015dd1 authored by robban64's avatar robban64
Browse files

fix: replaced code.pointer with competition_id and add team_id to code

parent fb697a32
No related branches found
No related tags found
No related merge requests found
Pipeline #42164 passed
from marshmallow.decorators import pre_dump
import app.database.models as models
from app.core import ma
from marshmallow_sqlalchemy import fields
......@@ -37,8 +38,9 @@ class CodeSchema(IdNameSchema):
id = ma.auto_field()
code = ma.auto_field()
pointer = ma.auto_field()
view_type_id = ma.auto_field()
competition_id = fields.fields.Integer()
team_id = fields.fields.Integer()
class ViewTypeSchema(IdNameSchema):
......
......@@ -131,11 +131,11 @@ def question_answer(data, score, question_id, team_id):
return db_add(QuestionAnswer(data, score, question_id, team_id))
def code(pointer, view_type_id):
def code(view_type_id, competition_id=None, team_id=None):
""" Adds a code to the database using the provided arguments. """
code_string = utils.generate_unique_code()
return db_add(Code(code_string, pointer, view_type_id))
return db_add(Code(code_string, view_type_id, competition_id, team_id))
def team(name, competition_id):
......@@ -144,7 +144,7 @@ def team(name, competition_id):
item = db_add(Team(name, competition_id))
# Add code for the team
code(item.id, 1)
code(1, competition_id, item.id)
return item
......@@ -189,10 +189,9 @@ def competition(name, year, city_id):
slide(item_competition.id)
# Add code for Judge view
code(item_competition.id, 2)
code(2, item_competition.id)
# Add code for Audience view
code(item_competition.id, 3)
code(3, item_competition.id)
item_competition = utils.refresh(item_competition)
return item_competition
......
......@@ -40,7 +40,7 @@ def code_by_code(code):
def code_list(competition_id):
""" Gets a list of all code objects associated with a the provided competition. """
# team_view_id = 1
join_competition = Competition.id == Code.pointer
join_competition = Competition.id == Code.competition_id
filters = Competition.id == competition_id
return Code.query.join(Competition, join_competition).filter(filters).all()
......
......@@ -205,17 +205,17 @@ class Component(db.Model):
class Code(db.Model):
table_args = (db.UniqueConstraint("pointer", "type"),)
id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Text, unique=True)
pointer = db.Column(db.Integer, nullable=False)
view_type_id = db.Column(db.Integer, db.ForeignKey("view_type.id"), nullable=False)
competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"), nullable=False)
team_id = db.Column(db.Integer, db.ForeignKey("team.id"), nullable=True)
def __init__(self, code, pointer, view_type_id):
def __init__(self, code, view_type_id, competition_id=None, team_id=None):
self.code = code
self.pointer = pointer
self.view_type_id = view_type_id
self.competition_id = competition_id
self.team_id = team_id
class ViewType(db.Model):
......
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