update user model; templates for api; setup user page and github oauth

This commit is contained in:
crflynn
2018-04-06 23:17:18 -04:00
parent 03995ebf5a
commit 3d8247886f
12 changed files with 509 additions and 66 deletions

View File

@@ -1,7 +1,9 @@
"""JSON API routes."""
from flask import abort
from flask import Blueprint
from flask import g
from flask import jsonify
from flask import render_template
from flask import request
from pypistats.models.download import OverallDownloadCount
@@ -15,6 +17,12 @@ from pypistats.models.download import SystemDownloadCount
blueprint = Blueprint('api', __name__, url_prefix='/api')
@blueprint.route("/")
def api():
"""Get API documentation."""
return render_template("api.html", user=g.user)
@blueprint.route("/<package>/recent")
def api_downloads_recent(package):
"""Get the recent downloads of a package."""
@@ -99,7 +107,7 @@ def generic_downloads(model, package, arg, name):
category = request.args.get(f"{arg}")
if category is not None:
downloads = model.query.\
filter_by(package=package, category=category).\
filter_by(package=package, category=category.lower()).\
order_by(model.date).all()
else:
downloads = model.query.\