mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 01:23:48 +01:00
Add last updated section to homepage
This commit is contained in:
parent
980e1c9eb1
commit
836caf0fe0
@ -17,12 +17,22 @@ def home():
|
||||
|
||||
query = Package.query.filter_by(approved=True, soft_deleted=False)
|
||||
count = query.count()
|
||||
|
||||
new = join(query.order_by(db.desc(Package.created_at))).limit(8).all()
|
||||
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()
|
||||
|
||||
updated = db.session.query(Package).select_from(PackageRelease).join(Package) \
|
||||
.filter_by(soft_deleted=False, approved=True) \
|
||||
.order_by(db.desc(PackageRelease.releaseDate)) \
|
||||
.limit(8).all()
|
||||
updated = updated[:4]
|
||||
|
||||
reviews = PackageReview.query.filter_by(recommends=True).order_by(db.desc(PackageReview.created_at)).limit(5).all()
|
||||
|
||||
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, reviews=reviews)
|
||||
new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, reviews=reviews)
|
||||
|
@ -367,6 +367,7 @@ def approve(package):
|
||||
|
||||
else:
|
||||
package.approved = True
|
||||
package.approved_at = datetime.datetime.now()
|
||||
|
||||
screenshots = PackageScreenshot.query.filter_by(package=package, approved=False).all()
|
||||
for s in screenshots:
|
||||
|
@ -66,7 +66,7 @@ Supported query parameters:
|
||||
* `random` - When present, enable random ordering and ignore `sort`.
|
||||
* `limit` - Return at most `limit` packages.
|
||||
* `hide` - Hide content based on [Content Flags](/help/content_flags/).
|
||||
* `sort` - Sort by (`name`, `title`, `score`, `downloads`, `created_at`).
|
||||
* `sort` - Sort by (`name`, `title`, `score`, `downloads`, `created_at`, `last_release`).
|
||||
* `order` - Sort ascending (`asc`) or descending (`desc`).
|
||||
* `protocol_version` - Only show packages supported by this Minetest protocol version.
|
||||
* `engine_version` - Only show packages supported by this Minetest engine version, eg: `5.3.0`.
|
||||
|
@ -457,6 +457,7 @@ class Package(db.Model):
|
||||
desc = db.Column(db.UnicodeText, nullable=True)
|
||||
type = db.Column(db.Enum(PackageType))
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
approved_at = db.Column(db.DateTime, nullable=True, default=None)
|
||||
|
||||
name_valid = db.CheckConstraint("name ~* '^[a-z0-9_]+$'")
|
||||
|
||||
|
@ -69,6 +69,11 @@ class QueryBuilder:
|
||||
return MinetestRelease.get(self.minetest_version, self.protocol_version)
|
||||
|
||||
def buildPackageQuery(self):
|
||||
query = None
|
||||
if self.order_by == "last_release":
|
||||
query = db.session.query(Package).select_from(PackageRelease).join(Package) \
|
||||
.filter_by(soft_deleted=False, approved=True)
|
||||
else:
|
||||
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
||||
|
||||
if len(self.types) > 0:
|
||||
@ -93,6 +98,8 @@ class QueryBuilder:
|
||||
to_order = Package.downloads
|
||||
elif self.order_by == "created_at" or self.order_by == "date":
|
||||
to_order = Package.created_at
|
||||
elif self.order_by == "last_release":
|
||||
to_order = PackageRelease.releaseDate
|
||||
else:
|
||||
abort(400)
|
||||
|
||||
|
@ -23,18 +23,11 @@
|
||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', sort='created_at', order='desc') }}" class="btn btn-secondary float-right">
|
||||
<a href="{{ url_for('packages.list_all', sort='last_release', order='desc') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
<h2 class="my-3">{{ _("Recently Added") }}</h2>
|
||||
{{ render_pkggrid(new) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', type='mod', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
<h2 class="my-3">{{ _("Top Mods") }}</h2>
|
||||
{{ render_pkggrid(pop_mod) }}
|
||||
<h2 class="my-3">{{ _("Recently Updated") }}</h2>
|
||||
{{ render_pkggrid(updated) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', type='game', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||
@ -44,6 +37,13 @@
|
||||
{{ render_pkggrid(pop_gam) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', type='mod', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
<h2 class="my-3">{{ _("Top Mods") }}</h2>
|
||||
{{ render_pkggrid(pop_mod) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', type='txp', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
@ -51,6 +51,13 @@
|
||||
{{ render_pkggrid(pop_txp) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_all', sort='created_at', order='desc') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
<h2 class="my-3">{{ _("Recently Added") }}</h2>
|
||||
{{ render_pkggrid(new) }}
|
||||
|
||||
|
||||
<a href="{{ url_for('packages.list_reviews') }}" class="btn btn-secondary float-right">
|
||||
{{ _("See more") }}
|
||||
</a>
|
||||
|
33
migrations/versions/dff4b87e4a76_.py
Normal file
33
migrations/versions/dff4b87e4a76_.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: dff4b87e4a76
|
||||
Revises: 3a24fc02365e
|
||||
Create Date: 2020-07-17 23:47:51.096874
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import datetime
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'dff4b87e4a76'
|
||||
down_revision = '3a24fc02365e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('package', sa.Column('approved_at', sa.DateTime(), nullable=True, server_default=None))
|
||||
|
||||
op.execute("""
|
||||
UPDATE package SET approved_at=created_at WHERE approved;
|
||||
""")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('package', 'approved_at')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user