Add page to find packages asking for donations

This commit is contained in:
rubenwardy 2023-03-05 17:31:21 +00:00
parent 4e154644ee
commit 08054e4969
4 changed files with 108 additions and 1 deletions

@ -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)

@ -15,6 +15,11 @@ footer {
a:hover {
color: #00bc8c;
}
.list-inline {
max-width: 520px;
margin: 0.25rem auto;
}
}
h1 {

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}title{% endblock %} - {{ config.USER_APP_NAME }}</title>
<link rel="stylesheet" type="text/css" href="/static/libs/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=37">
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=38">
<link rel="search" type="application/opensearchdescription+xml" href="/static/opensearch.xml" title="ContentDB" />
<link rel="shortcut icon" href="/favicon-16.png" sizes="16x16">
<link rel="icon" href="/favicon-128.png" sizes="128x128">
@ -248,6 +248,7 @@
<li class="list-inline-item"><a href="https://monitor.rubenwardy.com/d/3ELzFy3Wz/contentdb">{{ _("Stats / Monitoring") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('users.list_all') }}">{{ _("User List") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('threads.list_all') }}">{{ _("Threads") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('donate.donate') }}">{{ _("Support Packages") }}</a></li>
<li class="list-inline-item"><a href="https://github.com/minetest/contentdb">{{ _("Source Code") }}</a></li>
</ul>

@ -0,0 +1,77 @@
{% extends "base.html" %}
{% block title %}
{{ _("Support packages") }}
{% endblock %}
{% macro authorlink(author) %}
<a href="{{ url_for('users.profile', username=author.username) }}">
{{ author.display_name }}
</a>
{% endmacro %}
{% macro render_packages(packages) %}
<ul class="list-group">
{% for package in packages %}
<li class="list-group-item">
<div class="row">
<div class="col-sm-auto text-muted" style="min-width: 250px;">
<a href="{{ package.getURL('packages.view') }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
src="{{ package.getThumbnailOrPlaceholder() }}" />
<span class="pl-2">
{{ package.title }}
</span>
</a>
</div>
<div class="col-sm">
{{ _("by %(author)s", author=authorlink(package.author)) }}
</div>
<div class="col-sm-auto">
<a href="{{ package.getURL('packages.view') }}" class="btn btn-sm btn-secondary mr-1">
{{ _("View package") }}
</a>
<a href="{{ package.author.donate_url }}" class="btn btn-sm btn-primary" rel="nofollow">
<i class="fas fa-heart mr-1"></i>
{{ _("Donate") }}
</a>
</div>
</div>
</li>
{% endfor %}
</ul>
{% endmacro %}
{% block content %}
<h1>{{ self.title() }}</h1>
<h2>{{ _("Based on your reviews") }}</h2>
{% if reviewed_packages %}
{{ render_packages(reviewed_packages) }}
{% elif current_user.is_authenticated %}
<p class="text-muted">
{{ _("No reviewed packages accepting donations. Considering reviewing your favourite packages") }}
</p>
{% else %}
<p>
{{ _("Sign in to see recommendations based on the packages you've reviewed") }}
</p>
<p>
<a class="btn btn-primary" href="{{ url_for('users.login') }}">{{ _("Sign in") }}</a>
</p>
{% endif %}
<h2>{{ _("Top packages") }}</h2>
{{ render_packages(top_packages) }}
<p class="text-center mt-5">
<small>
{{ _("%(count)d packages are looking for donations", count=packages_count) }}
</small>
</p>
{% endblock %}