Manage students page #51
@@ -24,7 +24,6 @@ def check_data(data, required_fields):
|
|||||||
def instructor_required(func):
|
def instructor_required(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def dec(*args, **kwargs):
|
def dec(*args, **kwargs):
|
||||||
print(current_user)
|
|
||||||
if current_user.role != "instructor":
|
if current_user.role != "instructor":
|
||||||
return error_response(400, "User is not instructor!")
|
return error_response(400, "User is not instructor!")
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@@ -173,3 +172,28 @@ def enroll_student(uid, cid):
|
|||||||
resp = {"user": u.to_dict(), "course": c.to_dict()}
|
resp = {"user": u.to_dict(), "course": c.to_dict()}
|
||||||
return jsonify(resp)
|
return jsonify(resp)
|
||||||
|
|
||||||
|
@bp.route("/user/<string:username>/enroll/<int:cid>", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
@instructor_required
|
||||||
|
def enroll_student_by_username(username, cid):
|
||||||
|
u = User.query.filter_by(username=username).first()
|
||||||
|
if not u:
|
||||||
|
return error_response(400, f"User with username {username} does not exist")
|
||||||
|
|
||||||
|
c = Course.query.get(cid)
|
||||||
|
if not c:
|
||||||
|
return error_response(400, f"Course with id {cid} does not exist")
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
if not u.enroll(c):
|
||||||
|
return error_response(
|
||||||
|
400, f"User {u.id} is already enrolled in course {cid}"
|
||||||
|
)
|
||||||
|
|
||||||
|
elif request.method == "DELETE":
|
||||||
|
if not u.unenroll(c):
|
||||||
|
return error_response(400, f"User {u.id} is not enrolled in course {cid}")
|
||||||
|
|
||||||
|
resp = {"user": u.to_dict(), "course": c.to_dict()}
|
||||||
|
return jsonify(resp)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user