diff --git a/lemarche/siaes/admin.py b/lemarche/siaes/admin.py index 6e5d5d84c..b0d44ccbf 100644 --- a/lemarche/siaes/admin.py +++ b/lemarche/siaes/admin.py @@ -413,7 +413,7 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin): def get_queryset(self, request): qs = super().get_queryset(request) - qs = qs.with_tender_stats() + # qs = qs.with_tender_stats() return qs def get_readonly_fields(self, request, obj=None): diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index f29d4157d..70fff8af9 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -108,6 +108,21 @@ def queryset(self, request, queryset): return queryset +class UserAdminFilter(admin.SimpleListFilter): + title = "Suivi bizdev" + parameter_name = "admins" + + def lookups(self, request, model_admin): + admins = User.objects.is_admin_bizdev().values("id", "first_name") + return [(admin["id"], admin["first_name"]) for admin in admins] + + def queryset(self, request, queryset): + lookup_value = self.value() + if lookup_value: + queryset = queryset.filter(admins__id__exact=lookup_value) + return queryset + + class TenderNoteInline(GenericTabularInline): model = Note fields = ["text", "author", "created_at", "updated_at"] @@ -177,6 +192,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): "start_working_date", ResponseKindFilter, "siae_transactioned", + UserAdminFilter, ] advanced_filter_fields = ( "kind", @@ -383,7 +399,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): def get_queryset(self, request): qs = super().get_queryset(request) qs = qs.select_related("author") - qs = qs.with_siae_stats() + # qs = qs.with_siae_stats() # qs = qs.with_question_stats() # doesn't work when chaining these 2 querysets: adds duplicates... return qs diff --git a/lemarche/users/models.py b/lemarche/users/models.py index 5c143344a..0c25c008a 100644 --- a/lemarche/users/models.py +++ b/lemarche/users/models.py @@ -20,6 +20,9 @@ class UserQueryset(models.QuerySet): Custom queryset with additional filtering methods for users. """ + def is_admin_bizdev(self): + return self.filter(kind=user_constants.KIND_ADMIN, position="Bizdev", is_staff=True) + def has_company(self): return self.filter(company__isnull=False).distinct() @@ -88,6 +91,9 @@ def create_superuser(self, email, password, **extra_fields): return self.create_user(email, password, **extra_fields) + def is_admin_bizdev(self): + return self.get_queryset().is_admin_bizdev() + def has_company(self): return self.get_queryset().has_company()