Download app_pkg/routes/admin.py from ed29/xertify: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/ed29/xertify/resolve/main/app_pkg/routes/admin.py
- Command line
-
hf download hf://spaces/ed29/xertify/app_pkg/routes/admin.py
-
curl -L -o admin.py https://huggingface.co/spaces/ed29/xertify/resolve/main/app_pkg/routes/admin.py
1.36 kB
| from flask import Blueprint, render_template, request, redirect, url_for | |
| from flask_login import login_required, current_user | |
| from app_pkg.models import db | |
| from app_pkg.models.user import User | |
| admin_bp = Blueprint("admin", __name__, url_prefix="/admin") | |
| #Pending | |
| def list_pending(): | |
| if current_user.role != "admin": | |
| return {"error": "No autorizado"}, 403 | |
| users = User.query.filter_by(status="pending").all() | |
| # If the client accepts HTML, render a simple admin page | |
| if request.accept_mimetypes.accept_html: | |
| return render_template("admin_pending.html", users=users) | |
| return {"pending_users": [ | |
| {"id": u.id, "name": u.name, "email": u.email} | |
| for u in users | |
| ]} | |
| def approve(user_id): | |
| if current_user.role != "admin": | |
| return {"error": "No autorizado"}, 403 | |
| user = User.query.get(user_id) | |
| if not user: | |
| return {"error": "Usuario no encontrado"} | |
| user.status = "active" | |
| db.session.commit() | |
| # If request came from a browser form, redirect back to pending list | |
| if not request.is_json and request.accept_mimetypes.accept_html: | |
| return redirect(url_for("admin.list_pending")) | |
| return {"message": "Usuario aprobado"} | |