roundabout,
created on Tuesday, 11 June 2024, 18:15:37 (1718129737),
received on Wednesday, 31 July 2024, 06:54:49 (1722408889)
Author identity: vlad <vlad.muntoiu@gmail.com>
02da777b9740d7b646b5a2c60caec0cd3df170ab
api.py
@@ -37,11 +37,29 @@ def welcome():
return response @api_app.route("/user/<username>", methods=["GET"])@api_app.route("/user/<username>/", methods=["GET"])def get_user(username): response = flask.make_response(flask.render_template("user.xml", user=db.session.get(User, username))) response.headers["Content-Type"] = "application/xml" return response @api_app.route("/user/<username>/repositories", methods=["GET"]) @auth.login_required(optional=True) def get_user_repositories(username): user = db.session.get(User, username) page = flask.request.args.get("page", 1) page_size = flask.request.args.get("page_size", 64) if hasattr(flask.g, "user") and flask.g.user == username: repositories = Repo.query.filter_by(owner=user).paginate(page=page, per_page=page_size) else: repositories = Repo.query.filter_by(owner=user, visibility=2).paginate(page=page, per_page=page_size) response = flask.make_response( flask.render_template("user-repositories.xml", user=user, repositories=repositories.items, page=page, page_size=page_size) ) response.headers["Content-Type"] = "application/xml" return response app.register_blueprint(api_app)
templates/api/user-repositories.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <list> {% for repo in repositories %} <repository name="{{ repo.route }}" visibility="{{ repo.visibility }}" /> {% endfor %} </list>