mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Add package scores and split homepage into new and popular
This commit is contained in:
parent
9fc9826d30
commit
7813c766ac
@ -339,6 +339,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)
|
||||
|
||||
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])
|
||||
|
||||
@ -385,7 +387,8 @@ class Package(db.Model):
|
||||
"shortDesc": self.shortDesc,
|
||||
"type": self.type.toName(),
|
||||
"release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None,
|
||||
"thumbnail": (base_url + tnurl) if tnurl is not None else None
|
||||
"thumbnail": (base_url + tnurl) if tnurl is not None else None,
|
||||
"score": round(self.score * 10) / 10
|
||||
}
|
||||
|
||||
def getAsDictionary(self, base_url):
|
||||
@ -412,7 +415,9 @@ class Package(db.Model):
|
||||
"screenshots": [base_url + ss.url for ss in self.screenshots],
|
||||
|
||||
"url": base_url + self.getDownloadURL(),
|
||||
"release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None
|
||||
"release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None,
|
||||
|
||||
"score": round(self.score * 10) / 10
|
||||
}
|
||||
|
||||
def getThumbnailURL(self):
|
||||
@ -498,6 +503,21 @@ class Package(db.Model):
|
||||
else:
|
||||
raise Exception("Permission {} is not related to packages".format(perm.name))
|
||||
|
||||
def recalcScore(self):
|
||||
import datetime
|
||||
|
||||
self.score = 0
|
||||
|
||||
if self.forums is None:
|
||||
return
|
||||
|
||||
topic = ForumTopic.query.get(self.forums)
|
||||
if topic:
|
||||
days = (datetime.datetime.now() - topic.created_at).days
|
||||
months = days / 30
|
||||
years = days / 365
|
||||
self.score = topic.views / years + 80*min(6, months)
|
||||
|
||||
class MetaPackage(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||
|
@ -21,6 +21,7 @@
|
||||
<option value="importscreenshots" selected>Import screenshots from VCS</option>
|
||||
<option value="importdepends">Import dependencies from downloads</option>
|
||||
<option value="modprovides">Set provides to mod name</option>
|
||||
<option value="recalcscores">Recalc pakage scores</option>
|
||||
</select>
|
||||
<input type="submit" value="Perform" />
|
||||
</form>
|
||||
|
@ -25,6 +25,10 @@ Welcome
|
||||
|
||||
<main>
|
||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||
{{ render_pkggrid(packages) }}
|
||||
<h2>Newly Added</h2>
|
||||
{{ render_pkggrid(new) }}
|
||||
|
||||
<h2>Popular</h2>
|
||||
{{ render_pkggrid(popular) }}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
@ -48,8 +48,9 @@ def send_upload(path):
|
||||
def home_page():
|
||||
query = Package.query.filter_by(approved=True, soft_deleted=False)
|
||||
count = query.count()
|
||||
packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
|
||||
return render_template("index.html", packages=packages, count=count)
|
||||
new = query.order_by(db.desc(Package.created_at)).limit(3).all()
|
||||
popular = query.order_by(db.desc(Package.score)).limit(15).all()
|
||||
return render_template("index.html", new=new, popular=popular, count=count)
|
||||
|
||||
from . import users, githublogin, packages, meta, threads, api
|
||||
from . import sass, tasks, admin, notifications, tagseditor, thumbnails
|
||||
|
@ -64,6 +64,12 @@ def admin_page():
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for("admin_page"))
|
||||
elif action == "recalcscores":
|
||||
for p in Package.query.all():
|
||||
p.recalcScore()
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for("admin_page"))
|
||||
|
||||
else:
|
||||
flash("Unknown action: " + action, "error")
|
||||
|
@ -47,6 +47,8 @@ def build_packages_query():
|
||||
if search is not None and search.strip() != "":
|
||||
query = query.filter(Package.title.ilike('%' + search + '%'))
|
||||
|
||||
query = query.order_by(db.desc(Package.score))
|
||||
|
||||
return query, title
|
||||
|
||||
@menu.register_menu(app, ".mods", "Mods", order=11, endpoint_arguments_constructor=lambda: { 'type': 'mod' })
|
||||
|
28
migrations/versions/11b6ef362f98_.py
Normal file
28
migrations/versions/11b6ef362f98_.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 11b6ef362f98
|
||||
Revises: 9fc23495713b
|
||||
Create Date: 2018-07-04 01:01:45.440662
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '11b6ef362f98'
|
||||
down_revision = '9fc23495713b'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('package', sa.Column('score', sa.Float(), nullable=False, server_default="0.0"))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('package', 'score')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user