Skip to content

Commit

Permalink
Use clearer labels for structure membership
Browse files Browse the repository at this point in the history
Following cf47b66, use the helper for
more memberships.
  • Loading branch information
francoisfreitag committed Dec 17, 2024
1 parent 97c7445 commit d9dbf58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions itou/approvals/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ItouTabularInline,
PkSupportRemarkInline,
get_admin_view_link,
get_company_view_link,
get_structure_view_link,
)
from itou.utils.templatetags.str_filters import pluralizefr

Expand Down Expand Up @@ -60,7 +60,7 @@ def has_add_permission(self, request, obj=None):

@admin.display(description="Entreprise destinataire")
def to_company_link(self, obj):
return get_company_view_link(obj.to_company)
return get_structure_view_link(obj.to_company, display_attr="display_name")

# Custom read-only fields as workaround :
# there is no direct relation between approvals and employee records
Expand Down
8 changes: 4 additions & 4 deletions itou/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
PkSupportRemarkInline,
add_support_remark_to_obj,
get_admin_view_link,
get_company_view_link,
get_structure_view_link,
)


Expand Down Expand Up @@ -106,7 +106,7 @@ def has_add_permission(self, request, obj=None):

@admin.display(description="Entreprise")
def company_siret_link(self, obj):
return get_company_view_link(obj.company)
return get_structure_view_link(obj.company)


class PrescriberMembershipInline(DisabledNotificationsMixin, ItouTabularInline):
Expand Down Expand Up @@ -134,7 +134,7 @@ def has_add_permission(self, request, obj=None):
return True

def organization_id_link(self, obj):
return get_admin_view_link(obj.organization)
return get_structure_view_link(obj.organization)


class InstitutionMembershipInline(ItouTabularInline):
Expand Down Expand Up @@ -165,7 +165,7 @@ def has_add_permission(self, request, obj=None):
return True

def institution_id_link(self, obj):
return get_admin_view_link(obj.institution)
return get_structure_view_link(obj.institution)


class JobApplicationInline(ItouTabularInline):
Expand Down
16 changes: 9 additions & 7 deletions itou/utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def get_admin_view_link(obj, *, content=None, view="change"):
return format_html('<a href="{}">{}</a>', url, content or obj.pk)


def get_company_view_link(company):
return format_html(
"{} — SIRET : {} ({})",
get_admin_view_link(company, content=company.display_name),
company.siret,
company.kind,
)
def get_structure_view_link(structure, display_attr="name"):
format_string = "{link}"
format_kwargs = {"link": get_admin_view_link(structure, content=getattr(structure, display_attr))}
if hasattr(structure, "siret"):
format_string += " — SIRET {siret}"
format_kwargs["siret"] = structure.siret
format_string += " ({kind})"
format_kwargs["kind"] = structure.kind
return format_html(format_string, **format_kwargs)


class AbstractSupportRemarkInline(GenericStackedInline):
Expand Down

0 comments on commit d9dbf58

Please sign in to comment.