Skip to content

Commit

Permalink
Tender admin: new UserAdmin filter
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 20, 2024
1 parent b0fb1c9 commit fb3d76e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 17 additions & 1 deletion lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -177,6 +192,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"start_working_date",
ResponseKindFilter,
"siae_transactioned",
UserAdminFilter,
]
advanced_filter_fields = (
"kind",
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions lemarche/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit fb3d76e

Please sign in to comment.