add mode to examination schedule model and add endpoints list of examination schedule for students and project supervisors
This commit is contained in:
parent
b205bd1698
commit
3c5accfc6e
@ -5,6 +5,7 @@ from ..validators import validate_datetime_greater_than_now
|
||||
|
||||
class ExaminationScheduleSchema(Schema):
|
||||
title = fields.Str(validate=validate.Length(min=1, max=100), required=True)
|
||||
mode = fields.Boolean(required=True)
|
||||
|
||||
|
||||
class ExaminationScheduleUpdateSchema(Schema):
|
||||
@ -15,6 +16,7 @@ class ExaminationScheduleUpdateSchema(Schema):
|
||||
class ExaminationScheduleListItemSchema(Schema):
|
||||
id = fields.Integer(required=True)
|
||||
title = fields.Str(validate=validate.Length(min=1, max=100), required=True)
|
||||
mode = fields.Boolean(required=True)
|
||||
start_date = fields.DateTime(validate=validate_datetime_greater_than_now, required=True)
|
||||
end_date = fields.DateTime(validate=validate_datetime_greater_than_now, required=True)
|
||||
|
||||
|
@ -6,6 +6,7 @@ class ExaminationSchedule(Base):
|
||||
__tablename__ = 'examination_schedules'
|
||||
|
||||
title = db.Column(db.String(100), unique=True, nullable=False)
|
||||
mode = db.Column(db.Boolean, default=True, nullable=False) # True - stationary, False - non-stationary
|
||||
start_date = db.Column(db.DateTime)
|
||||
end_date = db.Column(db.DateTime)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from .enrollments import bp as enrollments_bp
|
||||
from .examination_schedule import bp as examination_schedule_bp
|
||||
|
||||
bp = Blueprint("examination_schedule", __name__, url_prefix="/examination_schedule")
|
||||
|
||||
bp.register_blueprint(enrollments_bp)
|
||||
bp.register_blueprint(examination_schedule_bp)
|
||||
|
@ -0,0 +1,32 @@
|
||||
import datetime
|
||||
|
||||
from apiflask import APIBlueprint
|
||||
from flask import abort
|
||||
|
||||
from ...dependencies import db
|
||||
from ..models import ExaminationSchedule
|
||||
from ..schemas import ExaminationScheduleListSchema
|
||||
|
||||
bp = APIBlueprint("list_of_examination_schedule", __name__, url_prefix="/")
|
||||
|
||||
|
||||
@bp.get('/project-supervisor-view/')
|
||||
@bp.output(ExaminationScheduleListSchema)
|
||||
def list_examination_schedule_for_project_supervisors() -> dict:
|
||||
now = datetime.datetime.utcnow()
|
||||
examination_schedules = db.session.query(ExaminationSchedule). \
|
||||
filter(ExaminationSchedule.start_date > now). \
|
||||
all()
|
||||
return {'examination_schedules': examination_schedules}
|
||||
|
||||
|
||||
@bp.get('/students-view/')
|
||||
@bp.output(ExaminationScheduleListSchema)
|
||||
def list_examination_schedule_for_students() -> dict:
|
||||
# in the future filter after the mode of examination schedule if we will have authorization module
|
||||
now = datetime.datetime.utcnow()
|
||||
examination_schedules = db.session.query(ExaminationSchedule).\
|
||||
filter(ExaminationSchedule.start_date < now).\
|
||||
filter(ExaminationSchedule.end_date > now).\
|
||||
all()
|
||||
return {'examination_schedules': examination_schedules}
|
@ -29,3 +29,12 @@ class EnrollmentPaginationSchema(Schema):
|
||||
class EnrollmentQuerySchema(Schema):
|
||||
page = fields.Integer()
|
||||
per_page = fields.Integer()
|
||||
|
||||
|
||||
class ExaminationScheduleSchema(Schema):
|
||||
id = fields.Integer()
|
||||
title = fields.Str()
|
||||
|
||||
|
||||
class ExaminationScheduleListSchema(Schema):
|
||||
examination_schedules = fields.List(fields.Nested(ExaminationScheduleSchema))
|
||||
|
@ -1,8 +1,8 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 97c55960cd98
|
||||
Revision ID: 64ad410af362
|
||||
Revises: ceaefb33117e
|
||||
Create Date: 2022-10-26 13:00:18.439990
|
||||
Create Date: 2022-10-27 09:44:53.799889
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '97c55960cd98'
|
||||
revision = '64ad410af362'
|
||||
down_revision = 'ceaefb33117e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@ -21,6 +21,7 @@ def upgrade():
|
||||
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('mode', sa.Boolean(), nullable=False),
|
||||
sa.Column('start_date', sa.DateTime(), nullable=True),
|
||||
sa.Column('end_date', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
Loading…
Reference in New Issue
Block a user