mirror of
https://github.com/minetest/contentdb.git
synced 2025-03-23 02:32:28 +01:00
Add download button and URL
This commit is contained in:
@ -147,6 +147,18 @@ class Package(db.Model):
|
|||||||
type=self.type.toName(),
|
type=self.type.toName(),
|
||||||
author=self.author.username, name=self.name)
|
author=self.author.username, name=self.name)
|
||||||
|
|
||||||
|
def getDownloadURL(self):
|
||||||
|
return url_for("package_download_page",
|
||||||
|
type=self.type.toName(),
|
||||||
|
author=self.author.username, name=self.name)
|
||||||
|
|
||||||
|
def getDownloadRelease(self):
|
||||||
|
for rel in self.releases:
|
||||||
|
if rel.approved:
|
||||||
|
return rel
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def checkPerm(self, user, perm):
|
def checkPerm(self, user, perm):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return False
|
return False
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<ul class="buttonset linedbuttonset">
|
<ul class="buttonset linedbuttonset">
|
||||||
|
{% if package.getDownloadRelease() %}<li><a href="{{ package.getDownloadURL() }}">Download</a></li>{% endif %}
|
||||||
{% if package.repo %}<li><a href="{{ package.repo }}">View Source</a></li>{% endif %}
|
{% if package.repo %}<li><a href="{{ package.repo }}">View Source</a></li>{% endif %}
|
||||||
{% if package.forums %}<li><a href="https://forum.minetest.net/viewtopic.php?t={{ package.forums }}">Forums</a></li>{% endif %}
|
{% if package.forums %}<li><a href="https://forum.minetest.net/viewtopic.php?t={{ package.forums }}">Forums</a></li>{% endif %}
|
||||||
{% if package.issueTracker %}<li><a href="{{ package.issueTracker }}">Issue Tracker</a></li>{% endif %}
|
{% if package.issueTracker %}<li><a href="{{ package.issueTracker }}">Issue Tracker</a></li>{% endif %}
|
||||||
|
@ -96,6 +96,23 @@ def package_page(type, author, name):
|
|||||||
|
|
||||||
return render_template("packages/view.html", package=package, releases=releases)
|
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):
|
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")])
|
name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
||||||
|
Reference in New Issue
Block a user