mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
parent
bbf1143090
commit
2617c53abf
@ -21,7 +21,7 @@ def home():
|
||||
pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all()
|
||||
pop_gam = join(query.filter_by(type=PackageType.GAME).order_by(db.desc(Package.score))).limit(4).all()
|
||||
pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(4).all()
|
||||
downloads_result = db.session.query(func.sum(PackageRelease.downloads)).one_or_none()
|
||||
downloads_result = db.session.query(func.sum(Package.downloads)).one_or_none()
|
||||
downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0]
|
||||
return render_template("index.html", count=count, downloads=downloads, \
|
||||
new=new, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam)
|
||||
|
@ -42,8 +42,7 @@ def generate_metrics(full=False):
|
||||
|
||||
return ret + "\n"
|
||||
|
||||
|
||||
downloads_result = db.session.query(func.sum(PackageRelease.downloads)).one_or_none()
|
||||
downloads_result = db.session.query(func.sum(Package.downloads)).one_or_none()
|
||||
downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0]
|
||||
|
||||
packages = Package.query.filter_by(approved=True, soft_deleted=False).count()
|
||||
|
@ -140,6 +140,7 @@ def download_release(package, id):
|
||||
})
|
||||
|
||||
Package.query.filter_by(id=package.id).update({
|
||||
"downloads": Package.downloads + 1,
|
||||
"score": Package.score + bonus
|
||||
})
|
||||
|
||||
|
@ -431,7 +431,8 @@ class Package(db.Model):
|
||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||
soft_deleted = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
score = db.Column(db.Float, nullable=False, default=0)
|
||||
score = db.Column(db.Float, nullable=False, default=0)
|
||||
downloads = db.Column(db.Integer, nullable=False, default=0)
|
||||
|
||||
review_thread_id = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=True, default=None)
|
||||
review_thread = db.relationship("Thread", foreign_keys=[review_thread_id])
|
||||
@ -658,12 +659,6 @@ class Package(db.Model):
|
||||
|
||||
return None
|
||||
|
||||
def getDownloadCount(self):
|
||||
counter = 0
|
||||
for release in self.releases:
|
||||
counter += release.downloads
|
||||
return counter
|
||||
|
||||
def checkPerm(self, user, perm):
|
||||
if not user.is_authenticated:
|
||||
return False
|
||||
@ -709,8 +704,7 @@ class Package(db.Model):
|
||||
raise Exception("Permission {} is not related to packages".format(perm.name))
|
||||
|
||||
def setStartScore(self):
|
||||
downloads = db.session.query(func.sum(PackageRelease.downloads)). \
|
||||
filter(PackageRelease.package_id == self.id).scalar() or 0
|
||||
downloads = self.downloads
|
||||
|
||||
forum_score = 0
|
||||
forum_bonus = 0
|
||||
|
@ -63,7 +63,7 @@
|
||||
</a>
|
||||
<a class="btn" rel="nofollow" href="{{ package.getDownloadURL() }}">
|
||||
<i class="fas fa-download"></i>
|
||||
<span class="count">{{ package.getDownloadCount() }}</span>
|
||||
<span class="count">{{ package.downloads }}</span>
|
||||
</a>
|
||||
<a class="btn" href="{{ url_for('threads.list_all', pid=package.id) }}">
|
||||
<i class="fas fa-comment-alt"></i>
|
||||
|
38
migrations/versions/c141a63b2487_.py
Normal file
38
migrations/versions/c141a63b2487_.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: c141a63b2487
|
||||
Revises: cb6ab141c522
|
||||
Create Date: 2020-07-09 00:05:39.845465
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm, func
|
||||
from app.models import Package, PackageRelease
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c141a63b2487'
|
||||
down_revision = 'cb6ab141c522'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('package', sa.Column('downloads', sa.Integer(), nullable=False, server_default="0"))
|
||||
|
||||
bind = op.get_bind()
|
||||
session = orm.Session(bind=bind)
|
||||
|
||||
for package in session.query(Package).all():
|
||||
downloads_result = session.query(func.sum(PackageRelease.downloads)).filter_by(package_id=package.id).one_or_none()
|
||||
downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0]
|
||||
package.downloads = downloads
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('package', 'downloads')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user