from flask import Blueprint, render_template, request from app.models.session import Session from app.models.user import User from app.extensions import db from paper.parser import PaperParser users = Blueprint("users", __name__, url_prefix="/users", template_folder="templates") @users.route("/parse/", methods=["POST"]) async def parse_users(session_id: int): session = Session.query.get_or_404(session_id) data = request.form async with PaperParser(session.name) as parser: users = await parser.get_participants(data.get("group")) for user in users: if not user.username: continue exists = db.session.query(User.id).filter_by(username=user.username).first() if not exists: db.session.add( User( first_name=user.first_name, last_name=user.last_name, username=user.username, phone=user.phone, session=session, ) ) db.session.commit() return render_template("user_cards.j2", users=session.users) @users.route("/", methods=["GET"]) def get_users(session_id: int): users = [] #Session.query.get_or_404(session_id) return render_template("user_cards.j2", users=users) @users.route("/", methods=["DELETE"]) def delete_users(session_id): session: Session = Session.query.get_or_404(session_id) if session.has_depending_tasks(): return 'Есть зависимые задачи', 409 User.query.filter_by(session=session).delete() db.session.commit() return render_template("user_cards.j2", users=[])