Add ability to search by tag

This commit is contained in:
rubenwardy 2020-04-07 18:23:06 +01:00
parent 663a9ba07b
commit 39a09c5d92
2 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,5 @@
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User, Tag
from .models import tags as Tags
from .utils import isNo, isYes
from sqlalchemy.sql.expression import func
from flask import abort
@ -19,10 +20,17 @@ class QueryBuilder:
if len(types) > 0:
title = ", ".join([type.value + "s" for type in types])
# Get tags types
tags = args.getlist("tag")
tags = [Tag.query.filter_by(name=tname).first() for tname in tags]
tags = [tag for tag in tags if tag is not None]
# Hid
hide_flags = args.getlist("hide")
self.title = title
self.types = types
self.tags = tags
self.random = "random" in args
self.lucky = "lucky" in args
@ -96,6 +104,9 @@ class QueryBuilder:
query = query.filter_by(author=author)
for tag in self.tags:
query = query.filter(Package.tags.any(Tag.id == tag.id))
if self.hide_nonfree:
query = query.filter(Package.license.has(License.is_foss == True))
query = query.filter(Package.media_license.has(License.is_foss == True))

View File

@ -38,7 +38,8 @@
</span>
{% endif %}
{% for t in package.tags %}
<span class="badge badge-primary">{{ t.title }}</span>
<a class="badge badge-primary"
href="{{ url_for('packages.list_all', tag=t.name) }}">{{ t.title }}</a>
{% endfor %}
</p>