From 0a77a0110d9a4f7f1a6f85d22a7b8ef1954cdd7b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 1 Jun 2023 17:55:00 +0100 Subject: [PATCH] Split Featured tag into Featured and Spotlight --- app/blueprints/api/endpoints.py | 11 ++++------- app/blueprints/homepage/__init__.py | 4 ++-- app/default_data.py | 3 ++- app/templates/index.html | 10 +++++----- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index f98a34de..68cf6cfd 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -77,9 +77,9 @@ def packages(): pkgs = [package for package in pkgs if package.get("release")] # Promote featured packages - if "sort" not in request.args and "order" not in request.args: + if "sort" not in request.args and "order" not in request.args and "q" not in request.args: featured_lut = set() - featured = qb.convertToDictionary(query.filter(Package.tags.any(name="featured")).all()) + featured = qb.convertToDictionary(query.filter(Package.tags.any(name="featured")).all())[:3] for pkg in featured: featured_lut.add(f"{pkg['author']}/{pkg['name']}") pkg["short_description"] = "Featured. " + pkg["short_description"] @@ -529,7 +529,7 @@ def homepage(): query = Package.query.filter_by(state=PackageState.APPROVED) count = query.count() - featured = query.filter(Package.tags.any(name="featured")).order_by( + spotlight = query.filter(Package.tags.any(name="spotlight")).order_by( func.random()).limit(6).all() new = query.order_by(db.desc(Package.approved_at)).limit(4).all() pop_mod = query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score)).limit(8).all() @@ -553,7 +553,7 @@ def homepage(): return jsonify({ "count": count, "downloads": downloads, - "featured": mapPackages(featured), + "spotlight": mapPackages(spotlight), "new": mapPackages(new), "updated": mapPackages(updated), "pop_mod": mapPackages(pop_mod), @@ -572,9 +572,6 @@ def welcome_v1(): .order_by(func.random()) \ .limit(5).all() - mtg = Package.query.filter(Package.author.has(username="Minetest"), Package.name == "minetest_game").one() - featured.insert(2, mtg) - def map_packages(packages: List[Package]): return [pkg.getAsDictionaryShort(current_app.config["BASE_URL"]) for pkg in packages] diff --git a/app/blueprints/homepage/__init__.py b/app/blueprints/homepage/__init__.py index e8a77c52..5f5fa19f 100644 --- a/app/blueprints/homepage/__init__.py +++ b/app/blueprints/homepage/__init__.py @@ -32,7 +32,7 @@ def home(): query = Package.query.filter_by(state=PackageState.APPROVED) count = query.count() - featured = query.filter(Package.tags.any(name="featured")).order_by(func.random()).limit(6).all() + spotlight_pkgs = query.filter(Package.tags.any(name="spotlight")).order_by(func.random()).limit(6).all() new = package_load(query.order_by(db.desc(Package.approved_at))).limit(4).all() pop_mod = package_load(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all() @@ -57,5 +57,5 @@ def home(): .select_from(Tag).outerjoin(Tags).join(Package).filter(Package.state == PackageState.APPROVED)\ .group_by(Tag.id).order_by(db.asc(Tag.title)).all() - return render_template("index.html", count=count, downloads=downloads, tags=tags, featured=featured, + return render_template("index.html", count=count, downloads=downloads, tags=tags, spotlight_pkgs=spotlight_pkgs, new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, high_reviewed=high_reviewed, reviews=reviews) diff --git a/app/default_data.py b/app/default_data.py index 3d0802de..7db893e0 100644 --- a/app/default_data.py +++ b/app/default_data.py @@ -27,7 +27,8 @@ def populate(session): for tag in ["Inventory", "Mapgen", "Building", "Mobs and NPCs", "Tools", "Player effects", "Environment", "Transport", "Maintenance", "Plants and farming", - "PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer", "Featured"]: + "PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer", + "Featured", "Spotlight"]: row = Tag(tag) tags[row.name] = row session.add(row) diff --git a/app/templates/index.html b/app/templates/index.html index 19e852fc..ce15cf2f 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -27,12 +27,12 @@ {% from "macros/packagegridtile.html" import render_pkggrid %}