This commit is contained in:
Patryk Drzewiński 2022-06-12 23:09:37 +02:00
commit f3f9d502d8
7 changed files with 77 additions and 7 deletions

View File

@ -1,9 +1,11 @@
from flask import Blueprint from flask import Blueprint
from .coordinator.routes import bp as coordinator_bp from .coordinator.routes import bp as coordinator_bp
from .project_supervisor.routes import bp as project_supervisor_bp from .project_supervisor.routes import bp as project_supervisor_bp
from .students.routes import bp as students_bp
api_bp = Blueprint('api', __name__, url_prefix='/api') api_bp = Blueprint('api', __name__, url_prefix='/api')
# register blueprints here # register blueprints here
api_bp.register_blueprint(coordinator_bp) api_bp.register_blueprint(coordinator_bp)
api_bp.register_blueprint(project_supervisor_bp) api_bp.register_blueprint(project_supervisor_bp)
api_bp.register_blueprint(students_bp)

View File

@ -1,7 +1,9 @@
from flask import Blueprint from flask import Blueprint
from .students import bp as students_bp from .students import bp as students_bp
from .groups import bp as groups_bp
bp = Blueprint("coordinator", __name__, url_prefix="/coordinator") bp = Blueprint("coordinator", __name__, url_prefix="/coordinator")
bp.register_blueprint(students_bp) bp.register_blueprint(students_bp)
bp.register_blueprint(groups_bp)

View File

@ -9,7 +9,7 @@ from ..students.models import Student
def check_columns(df: pd.DataFrame) -> bool: def check_columns(df: pd.DataFrame) -> bool:
headers = set(df.keys().values) headers = set(df.keys().values)
columns = ['NAZWISKO','IMIE','INDEKS','PESEL','EMAIL'] columns = ['NAZWISKO', 'IMIE', 'INDEKS', 'PESEL', 'EMAIL']
if len(headers - set(columns)) != 0: if len(headers - set(columns)) != 0:
return False return False
@ -31,11 +31,11 @@ def parse_csv(file, mode) -> Generator[Student, Any, None]:
# if not check_columns(df): # if not check_columns(df):
# raise InvalidNameOrTypeHeaderException # raise InvalidNameOrTypeHeaderException
students = (Student(last_name = dict(item.items())['NAZWISKO'], students = (Student(last_name=dict(item.items())['NAZWISKO'],
first_name = dict(item.items())['NAZWISKO'], first_name=dict(item.items())['IMIE'],
index = dict(item.items())['INDEKS'], index=dict(item.items())['INDEKS'],
pesel = str(int(dict(item.items())['PESEL'])) if not pd.isna(dict(item.items())['PESEL']) else '', pesel=str(int(dict(item.items())['PESEL'])) if not pd.isna(dict(item.items())['PESEL']) else None,
email = dict(item.items())['EMAIL'], email=dict(item.items())['EMAIL'],
mode=mode) mode=mode)
for _, item in df.iterrows()) for _, item in df.iterrows())

View File

@ -0,0 +1,7 @@
from flask import Blueprint
from .registrations import bp as registrations_bp
bp = Blueprint("students", __name__, url_prefix="/students")
bp.register_blueprint(registrations_bp)

View File

@ -0,0 +1,39 @@
from apiflask import APIBlueprint
from flask import abort
from ...project_supervisor.models import ProjectSupervisor
from ..models import Group
from ...dependencies import db
from ..schemas import ProjectSupervisorPaginationSchema, ProjectSupervisorQuerySchema
from ...base.utils import paginate_models
bp = APIBlueprint("registrations", __name__, url_prefix="/registrations")
@bp.route('/', methods=['GET'])
@bp.input(ProjectSupervisorQuerySchema, location='query')
@bp.output(ProjectSupervisorPaginationSchema)
def list_available_groups(query: dict) -> dict:
mode = query.get('mode')
page = query.get('page')
per_page = query.get('per_page')
ps_query = db.session.query(ProjectSupervisor,
(ProjectSupervisor.count_groups - db.func.count(Group.id))).join(Group)
if mode is not None:
ps_query = ps_query.filter(ProjectSupervisor.mode == mode)
ps_query = ps_query.group_by(Group.id)
response = paginate_models(page, ps_query, per_page)
if (message := response.get('message')) is not None:
abort(response['status_code'], message)
project_supervisors = []
for project_supervisor, available_groups in response['items']:
setattr(project_supervisor, 'available_groups', available_groups)
project_supervisors.append(project_supervisor)
return {
"project_supervisors": project_supervisors,
"max_pages": response['max_pages']
}

View File

@ -0,0 +1,20 @@
from ..dependencies import ma
from marshmallow import fields
class ProjectSupervisorSchema(ma.Schema):
first_name = fields.Str()
last_name = fields.Str()
mode = fields.Boolean()
available_groups = fields.Integer()
class ProjectSupervisorPaginationSchema(ma.Schema):
project_supervisors = fields.List(fields.Nested(ProjectSupervisorSchema))
max_pages = fields.Integer()
class ProjectSupervisorQuerySchema(ma.Schema):
page = fields.Integer()
per_page = fields.Integer()
mode = fields.Boolean()