Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route("/tests/<int:test_id>/json", methods=["GET", "POST"])
- @login_required
- def test_json(test_id):
- return_dict = {
- "status": "invalid",
- "error": gettext("The test does not exist"),
- "test": "",
- }
- test = context.query_first(Test, Test.id == test_id)
- if test.rooms:
- if (
- current_user in test.rooms[0].students
- or current_user not in test.rooms[0].professors
- ):
- instance: list = list(
- filter(lambda x: x.student == current_user, test.test_instances)
- )
- if instance:
- instance: TestInstance = instance[0]
- return_dict["test_instance"] = instance.serialize()
- return_dict["status"] = "valid"
- return_dict["test"] = test.serialize()
- else:
- return_dict["error"] = gettext(
- "There are no tests with the parameters provided"
- )
- else:
- return_dict["error"] = gettext(
- "The test belongs to a room to which you do not have access to."
- )
- else:
- return_dict["error"] = gettext("The test does not belong to any room")
- return jsonify(return_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement