WIP: search: Read user choices
This commit is contained in:
parent
3934f4e062
commit
aa34c3e9da
|
@ -4,6 +4,7 @@ from app.models.post import Post
|
|||
from app.models.comment import Comment
|
||||
from app.models.topic import Topic
|
||||
from app.models.program import Program
|
||||
from app.models.forum import Forum
|
||||
from app.utils.render import render
|
||||
from sqlalchemy import func, Date
|
||||
from flask import request
|
||||
|
@ -74,6 +75,136 @@ def search(page=1):
|
|||
Comment.date_created.cast(Date) == form.date.data
|
||||
)
|
||||
|
||||
all_forum = False
|
||||
all_programs = False
|
||||
all_tutorials = False
|
||||
all_sprites = False
|
||||
for i in form.scope.iter_choices():
|
||||
if i[2] is True:
|
||||
match i[0]:
|
||||
case 'all-forum':
|
||||
all_forum = True
|
||||
continue
|
||||
case 'news-forum':
|
||||
if all_forum:
|
||||
continue
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'news'
|
||||
)
|
||||
break
|
||||
case 'help-and-questions-forum':
|
||||
if all_forum:
|
||||
continue
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'help'
|
||||
)
|
||||
break
|
||||
case 'projects-forum':
|
||||
if all_forum:
|
||||
continue
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'projects'
|
||||
)
|
||||
break
|
||||
case 'community-forum':
|
||||
if all_forum:
|
||||
continue
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'community'
|
||||
)
|
||||
break
|
||||
case 'discussions-forum':
|
||||
if all_forum:
|
||||
continue
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'discussion'
|
||||
)
|
||||
break
|
||||
case 'administration-forum':
|
||||
f = Forum.query.filter_by(prefix='admin').first()
|
||||
# If the user can access the forum
|
||||
if all_forum and current_user.is_authenticated and current_user.can_access_forum(f):
|
||||
continue
|
||||
elif all_forum:
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix != 'admin'
|
||||
)
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'admin'
|
||||
)
|
||||
break
|
||||
case 'creativecalc-forum':
|
||||
f = Forum.query.filter_by(prefix='creativecalc').first()
|
||||
# If the user can access the forum
|
||||
if all_forum and current_user.is_authenticated and current_user.can_access_forum(f):
|
||||
continue
|
||||
elif all_forum:
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix != 'creativecalc'
|
||||
)
|
||||
topic_query = topic_query.where(
|
||||
Topic.forum.prefix == 'creativecalc'
|
||||
)
|
||||
break
|
||||
case 'all-programs':
|
||||
all_programs = True
|
||||
continue
|
||||
case 'games-programs':
|
||||
if all_programs:
|
||||
continue
|
||||
program_query = program_query.where(
|
||||
len([x for x in Program.tags if x.tag_id.split('.')[0] == 'calc']) != 0
|
||||
)
|
||||
break
|
||||
case 'utilities-programs':
|
||||
if all_programs:
|
||||
continue
|
||||
break
|
||||
case 'software-programs':
|
||||
if all_programs:
|
||||
continue
|
||||
break
|
||||
case 'all-users':
|
||||
continue
|
||||
case 'all-tutorials':
|
||||
all_tutorials = True
|
||||
continue
|
||||
case 'basic-tutorials':
|
||||
if all_tutorials:
|
||||
continue
|
||||
break
|
||||
case 'c-cpp-tutorials':
|
||||
if all_tutorials:
|
||||
continue
|
||||
break
|
||||
case 'arduino-tutorials':
|
||||
if all_tutorials:
|
||||
continue
|
||||
break
|
||||
case 'python-tutorials':
|
||||
if all_tutorials:
|
||||
continue
|
||||
break
|
||||
case 'all-sprites':
|
||||
all_sprites = True
|
||||
continue
|
||||
case 'characters-sprites':
|
||||
if all_sprites:
|
||||
continue
|
||||
break
|
||||
case 'environnement-sprites':
|
||||
if all_sprites:
|
||||
continue
|
||||
break
|
||||
case 'objects-sprites':
|
||||
if all_sprites:
|
||||
continue
|
||||
break
|
||||
case 'interfaces-sprites':
|
||||
if all_sprites:
|
||||
continue
|
||||
break
|
||||
|
||||
match form.sortBy.data:
|
||||
case "Date croissante":
|
||||
topic_query = topic_query.order_by(
|
||||
|
|
Loading…
Reference in New Issue