add skeleton of examination package and create ExaminationSchedule, Enrollment and Committee models
This commit is contained in:
parent
dab59189cf
commit
adfb941fbe
@ -13,7 +13,7 @@ from .api import api_bp
|
||||
from .errors import request_entity_too_large, register_error_handlers
|
||||
|
||||
|
||||
def create_app(config_name: str = None) -> APIFlask:
|
||||
def create_app(config_name: str = '') -> APIFlask:
|
||||
if config_name is None:
|
||||
config_name = os.environ.get("FLASK_ENV")
|
||||
|
||||
|
@ -2,6 +2,7 @@ from flask import Blueprint
|
||||
from .coordinator.routes import bp as coordinator_bp
|
||||
from .project_supervisor.routes import bp as project_supervisor_bp
|
||||
from .students.routes import bp as students_bp
|
||||
from .examination_schedule.routes import bp as examination_schedules_bp
|
||||
|
||||
api_bp = Blueprint('api', __name__, url_prefix='/api')
|
||||
|
||||
@ -9,3 +10,4 @@ api_bp = Blueprint('api', __name__, url_prefix='/api')
|
||||
api_bp.register_blueprint(coordinator_bp)
|
||||
api_bp.register_blueprint(project_supervisor_bp)
|
||||
api_bp.register_blueprint(students_bp)
|
||||
api_bp.register_blueprint(examination_schedules_bp)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import TypedDict, Tuple
|
||||
from typing import TypedDict, Union
|
||||
|
||||
from flask import current_app, abort
|
||||
from flask import current_app
|
||||
from flask_sqlalchemy import BaseQuery
|
||||
from sqlalchemy import desc
|
||||
|
||||
@ -10,7 +10,7 @@ class PaginationResponse(TypedDict):
|
||||
max_pages: int
|
||||
|
||||
|
||||
def order_by_column_name(query: BaseQuery, model_field: str, order_by_col_name: str) -> BaseQuery:
|
||||
def order_by_column_name(query: BaseQuery, model_field: str, order_by_col_name: Union[str, None]) -> BaseQuery:
|
||||
if order_by_col_name is not None:
|
||||
if order_by_col_name == 'asc':
|
||||
query = query.order_by(model_field)
|
||||
|
0
backend/app/examination_schedule/__init__.py
Normal file
0
backend/app/examination_schedule/__init__.py
Normal file
36
backend/app/examination_schedule/models.py
Normal file
36
backend/app/examination_schedule/models.py
Normal file
@ -0,0 +1,36 @@
|
||||
from ..dependencies import db
|
||||
from ..base.models import Base
|
||||
|
||||
|
||||
class ExaminationSchedule(Base):
|
||||
__tablename__ = 'examination_schedules'
|
||||
|
||||
title = db.Column(db.String(100), unique=True, nullable=False)
|
||||
start_date = db.Column(db.DateTime, nullable=False)
|
||||
end_date = db.Column(db.DateTime, nullable=False)
|
||||
|
||||
|
||||
class Enrollment(Base):
|
||||
__tablename__ = 'enrollments'
|
||||
|
||||
start_date = db.Column(db.DateTime, nullable=False)
|
||||
end_date = db.Column(db.DateTime, nullable=False)
|
||||
examination_schedule_id = db.Column(db.Integer, db.ForeignKey('examination_schedules.id'))
|
||||
examination_schedule = db.relationship('ExaminationSchedule', backref='enrollments')
|
||||
committee = db.relationship("Committee", uselist=False, backref='enrollment')
|
||||
group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))
|
||||
|
||||
|
||||
class Committee(Base):
|
||||
__tablename__ = 'committees'
|
||||
|
||||
enrollment_id = db.Column(db.Integer, db.ForeignKey('enrollments.id'))
|
||||
members = db.relationship('ProjectSupervisor', secondary='committees_projects_supervisors', backref='committees')
|
||||
|
||||
|
||||
class CommitteeProjectSupervisor(Base):
|
||||
__tablename__ = 'committees_projects_supervisors'
|
||||
|
||||
chairman = db.Column(db.Boolean, default=False, nullable=False)
|
||||
committee_id = db.Column(db.Integer, db.ForeignKey('committees.id'))
|
||||
member_id = db.Column(db.Integer, db.ForeignKey('project_supervisors.id'))
|
3
backend/app/examination_schedule/routes/__init__.py
Normal file
3
backend/app/examination_schedule/routes/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint("examination_schedule", __name__, url_prefix="/examination_schedule")
|
0
backend/app/examination_schedule/schemas.py
Normal file
0
backend/app/examination_schedule/schemas.py
Normal file
@ -3,7 +3,7 @@ from flask_sqlalchemy import BaseQuery
|
||||
from ..dependencies import db
|
||||
from ..base.models import Person, Base
|
||||
from ..base.utils import order_by_column_name
|
||||
|
||||
from ..examination_schedule.models import Enrollment
|
||||
|
||||
class Group(Base):
|
||||
__tablename__ = "groups"
|
||||
@ -16,6 +16,7 @@ class Group(Base):
|
||||
project_supervisor = db.relationship('ProjectSupervisor', backref='groups', lazy=True)
|
||||
points_for_first_term = db.Column(db.Integer, default=0, nullable=False)
|
||||
points_for_second_term = db.Column(db.Integer, default=0, nullable=False)
|
||||
enrollment = db.relationship('Enrollment', uselist=False, backref='group')
|
||||
|
||||
@classmethod
|
||||
def search_by_name(cls, search_name: str = None) -> BaseQuery:
|
||||
|
63
backend/migrations/versions/c7adfbd3c67f_.py
Normal file
63
backend/migrations/versions/c7adfbd3c67f_.py
Normal file
@ -0,0 +1,63 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: c7adfbd3c67f
|
||||
Revises: ceaefb33117e
|
||||
Create Date: 2022-10-26 08:11:00.965906
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c7adfbd3c67f'
|
||||
down_revision = 'ceaefb33117e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('examination_schedules',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('title', sa.String(length=100), nullable=False),
|
||||
sa.Column('start_date', sa.DateTime(), nullable=False),
|
||||
sa.Column('end_date', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('title')
|
||||
)
|
||||
op.create_table('enrollments',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('start_date', sa.DateTime(), nullable=False),
|
||||
sa.Column('end_date', sa.DateTime(), nullable=False),
|
||||
sa.Column('examination_schedule_id', sa.Integer(), nullable=True),
|
||||
sa.Column('group_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['examination_schedule_id'], ['examination_schedules.id'], ),
|
||||
sa.ForeignKeyConstraint(['group_id'], ['groups.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('committees',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('enrollment_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['enrollment_id'], ['enrollments.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('committees_projects_supervisors',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('chairman', sa.Boolean(), nullable=False),
|
||||
sa.Column('committee_id', sa.Integer(), nullable=True),
|
||||
sa.Column('member_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['committee_id'], ['committees.id'], ),
|
||||
sa.ForeignKeyConstraint(['member_id'], ['project_supervisors.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('committees_projects_supervisors')
|
||||
op.drop_table('committees')
|
||||
op.drop_table('enrollments')
|
||||
op.drop_table('examination_schedules')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user