mirror of
https://github.com/minetest/contentdb.git
synced 2025-03-25 03:12:40 +01:00
Collections: Add ability to pin to profile
This commit is contained in:
@ -80,6 +80,7 @@ class CollectionForm(FlaskForm):
|
|||||||
short_description = StringField(lazy_gettext("Short Description"), [Optional(), Length(0, 200)])
|
short_description = StringField(lazy_gettext("Short Description"), [Optional(), Length(0, 200)])
|
||||||
long_description = TextAreaField(lazy_gettext("Page Content"), [Optional()], filters=[nonempty_or_none])
|
long_description = TextAreaField(lazy_gettext("Page Content"), [Optional()], filters=[nonempty_or_none])
|
||||||
private = BooleanField(lazy_gettext("Private"))
|
private = BooleanField(lazy_gettext("Private"))
|
||||||
|
pinned = BooleanField(lazy_gettext("Pinned to my profile"))
|
||||||
descriptions = FieldList(
|
descriptions = FieldList(
|
||||||
StringField(lazy_gettext("Short Description"), [Optional(), Length(0, 500)], filters=[nonempty_or_none]),
|
StringField(lazy_gettext("Short Description"), [Optional(), Length(0, 500)], filters=[nonempty_or_none]),
|
||||||
min_entries=0)
|
min_entries=0)
|
||||||
@ -122,6 +123,7 @@ def create_edit(author=None, name=None):
|
|||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
# HACK: fix bug in wtforms
|
# HACK: fix bug in wtforms
|
||||||
form.private.data = collection.private if collection else False
|
form.private.data = collection.private if collection else False
|
||||||
|
form.pinned.data = collection.pinned if collection else False
|
||||||
if collection:
|
if collection:
|
||||||
for item in collection.items:
|
for item in collection.items:
|
||||||
form.descriptions.append_entry(item.description)
|
form.descriptions.append_entry(item.description)
|
||||||
@ -129,6 +131,7 @@ def create_edit(author=None, name=None):
|
|||||||
form.package_removed.append_entry("0")
|
form.package_removed.append_entry("0")
|
||||||
else:
|
else:
|
||||||
form.name = None
|
form.name = None
|
||||||
|
form.pinned = None
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
ret = handle_create_edit(collection, form, initial_packages, author)
|
ret = handle_create_edit(collection, form, initial_packages, author)
|
||||||
@ -319,6 +322,7 @@ def package_add(package):
|
|||||||
@login_required
|
@login_required
|
||||||
def package_toggle_favorite(package):
|
def package_toggle_favorite(package):
|
||||||
collection, _is_new = get_or_create_favorites(db.session)
|
collection, _is_new = get_or_create_favorites(db.session)
|
||||||
|
collection.author = current_user
|
||||||
|
|
||||||
if toggle_package(collection, package):
|
if toggle_package(collection, package):
|
||||||
msg = gettext("Added package to favorites collection")
|
msg = gettext("Added package to favorites collection")
|
||||||
|
@ -22,7 +22,7 @@ from flask_babel import gettext
|
|||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from sqlalchemy import func, text
|
from sqlalchemy import func, text
|
||||||
|
|
||||||
from app.models import User, db, Package, PackageReview, PackageState, PackageType, UserRank
|
from app.models import User, db, Package, PackageReview, PackageState, PackageType, UserRank, Collection
|
||||||
from app.utils import get_daterange_options
|
from app.utils import get_daterange_options
|
||||||
from app.tasks.forumtasks import check_forum_account
|
from app.tasks.forumtasks import check_forum_account
|
||||||
|
|
||||||
@ -230,11 +230,14 @@ def profile(username):
|
|||||||
.filter(Package.author != user) \
|
.filter(Package.author != user) \
|
||||||
.order_by(db.asc(Package.title)).all()
|
.order_by(db.asc(Package.title)).all()
|
||||||
|
|
||||||
|
pinned_collections = user.collections.filter(Collection.private == False,
|
||||||
|
Collection.pinned == True, Collection.packages.any()).all()
|
||||||
|
|
||||||
unlocked, locked = get_user_medals(user)
|
unlocked, locked = get_user_medals(user)
|
||||||
# Process GET or invalid POST
|
# Process GET or invalid POST
|
||||||
return render_template("users/profile.html", user=user,
|
return render_template("users/profile.html", user=user,
|
||||||
packages=packages, maintained_packages=maintained_packages,
|
packages=packages, maintained_packages=maintained_packages,
|
||||||
medals_unlocked=unlocked, medals_locked=locked)
|
medals_unlocked=unlocked, medals_locked=locked, pinned_collections=pinned_collections)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/users/<username>/check-forums/", methods=["POST"])
|
@bp.route("/users/<username>/check-forums/", methods=["POST"])
|
||||||
|
@ -101,3 +101,8 @@ def timedelta(value):
|
|||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def abs_url(url):
|
def abs_url(url):
|
||||||
return utils.abs_url(url)
|
return utils.abs_url(url)
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter()
|
||||||
|
def limit(arr, num):
|
||||||
|
return arr[:num]
|
||||||
|
@ -32,7 +32,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ render_field(form.short_description) }}
|
{{ render_field(form.short_description) }}
|
||||||
{{ render_checkbox_field(form.private, class_="my-3") }}
|
|
||||||
|
<div class="row my-5 gap-5">
|
||||||
|
<div class="col-md-auto">
|
||||||
|
{{ render_checkbox_field(form.private) }}
|
||||||
|
</div>
|
||||||
|
{% if form.pinned %}
|
||||||
|
<div class="col-md-auto">
|
||||||
|
{{ render_checkbox_field(form.pinned) }}
|
||||||
|
<p class="form-text mb-0">
|
||||||
|
{{ _("This requires the collection to be public") }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% if collection %}
|
{% if collection %}
|
||||||
{{ render_field(form.long_description, fieldclass="form-control markdown") }}
|
{{ render_field(form.long_description, fieldclass="form-control markdown") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -213,6 +213,21 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||||
|
|
||||||
|
{% for collection in pinned_collections %}
|
||||||
|
<section id="{{ collection.name }}" class="my-4">
|
||||||
|
<a class="float-end btn btn-primary btn-sm" href="{{ url_for('collections.view', author=collection.author.username, name=collection.name) }}">
|
||||||
|
View collection
|
||||||
|
</a>
|
||||||
|
<h2>{{ collection.title }}</h2>
|
||||||
|
{% set collection_packages = collection.packages | limit(4) %}
|
||||||
|
{{ render_pkggrid(collection_packages) }}
|
||||||
|
</section>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<section id="packages" class="my-4">
|
||||||
<div class="float-end">
|
<div class="float-end">
|
||||||
{% if packages %}
|
{% if packages %}
|
||||||
<div class="btn-group btn-group-sm me-2" role="group" aria-label="Sorting">
|
<div class="btn-group btn-group-sm me-2" role="group" aria-label="Sorting">
|
||||||
@ -245,9 +260,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="my-3">{{ _("Packages") }}</h2>
|
<h2 class="my-3">{{ _("Packages") }}</h2>
|
||||||
|
|
||||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
|
||||||
{{ render_pkggrid(packages, show_author=False) }}
|
{{ render_pkggrid(packages, show_author=False) }}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
{% if maintained_packages %}
|
{% if maintained_packages %}
|
||||||
|
Reference in New Issue
Block a user