mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 09:33:44 +01:00
Add tag filter list to package page
This commit is contained in:
parent
2faa0e4219
commit
ae4352068e
@ -80,12 +80,15 @@ def list_all():
|
|||||||
qb.show_discarded = True
|
qb.show_discarded = True
|
||||||
topics = qb.buildTopicQuery().all()
|
topics = qb.buildTopicQuery().all()
|
||||||
|
|
||||||
tags = Tag.query.all()
|
tags = db.session.query(func.count(Tags.c.tag_id), Tag) \
|
||||||
|
.select_from(Tag).outerjoin(Tags).group_by(Tag.id).order_by(db.asc(Tag.title))
|
||||||
|
|
||||||
|
selected_tags = set(qb.tags)
|
||||||
|
|
||||||
return render_template("packages/list.html", \
|
return render_template("packages/list.html", \
|
||||||
title=title, packages=query.items, topics=topics, \
|
title=title, packages=query.items, pagination=query, \
|
||||||
query=search, tags=tags, type=type_name, \
|
query=search, tags=tags, selected_tags=selected_tags, type=type_name, \
|
||||||
authors=authors, packages_count=query.total, \
|
authors=authors, packages_count=query.total, topics=topics)
|
||||||
pagination=query)
|
|
||||||
|
|
||||||
|
|
||||||
def getReleases(package):
|
def getReleases(package):
|
||||||
|
@ -19,20 +19,48 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
<div class="col-md-9">
|
||||||
{{ render_pkggrid(packages) }}
|
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||||
|
{{ render_pkggrid(packages) }}
|
||||||
|
|
||||||
|
|
||||||
{% from "macros/pagination.html" import render_pagination %}
|
{% from "macros/pagination.html" import render_pagination %}
|
||||||
{{ render_pagination(pagination, url_set_query) }}
|
{{ render_pagination(pagination, url_set_query) }}
|
||||||
|
|
||||||
|
|
||||||
{% if topics %}
|
{% if topics %}
|
||||||
<h2 style="margin-top:2em;">More content from the forums</h2>
|
<h2 style="margin-top:2em;">More content from the forums</h2>
|
||||||
|
|
||||||
{% from "macros/topics.html" import render_topics %}
|
{% from "macros/topics.html" import render_topics %}
|
||||||
{{ render_topics(topics, current_user) }}
|
{{ render_topics(topics, current_user) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<aside class="col-md-3">
|
||||||
|
<p class="text-muted">Filter by tags</p>
|
||||||
|
|
||||||
|
{% for pair in tags %}
|
||||||
|
{% set count = pair[0] %}
|
||||||
|
{% set tag = pair[1] %}
|
||||||
|
|
||||||
|
{% if tag in selected_tags %}
|
||||||
|
<a class="badge badge-primary"
|
||||||
|
href="{{ url_set_query(page=1, _remove={ 'tag': tag.name }) }}">
|
||||||
|
|
||||||
|
{{ tag.title }}
|
||||||
|
({{ count }})
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="badge badge-secondary"
|
||||||
|
href="{{ url_set_query(page=1, _add={ 'tag': tag.name }) }}">
|
||||||
|
|
||||||
|
{{ tag.title }}
|
||||||
|
({{ count }})
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
24
app/utils.py
24
app/utils.py
@ -22,6 +22,7 @@ from .models import *
|
|||||||
from . import app
|
from . import app
|
||||||
import random, string, os, imghdr
|
import random, string, os, imghdr
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
from werkzeug.datastructures import MultiDict
|
||||||
|
|
||||||
# These are given to Jinja in template_filters.py
|
# These are given to Jinja in template_filters.py
|
||||||
|
|
||||||
@ -33,9 +34,26 @@ def abs_url(path):
|
|||||||
return urljoin(app.config["BASE_URL"], path)
|
return urljoin(app.config["BASE_URL"], path)
|
||||||
|
|
||||||
def url_set_query(**kwargs):
|
def url_set_query(**kwargs):
|
||||||
args = dict(request.args)
|
args = MultiDict(request.args)
|
||||||
args.update(kwargs)
|
|
||||||
return url_for(request.endpoint, **args)
|
for key, value in kwargs.items():
|
||||||
|
if key == "_add":
|
||||||
|
for key2, value_to_add in value.items():
|
||||||
|
values = set(args.getlist(key2))
|
||||||
|
values.add(value_to_add)
|
||||||
|
args.setlist(key2, list(values))
|
||||||
|
elif key == "_remove":
|
||||||
|
for key2, value_to_remove in value.items():
|
||||||
|
values = set(args.getlist(key2))
|
||||||
|
values.discard(value_to_remove)
|
||||||
|
args.setlist(key2, list(values))
|
||||||
|
else:
|
||||||
|
args.setlist(key, [ value ])
|
||||||
|
|
||||||
|
|
||||||
|
dargs = dict(args.lists())
|
||||||
|
|
||||||
|
return url_for(request.endpoint, **dargs)
|
||||||
|
|
||||||
def get_int_or_abort(v, default=None):
|
def get_int_or_abort(v, default=None):
|
||||||
if v is None:
|
if v is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user