mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 15:07:35 +01:00
Filter tags by available packages in package search
This commit is contained in:
parent
dd7146205a
commit
64dab0c4b6
@ -96,8 +96,9 @@ def list_all():
|
|||||||
qb.show_discarded = True
|
qb.show_discarded = True
|
||||||
topics = qb.buildTopicQuery().all()
|
topics = qb.buildTopicQuery().all()
|
||||||
|
|
||||||
tags = db.session.query(func.count(Tags.c.tag_id), Tag) \
|
tags_query = 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()
|
.select_from(Tag).join(Tags).join(Package).group_by(Tag.id).order_by(db.asc(Tag.title))
|
||||||
|
tags = qb.filterPackageQuery(tags_query).all()
|
||||||
|
|
||||||
selected_tags = set(qb.tags)
|
selected_tags = set(qb.tags)
|
||||||
|
|
||||||
|
@ -76,45 +76,12 @@ class QueryBuilder:
|
|||||||
else:
|
else:
|
||||||
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
||||||
|
|
||||||
|
return self.filterPackageQuery(self.orderPackageQuery(query))
|
||||||
|
|
||||||
|
def filterPackageQuery(self, query):
|
||||||
if len(self.types) > 0:
|
if len(self.types) > 0:
|
||||||
query = query.filter(Package.type.in_(self.types))
|
query = query.filter(Package.type.in_(self.types))
|
||||||
|
|
||||||
if self.search:
|
|
||||||
query = query.search(self.search, sort=self.order_by is None)
|
|
||||||
|
|
||||||
if self.random:
|
|
||||||
query = query.order_by(func.random())
|
|
||||||
else:
|
|
||||||
to_order = None
|
|
||||||
if self.order_by is None and self.search:
|
|
||||||
pass
|
|
||||||
elif self.order_by is None or self.order_by == "score":
|
|
||||||
to_order = Package.score
|
|
||||||
elif self.order_by == "name":
|
|
||||||
to_order = Package.name
|
|
||||||
elif self.order_by == "title":
|
|
||||||
to_order = Package.title
|
|
||||||
elif self.order_by == "downloads":
|
|
||||||
to_order = Package.downloads
|
|
||||||
elif self.order_by == "created_at" or self.order_by == "date":
|
|
||||||
to_order = Package.created_at
|
|
||||||
elif self.order_by == "approved_at" or self.order_by == "date":
|
|
||||||
to_order = Package.approved_at
|
|
||||||
elif self.order_by == "last_release":
|
|
||||||
to_order = PackageRelease.releaseDate
|
|
||||||
else:
|
|
||||||
abort(400)
|
|
||||||
|
|
||||||
if to_order:
|
|
||||||
if self.order_dir == "asc":
|
|
||||||
to_order = db.asc(to_order)
|
|
||||||
elif self.order_dir == "desc":
|
|
||||||
to_order = db.desc(to_order)
|
|
||||||
else:
|
|
||||||
abort(400)
|
|
||||||
|
|
||||||
query = query.order_by(to_order)
|
|
||||||
|
|
||||||
if self.author:
|
if self.author:
|
||||||
author = User.query.filter_by(username=self.author).first()
|
author = User.query.filter_by(username=self.author).first()
|
||||||
if not author:
|
if not author:
|
||||||
@ -150,6 +117,46 @@ class QueryBuilder:
|
|||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
def orderPackageQuery(self, query):
|
||||||
|
if self.search:
|
||||||
|
query = query.search(self.search, sort=self.order_by is None)
|
||||||
|
|
||||||
|
if self.random:
|
||||||
|
query = query.order_by(func.random())
|
||||||
|
return query
|
||||||
|
|
||||||
|
to_order = None
|
||||||
|
if self.order_by is None and self.search:
|
||||||
|
pass
|
||||||
|
elif self.order_by is None or self.order_by == "score":
|
||||||
|
to_order = Package.score
|
||||||
|
elif self.order_by == "name":
|
||||||
|
to_order = Package.name
|
||||||
|
elif self.order_by == "title":
|
||||||
|
to_order = Package.title
|
||||||
|
elif self.order_by == "downloads":
|
||||||
|
to_order = Package.downloads
|
||||||
|
elif self.order_by == "created_at" or self.order_by == "date":
|
||||||
|
to_order = Package.created_at
|
||||||
|
elif self.order_by == "approved_at" or self.order_by == "date":
|
||||||
|
to_order = Package.approved_at
|
||||||
|
elif self.order_by == "last_release":
|
||||||
|
to_order = PackageRelease.releaseDate
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
if to_order:
|
||||||
|
if self.order_dir == "asc":
|
||||||
|
to_order = db.asc(to_order)
|
||||||
|
elif self.order_dir == "desc":
|
||||||
|
to_order = db.desc(to_order)
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
query = query.order_by(to_order)
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
def buildTopicQuery(self, show_added=False):
|
def buildTopicQuery(self, show_added=False):
|
||||||
query = ForumTopic.query
|
query = ForumTopic.query
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user