Merge branch 'master' of https://git.wmi.amu.edu.pl/s459309/system-pri
This commit is contained in:
commit
f3f9d502d8
@ -1,9 +1,11 @@
|
||||
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
|
||||
|
||||
api_bp = Blueprint('api', __name__, url_prefix='/api')
|
||||
|
||||
# register blueprints here
|
||||
api_bp.register_blueprint(coordinator_bp)
|
||||
api_bp.register_blueprint(project_supervisor_bp)
|
||||
api_bp.register_blueprint(students_bp)
|
||||
|
@ -1,7 +1,9 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from .students import bp as students_bp
|
||||
from .groups import bp as groups_bp
|
||||
|
||||
bp = Blueprint("coordinator", __name__, url_prefix="/coordinator")
|
||||
|
||||
bp.register_blueprint(students_bp)
|
||||
bp.register_blueprint(groups_bp)
|
||||
|
@ -32,9 +32,9 @@ def parse_csv(file, mode) -> Generator[Student, Any, None]:
|
||||
# raise InvalidNameOrTypeHeaderException
|
||||
|
||||
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'],
|
||||
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'],
|
||||
mode=mode)
|
||||
for _, item in df.iterrows())
|
||||
|
7
backend/app/students/routes/__init__.py
Normal file
7
backend/app/students/routes/__init__.py
Normal 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)
|
39
backend/app/students/routes/registrations.py
Normal file
39
backend/app/students/routes/registrations.py
Normal 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']
|
||||
}
|
@ -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()
|
Loading…
Reference in New Issue
Block a user