diff --git a/app/blueprints/donate/__init__.py b/app/blueprints/donate/__init__.py new file mode 100644 index 00000000..2ee52801 --- /dev/null +++ b/app/blueprints/donate/__init__.py @@ -0,0 +1,24 @@ +from flask import Blueprint, render_template +from flask_login import current_user + +from app.models import User, Package, PackageState, db, License + +bp = Blueprint("donate", __name__) + + +@bp.route("/donate/") +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() + + 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() + + return render_template("donate/index.html", + reviewed_packages=reviewed_packages, top_packages=top_packages, packages_count=packages_count) diff --git a/app/scss/custom.scss b/app/scss/custom.scss index d40a9bec..8215625e 100644 --- a/app/scss/custom.scss +++ b/app/scss/custom.scss @@ -15,6 +15,11 @@ footer { a:hover { color: #00bc8c; } + + .list-inline { + max-width: 520px; + margin: 0.25rem auto; + } } h1 { diff --git a/app/templates/base.html b/app/templates/base.html index 6912f460..7ede977a 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -6,7 +6,7 @@ {% block title %}title{% endblock %} - {{ config.USER_APP_NAME }} - + @@ -248,6 +248,7 @@
  • {{ _("Stats / Monitoring") }}
  • {{ _("User List") }}
  • {{ _("Threads") }}
  • +
  • {{ _("Support Packages") }}
  • {{ _("Source Code") }}
  • diff --git a/app/templates/donate/index.html b/app/templates/donate/index.html new file mode 100644 index 00000000..5fb19056 --- /dev/null +++ b/app/templates/donate/index.html @@ -0,0 +1,77 @@ +{% extends "base.html" %} + +{% block title %} + {{ _("Support packages") }} +{% endblock %} + +{% macro authorlink(author) %} + + {{ author.display_name }} + +{% endmacro %} + +{% macro render_packages(packages) %} + +{% endmacro %} + + +{% block content %} +

    {{ self.title() }}

    + +

    {{ _("Based on your reviews") }}

    + {% if reviewed_packages %} + {{ render_packages(reviewed_packages) }} + {% elif current_user.is_authenticated %} +

    + {{ _("No reviewed packages accepting donations. Considering reviewing your favourite packages") }} +

    + {% else %} +

    + {{ _("Sign in to see recommendations based on the packages you've reviewed") }} +

    +

    + {{ _("Sign in") }} +

    + {% endif %} + +

    {{ _("Top packages") }}

    + {{ render_packages(top_packages) }} +

    + + {{ _("%(count)d packages are looking for donations", count=packages_count) }} + +

    +{% endblock %}