From 9326fdf14ff5392c18acde9443ce52ba53707e2e Mon Sep 17 00:00:00 2001 From: berk76 Date: Sat, 5 Oct 2024 23:19:48 +0200 Subject: [PATCH] Hide adverts created by deactivated users (#90) * Hide adverts created by deactivated users * Hide adverts created by deactivated users * Hide adverts created by deactivated users * Hide adverts created by deactivated users * Hide adverts created by deactivated users * Hide adverts created by deactivated users --- svjis/articles/views_adverts.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/svjis/articles/views_adverts.py b/svjis/articles/views_adverts.py index 94c509e..5559247 100644 --- a/svjis/articles/views_adverts.py +++ b/svjis/articles/views_adverts.py @@ -9,10 +9,13 @@ def get_side_menu(active_item, user): + description_template = '{} ({})' result = [] result.append( { - 'description': _("All") + f' ({models.Advert.objects.filter(published=True).count()})', + 'description': description_template.format( + _("All"), models.Advert.objects.filter(published=True, created_by_user__is_active=True).count() + ), 'link': reverse(adverts_list_view) + '?scope=all', 'active': True if active_item == 'all' else False, } @@ -22,7 +25,10 @@ def get_side_menu(active_item, user): for t in types: result.append( { - 'description': t.description + f' ({models.Advert.objects.filter(published=True, type=t).count()})', + 'description': description_template.format( + t.description, + models.Advert.objects.filter(published=True, created_by_user__is_active=True, type=t).count(), + ), 'link': reverse(adverts_list_view) + f'?scope={t.description}', 'active': True if active_item == t.description else False, } @@ -31,7 +37,9 @@ def get_side_menu(active_item, user): if user.has_perm('articles.svjis_add_advert'): result.append( { - 'description': _("Mine") + f' ({models.Advert.objects.filter(created_by_user=user).count()})', + 'description': description_template.format( + _("Mine"), models.Advert.objects.filter(created_by_user=user).count() + ), 'link': reverse(adverts_list_view) + '?scope=mine', 'active': True if active_item == 'mine' else False, } @@ -44,7 +52,7 @@ def get_side_menu(active_item, user): @permission_required("articles.svjis_view_adverts_menu") @require_GET def adverts_list_view(request): - advert_list = models.Advert.objects.filter(published=True) + advert_list = models.Advert.objects.filter(published=True, created_by_user__is_active=True) scope = request.GET.get('scope', 'all') scope_description = _('All')