mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
Add download counting
This commit is contained in:
parent
0f3adda592
commit
23c406bff9
@ -496,6 +496,12 @@ class Package(db.Model):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getDownloadCount(self):
|
||||||
|
counter = 0
|
||||||
|
for release in self.releases:
|
||||||
|
counter += release.downloads
|
||||||
|
return counter
|
||||||
|
|
||||||
def checkPerm(self, user, perm):
|
def checkPerm(self, user, perm):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return False
|
return False
|
||||||
@ -639,6 +645,7 @@ class PackageRelease(db.Model):
|
|||||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
task_id = db.Column(db.String(37), nullable=True)
|
task_id = db.Column(db.String(37), nullable=True)
|
||||||
commit_hash = db.Column(db.String(41), nullable=True, default=None)
|
commit_hash = db.Column(db.String(41), nullable=True, default=None)
|
||||||
|
downloads = db.Column(db.Integer, nullable=False, default=0)
|
||||||
|
|
||||||
min_rel_id = db.Column(db.Integer, db.ForeignKey("minetest_release.id"), nullable=True, server_default=None)
|
min_rel_id = db.Column(db.Integer, db.ForeignKey("minetest_release.id"), nullable=True, server_default=None)
|
||||||
min_rel = db.relationship("MinetestRelease", foreign_keys=[min_rel_id])
|
min_rel = db.relationship("MinetestRelease", foreign_keys=[min_rel_id])
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<div class="row" style="margin-top: 2rem;">
|
<div class="row" style="margin-top: 2rem;">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
{{ package.getDownloadCount() }} downloads
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group-horizontal col-md-auto">
|
<div class="btn-group-horizontal col-md-auto">
|
||||||
{% if package.repo %}<a class="btn btn-secondary" href="{{ package.repo }}">View Source</a>{% endif %}
|
{% if package.repo %}<a class="btn btn-secondary" href="{{ package.repo }}">View Source</a>{% endif %}
|
||||||
@ -112,7 +113,7 @@
|
|||||||
|
|
||||||
<aside class="float-right ml-4" style="width: 18rem;">
|
<aside class="float-right ml-4" style="width: 18rem;">
|
||||||
{% if package.getDownloadRelease() %}
|
{% if package.getDownloadRelease() %}
|
||||||
<a class="btn btn-download btn-lg btn-block"
|
<a class="btn btn-download btn-lg btn-block" rel="nofollow"
|
||||||
href="{{ package.getDownloadURL() }}" class="btn_green">
|
href="{{ package.getDownloadURL() }}" class="btn_green">
|
||||||
Download
|
Download
|
||||||
</a>
|
</a>
|
||||||
@ -260,10 +261,10 @@
|
|||||||
|
|
||||||
{% if not rel.approved %}<i>{% endif %}
|
{% if not rel.approved %}<i>{% endif %}
|
||||||
|
|
||||||
<a href="{{ rel.getDownloadURL() }}">{{ rel.title }}</a>{% if rel.commit_hash %}
|
<a href="{{ rel.getDownloadURL() }}" rel="nofollow">{{ rel.title }}</a>{% if rel.commit_hash %}
|
||||||
[{{ rel.commit_hash | truncate(5, end='') }}]{% endif %}<br>
|
[{{ rel.commit_hash | truncate(5, end='') }}]{% endif %}<br>
|
||||||
<small>created {{ rel.releaseDate | datetime }}.</small>
|
<small>created {{ rel.releaseDate | datetime }}.</small>
|
||||||
{% if rel.task_id %}
|
{% if (package.checkPerm(current_user, "MAKE_RELEASE") or package.checkPerm(current_user, "APPROVE_RELEASE")) and rel.task_id %}
|
||||||
<a href="{{ url_for('check_task', id=rel.task_id, r=package.getDetailsURL()) }}">Importing...</a>
|
<a href="{{ url_for('check_task', id=rel.task_id, r=package.getDetailsURL()) }}">Importing...</a>
|
||||||
{% elif not rel.approved %}
|
{% elif not rel.approved %}
|
||||||
Waiting for approval.
|
Waiting for approval.
|
||||||
|
@ -160,6 +160,11 @@ def package_download_page(package):
|
|||||||
flash("No download available.", "error")
|
flash("No download available.", "error")
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
else:
|
else:
|
||||||
|
PackageRelease.query.filter_by(id=release.id).update({
|
||||||
|
"downloads": PackageRelease.downloads + 1
|
||||||
|
})
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(release.url, code=302)
|
return redirect(release.url, code=302)
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,6 +129,11 @@ def download_release_page(package, id):
|
|||||||
flash("No download available.", "error")
|
flash("No download available.", "error")
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
else:
|
else:
|
||||||
|
PackageRelease.query.filter_by(id=release.id).update({
|
||||||
|
"downloads": PackageRelease.downloads + 1
|
||||||
|
})
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(release.url, code=300)
|
return redirect(release.url, code=300)
|
||||||
|
|
||||||
@app.route("/packages/<author>/<name>/releases/<id>/", methods=["GET", "POST"])
|
@app.route("/packages/<author>/<name>/releases/<id>/", methods=["GET", "POST"])
|
||||||
|
28
migrations/versions/9ec17b558413_.py
Normal file
28
migrations/versions/9ec17b558413_.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 9ec17b558413
|
||||||
|
Revises: 97a9c461bc2d
|
||||||
|
Create Date: 2019-01-29 00:37:49.507631
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '9ec17b558413'
|
||||||
|
down_revision = '97a9c461bc2d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('package_release', sa.Column('downloads', sa.Integer(), nullable=False, server_default="0"))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('package_release', 'downloads')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user