diff options
| author | rubenwardy <rw@rubenwardy.com> | 2018-03-23 16:20:56 +0000 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2018-03-23 16:21:06 +0000 |
| commit | 5a9fc51ffcc4744179687540df50b5a778275099 (patch) | |
| tree | 93b82d51f7994299d94f686f65bc16a43bd5fffa /app/views | |
| parent | 570dd519df311b159fd1416be9162700c623db6b (diff) | |
| download | cheatdb-5a9fc51ffcc4744179687540df50b5a778275099.tar.xz | |
Add download button and URL
Diffstat (limited to 'app/views')
| -rw-r--r-- | app/views/packages.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/views/packages.py b/app/views/packages.py index 142b87a..1eee29c 100644 --- a/app/views/packages.py +++ b/app/views/packages.py @@ -96,6 +96,23 @@ def package_page(type, author, name): return render_template("packages/view.html", package=package, releases=releases) +@app.route("/<type>s/<author>/<name>/download/") +def package_download_page(type, author, name): + package = getPageByInfo(type, author, name) + release = package.getDownloadRelease() + + if release is None: + wantsJson = "application/zip" in request.accept_mimetypes and \ + not "text/html" in request.accept_mimetypes + + if wantsJson: + return "", 204 + else: + flash("No download available.", "error") + return redirect(package.getDetailsURL()) + else: + return redirect(release.url, code=302) + class PackageForm(FlaskForm): name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")]) |
