Add tags list to homepage

This commit is contained in:
rubenwardy 2020-07-18 02:48:22 +01:00
parent c7b1dcec4f
commit 68a132f271
3 changed files with 22 additions and 7 deletions

View File

@ -34,5 +34,8 @@ def home():
downloads_result = db.session.query(func.sum(Package.downloads)).one_or_none()
downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0]
return render_template("index.html", count=count, downloads=downloads, \
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)).all()
return render_template("index.html", count=count, downloads=downloads, tags=tags, \
new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, reviews=reviews)

View File

@ -58,6 +58,20 @@
{{ render_pkggrid(pop_txp) }}
<h2 class="my-3">{{ _("Search by Tags") }}</h2>
{% for pair in tags %}
{% set count = pair[0] %}
{% set tag = pair[1] %}
<a class="btn btn-sm btn-secondary m-1" rel="nofollow"
href="{{ url_for('packages.list_all', tag=tag.name) }}">
{{ tag.title }}
<span class="badge badge-pill badge-light ml-1">{{ count }}</span>
</a>
{% endfor %}
<div class="clearfix mb-4"></div>
<a href="{{ url_for('packages.list_reviews') }}" class="btn btn-secondary float-right">
{{ _("See more") }}
</a>

View File

@ -27,18 +27,16 @@
{% set tag = pair[1] %}
{% if tag in selected_tags %}
<a class="badge badge-primary" rel="nofollow"
<a class="btn btn-sm btn-primary m-1" rel="nofollow"
href="{{ url_set_query(page=1, _remove={ 'tag': tag.name }) }}">
{{ tag.title }}
({{ count }})
<span class="badge badge-pill badge-light ml-1">{{ count }}</span>
</a>
{% else %}
<a class="badge badge-secondary" rel="nofollow"
<a class="btn btn-sm btn-secondary m-1" rel="nofollow"
href="{{ url_set_query(page=1, _add={ 'tag': tag.name }) }}">
{{ tag.title }}
({{ count }})
<span class="badge badge-pill badge-light ml-1">{{ count }}</span>
</a>
{% endif %}
{% endfor %}