Add per-package donate URLs

This commit is contained in:
rubenwardy
2023-03-05 18:13:07 +00:00
parent 08054e4969
commit 07f5d2e0d5
11 changed files with 58 additions and 11 deletions

View File

@@ -723,5 +723,10 @@ def json_schema():
"type": ["string", "null"],
"format": "uri"
},
"donate_url": {
"description": "URL to a donation page",
"type": ["string", "null"],
"format": "uri"
},
},
})

View File

@@ -1,5 +1,6 @@
from flask import Blueprint, render_template
from flask_login import current_user
from sqlalchemy import or_
from app.models import User, Package, PackageState, db, License
@@ -11,12 +12,18 @@ def donate():
reviewed_packages = None
if current_user.is_authenticated:
reviewed_packages = Package.query.filter(
Package.state == PackageState.APPROVED,
Package.reviews.any(author_id=current_user.id, recommends=True),
Package.author.has(User.donate_url.isnot(None))).order_by(db.asc(Package.title)).all()
Package.state == PackageState.APPROVED,
Package.reviews.any(author_id=current_user.id, recommends=True),
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))
query = Package.query.filter(Package.license.has(License.is_foss == True), Package.media_license.has(License.is_foss == True),
Package.state == PackageState.APPROVED, Package.author.has(User.donate_url.isnot(None))).order_by(db.desc(Package.score))
packages_count = query.count()
top_packages = query.limit(40).all()

View File

@@ -248,7 +248,8 @@ class PackageForm(FlaskForm):
website = StringField(lazy_gettext("Website URL"), [Optional(), URL()], filters = [lambda x: x or None])
issueTracker = StringField(lazy_gettext("Issue Tracker URL"), [Optional(), URL()], filters = [lambda x: x or None])
forums = IntegerField(lazy_gettext("Forum Topic ID"), [Optional(), NumberRange(0,999999)])
video_url = StringField(lazy_gettext("Video URL"), [Optional(), URL()], filters = [lambda x: x or None])
video_url = StringField(lazy_gettext("Video URL"), [Optional(), URL()], filters=[lambda x: x or None])
donate_url = StringField(lazy_gettext("Donate URL"), [Optional(), URL()], filters=[lambda x: x or None])
submit = SubmitField(lazy_gettext("Save"))
@@ -294,6 +295,7 @@ def handle_create_edit(package: typing.Optional[Package], form: PackageForm, aut
"issueTracker": form.issueTracker.data,
"forums": form.forums.data,
"video_url": form.video_url.data,
"donate_url": form.donate_url.data,
})
if wasNew: