Improve YouTube history sorting and filters
This commit is contained in:
@@ -28,6 +28,18 @@
|
|||||||
</p>
|
</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>
|
<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>
|
||||||
|
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
{% if history %}
|
{% if history %}
|
||||||
@@ -99,7 +111,7 @@
|
|||||||
{% if total_pages > 1 %}
|
{% if total_pages > 1 %}
|
||||||
<div class="mt-8 flex items-center justify-center gap-2">
|
<div class="mt-8 flex items-center justify-center gap-2">
|
||||||
{% if page > 1 %}
|
{% 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
|
Précédent
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -107,7 +119,7 @@
|
|||||||
Page {{ page }} / {{ total_pages }}
|
Page {{ page }} / {{ total_pages }}
|
||||||
</span>
|
</span>
|
||||||
{% if page < total_pages %}
|
{% 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
|
Suivant
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
+17
-1
@@ -201,7 +201,22 @@ def delYouTube(id):
|
|||||||
def youtubeHistory():
|
def youtubeHistory():
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
per_page = 20
|
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()
|
total = history_query.count()
|
||||||
history = history_query.offset((page - 1) * per_page).limit(per_page).all()
|
history = history_query.offset((page - 1) * per_page).limit(per_page).all()
|
||||||
total_pages = (total + per_page - 1) // per_page
|
total_pages = (total + per_page - 1) // per_page
|
||||||
@@ -221,6 +236,7 @@ def youtubeHistory():
|
|||||||
page=page,
|
page=page,
|
||||||
total_pages=total_pages,
|
total_pages=total_pages,
|
||||||
total=total,
|
total=total,
|
||||||
|
history_filter=history_filter,
|
||||||
msg=msg,
|
msg=msg,
|
||||||
msg_type=msg_type,
|
msg_type=msg_type,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user