Add download button and URL

This commit is contained in:
rubenwardy
2018-03-23 16:20:56 +00:00
parent 570dd519df
commit 5a9fc51ffc
3 changed files with 30 additions and 0 deletions

View File

@@ -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")])