2023-03-05 18:31:21 +01:00
|
|
|
from flask import Blueprint, render_template
|
|
|
|
from flask_login import current_user
|
2023-04-30 01:27:10 +02:00
|
|
|
from sqlalchemy import or_, and_
|
2023-03-05 18:31:21 +01:00
|
|
|
|
2023-04-15 03:37:58 +02:00
|
|
|
from app.models import User, Package, PackageState, db, License, PackageReview
|
2023-03-05 18:31:21 +01:00
|
|
|
|
|
|
|
bp = Blueprint("donate", __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/donate/")
|
|
|
|
def donate():
|
|
|
|
reviewed_packages = None
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
reviewed_packages = Package.query.filter(
|
2023-03-05 19:13:07 +01:00
|
|
|
Package.state == PackageState.APPROVED,
|
2023-04-30 01:27:10 +02:00
|
|
|
Package.reviews.any(and_(PackageReview.author_id == current_user.id, PackageReview.rating >= 3)),
|
2023-03-05 19:13:07 +01:00
|
|
|
or_(Package.donate_url.isnot(None), Package.author.has(User.donate_url.isnot(None)))
|
|
|
|
).order_by(db.asc(Package.title)).all()
|
|
|
|
|
|
|
|
query = Package.query.filter(
|
|
|
|
Package.license.has(License.is_foss == True),
|
|
|
|
Package.media_license.has(License.is_foss == True),
|
|
|
|
Package.state == PackageState.APPROVED,
|
|
|
|
or_(Package.donate_url.isnot(None), Package.author.has(User.donate_url.isnot(None)))
|
|
|
|
).order_by(db.desc(Package.score))
|
2023-03-05 18:31:21 +01:00
|
|
|
|
|
|
|
packages_count = query.count()
|
|
|
|
top_packages = query.limit(40).all()
|
|
|
|
|
|
|
|
return render_template("donate/index.html",
|
|
|
|
reviewed_packages=reviewed_packages, top_packages=top_packages, packages_count=packages_count)
|