2021-11-23 02:05:43 +01:00
|
|
|
from flask import Blueprint, render_template, redirect
|
2019-11-16 00:51:42 +01:00
|
|
|
|
|
|
|
bp = Blueprint("homepage", __name__)
|
|
|
|
|
|
|
|
from app.models import *
|
2020-04-21 21:35:05 +02:00
|
|
|
from sqlalchemy.orm import joinedload
|
2019-11-16 00:51:42 +01:00
|
|
|
from sqlalchemy.sql.expression import func
|
2021-11-23 01:58:53 +01:00
|
|
|
|
|
|
|
|
2022-10-26 10:43:23 +02:00
|
|
|
GAMEJAM_BANNER = "https://raw.githubusercontent.com/GreenXenith/minetestgamejam/master/2022/images/banner_textless.png"
|
|
|
|
|
|
|
|
|
2022-10-25 18:24:43 +02:00
|
|
|
class GameJam:
|
2022-10-26 10:43:23 +02:00
|
|
|
cover_image = type("", (), dict(url=GAMEJAM_BANNER))()
|
2022-10-25 18:24:43 +02:00
|
|
|
tags = []
|
|
|
|
|
|
|
|
def getCoverImageURL(self):
|
2022-10-26 10:43:23 +02:00
|
|
|
return GAMEJAM_BANNER
|
2022-10-25 18:24:43 +02:00
|
|
|
|
|
|
|
def getURL(self, _name):
|
|
|
|
return "/gamejam/"
|
|
|
|
|
|
|
|
title = "Minetest Game Jam 2022"
|
|
|
|
author = None
|
|
|
|
|
|
|
|
short_desc = "It's back! We're holding a 3-week Game Jam starting November 1st. Sharpen your gamedev skills with a " \
|
|
|
|
"chance for cash prizes. "
|
|
|
|
type = type("", (), dict(value="Competition"))()
|
|
|
|
content_warnings = []
|
|
|
|
reviews = []
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/gamejam/")
|
|
|
|
def gamejam():
|
|
|
|
return redirect("https://forum.minetest.net/viewtopic.php?t=28802")
|
|
|
|
|
|
|
|
|
2019-11-16 00:51:42 +01:00
|
|
|
@bp.route("/")
|
2019-11-21 20:38:26 +01:00
|
|
|
def home():
|
2020-04-21 21:35:05 +02:00
|
|
|
def join(query):
|
2020-12-04 03:23:04 +01:00
|
|
|
return query.options(
|
|
|
|
joinedload(Package.license),
|
|
|
|
joinedload(Package.media_license))
|
2020-04-21 21:35:05 +02:00
|
|
|
|
2020-09-16 18:51:03 +02:00
|
|
|
query = Package.query.filter_by(state=PackageState.APPROVED)
|
2019-11-16 00:51:42 +01:00
|
|
|
count = query.count()
|
2020-07-18 02:22:52 +02:00
|
|
|
|
2021-07-22 15:05:59 +02:00
|
|
|
featured = query.filter(Package.tags.any(name="featured")).order_by(func.random()).limit(6).all()
|
2022-10-25 18:24:43 +02:00
|
|
|
featured.insert(0, GameJam())
|
2021-07-22 13:13:16 +02:00
|
|
|
|
2020-12-14 12:52:38 +01:00
|
|
|
new = join(query.order_by(db.desc(Package.approved_at))).limit(4).all()
|
2020-04-21 21:35:05 +02:00
|
|
|
pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all()
|
2020-12-14 12:52:38 +01:00
|
|
|
pop_gam = join(query.filter_by(type=PackageType.GAME).order_by(db.desc(Package.score))).limit(8).all()
|
|
|
|
pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(8).all()
|
2020-12-14 12:48:07 +01:00
|
|
|
high_reviewed = join(query.order_by(db.desc(Package.score - Package.score_downloads))) \
|
|
|
|
.filter(Package.reviews.any()).limit(4).all()
|
2020-07-18 02:22:52 +02:00
|
|
|
|
|
|
|
updated = db.session.query(Package).select_from(PackageRelease).join(Package) \
|
2020-09-16 18:51:03 +02:00
|
|
|
.filter_by(state=PackageState.APPROVED) \
|
2020-07-18 02:22:52 +02:00
|
|
|
.order_by(db.desc(PackageRelease.releaseDate)) \
|
2020-07-18 02:27:23 +02:00
|
|
|
.limit(20).all()
|
2020-12-14 12:48:07 +01:00
|
|
|
updated = updated[:4]
|
2020-07-18 02:22:52 +02:00
|
|
|
|
2020-07-09 06:22:58 +02:00
|
|
|
reviews = PackageReview.query.filter_by(recommends=True).order_by(db.desc(PackageReview.created_at)).limit(5).all()
|
2020-07-18 02:22:52 +02:00
|
|
|
|
2020-07-09 02:11:50 +02:00
|
|
|
downloads_result = db.session.query(func.sum(Package.downloads)).one_or_none()
|
2020-01-19 16:03:38 +01:00
|
|
|
downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0]
|
2020-07-18 02:22:52 +02:00
|
|
|
|
2020-07-18 03:48:22 +02:00
|
|
|
tags = db.session.query(func.count(Tags.c.tag_id), Tag) \
|
|
|
|
.select_from(Tag).outerjoin(Tags).group_by(Tag.id).order_by(db.asc(Tag.title)).all()
|
|
|
|
|
2021-07-22 13:13:16 +02:00
|
|
|
return render_template("index.html", count=count, downloads=downloads, tags=tags, featured=featured,
|
2020-12-14 12:48:07 +01:00
|
|
|
new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, high_reviewed=high_reviewed, reviews=reviews)
|