Improve YouTube history sorting and filters

This commit is contained in:
2026-08-16 21:55:18 +02:00
parent e22f7b2d0f
commit 8eb6917337
2 changed files with 31 additions and 3 deletions
+14 -2
View File
@@ -28,6 +28,18 @@
</p>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">{{ total }} vidéo{{ 's' if total > 1 else '' }} au total.</p>
</div>
<div class="flex flex-wrap gap-2 mb-6" aria-label="Filtrer l'historique des vidéos">
<a href="{{ url_for('youtubeHistory') }}" class="px-4 py-2 rounded-lg text-sm font-medium transition-colors {{ 'bg-red-600 text-white' if history_filter == 'all' else 'bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300' }}">
Toutes
</a>
<a href="{{ url_for('youtubeHistory', filter='video') }}" class="px-4 py-2 rounded-lg text-sm font-medium transition-colors {{ 'bg-red-600 text-white' if history_filter == 'video' else 'bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300' }}">
Vidéos
</a>
<a href="{{ url_for('youtubeHistory', filter='short') }}" class="px-4 py-2 rounded-lg text-sm font-medium transition-colors {{ 'bg-red-600 text-white' if history_filter == 'short' else 'bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300' }}">
Shorts
</a>
</div>
</div>
{% if history %}
@@ -99,7 +111,7 @@
{% if total_pages > 1 %}
<div class="mt-8 flex items-center justify-center gap-2">
{% if page > 1 %}
<a href="{{ url_for('youtubeHistory', page=page-1) }}" class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm">
<a href="{{ url_for('youtubeHistory', page=page-1, filter=history_filter) }}" class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm">
Précédent
</a>
{% endif %}
@@ -107,7 +119,7 @@
Page {{ page }} / {{ total_pages }}
</span>
{% if page < total_pages %}
<a href="{{ url_for('youtubeHistory', page=page+1) }}" class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm">
<a href="{{ url_for('youtubeHistory', page=page+1, filter=history_filter) }}" class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm">
Suivant
</a>
{% endif %}
+17 -1
View File
@@ -201,7 +201,22 @@ def delYouTube(id):
def youtubeHistory():
page = request.args.get('page', 1, type=int)
per_page = 20
history_query = YouTubeVideoHistory.query.order_by(YouTubeVideoHistory.detected_at.desc())
history_filter = request.args.get('filter', 'all')
if history_filter not in {'all', 'video', 'short'}:
history_filter = 'all'
history_query = YouTubeVideoHistory.query
if history_filter == 'video':
history_query = history_query.filter(YouTubeVideoHistory.is_short.is_(False))
elif history_filter == 'short':
history_query = history_query.filter(YouTubeVideoHistory.is_short.is_(True))
# published_at provient du flux YouTube (format ISO 8601), ce qui permet de
# présenter les vidéos par date de publication, plutôt que par date de détection.
history_query = history_query.order_by(
YouTubeVideoHistory.published_at.desc(),
YouTubeVideoHistory.detected_at.desc(),
)
total = history_query.count()
history = history_query.offset((page - 1) * per_page).limit(per_page).all()
total_pages = (total + per_page - 1) // per_page
@@ -221,6 +236,7 @@ def youtubeHistory():
page=page,
total_pages=total_pages,
total=total,
history_filter=history_filter,
msg=msg,
msg_type=msg_type,
)