Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. @app.route("/tests/<int:test_id>/json", methods=["GET", "POST"])
  2. @login_required
  3. def test_json(test_id):
  4. return_dict = {
  5. "status": "invalid",
  6. "error": gettext("The test does not exist"),
  7. "test": "",
  8. }
  9. test = context.query_first(Test, Test.id == test_id)
  10. if test.rooms:
  11. if (
  12. current_user in test.rooms[0].students
  13. or current_user not in test.rooms[0].professors
  14. ):
  15.  
  16. instance: list = list(
  17. filter(lambda x: x.student == current_user, test.test_instances)
  18. )
  19. if instance:
  20. instance: TestInstance = instance[0]
  21. return_dict["test_instance"] = instance.serialize()
  22. return_dict["status"] = "valid"
  23. return_dict["test"] = test.serialize()
  24. else:
  25. return_dict["error"] = gettext(
  26. "There are no tests with the parameters provided"
  27. )
  28. else:
  29. return_dict["error"] = gettext(
  30. "The test belongs to a room to which you do not have access to."
  31. )
  32. else:
  33. return_dict["error"] = gettext("The test does not belong to any room")
  34. return jsonify(return_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement