search: Get publish date selector working

This commit is contained in:
Eragon 2023-09-27 23:11:29 +02:00
parent 0c3fa843d8
commit 4a23aee7d9
Signed by: Eragon
GPG Key ID: 087126EBFC725006
1 changed files with 11 additions and 1 deletions

View File

@ -6,7 +6,7 @@ from app.models.topic import Topic
from app.models.forum import Forum
from app.models.program import Program
from app.utils.render import render
from sqlalchemy import text, func
from sqlalchemy import text, func, Date
from flask import request
from flask_sqlalchemy import Pagination
@ -59,6 +59,16 @@ def search(page=1):
Comment.id,
Post.id
)
if (form.date.data):
topic_query = topic_query.where(
Topic.date_created.cast(Date) == form.date.data
)
program_query = program_query.where(
Program.date_created.cast(Date) == form.date.data
)
comment_query = comment_query.where(
Comment.date_created.cast(Date) == form.date.data
)
if (form.sortBy.data == "Date croissante"):
topic_query = topic_query.order_by(
Topic.date_created.asc()