refactor: replace full name logic with short_name template filter and utility across inspection views and templates
This commit is contained in:
parent
e6166b6adb
commit
6cfd80d61e
5 changed files with 13 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
{% load i18n static inspections_tags %}
|
{% load i18n static inspections_tags short_name %}
|
||||||
|
|
||||||
{# Inspections et contrôles liés à l'asset #}
|
{# Inspections et contrôles liés à l'asset #}
|
||||||
<div class="card mb-3" id="asset-inspections-card">
|
<div class="card mb-3" id="asset-inspections-card">
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
<span class="badge bg-light text-dark border">{{ insp.get_nature_display }}</span>
|
<span class="badge bg-light text-dark border">{{ insp.get_nature_display }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<i class="bi bi-person me-1 text-muted"></i>{{ insp.inspector.get_full_name|default:insp.inspector.username|default:"-" }}
|
<i class="bi bi-person me-1 text-muted"></i>{{ insp.inspector|short_name|default:insp.inspector.username|default:"-" }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="small text-muted text-truncate d-inline-block" style="max-width: 220px;" title="{{ insp.details_summary }}">
|
<span class="small text-muted text-truncate d-inline-block" style="max-width: 220px;" title="{{ insp.details_summary }}">
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
||||||
<span class="text-muted"><i class="bi bi-person me-1"></i>{% translate "Inspecteur" %}</span>
|
<span class="text-muted"><i class="bi bi-person me-1"></i>{% translate "Inspecteur" %}</span>
|
||||||
<span class="fw-semibold">{{ insp.inspector.get_full_name|default:insp.inspector.username|default:"-" }}</span>
|
<span class="fw-semibold">{{ insp.inspector|short_name|default:insp.inspector.username|default:"-" }}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{% get_inspection_detail_template insp as detail_template %}
|
{% get_inspection_detail_template insp as detail_template %}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ def short_name(user):
|
||||||
first = getattr(user, "first_name", "") or ""
|
first = getattr(user, "first_name", "") or ""
|
||||||
last = getattr(user, "last_name", "") or ""
|
last = getattr(user, "last_name", "") or ""
|
||||||
initial = (last[0].upper() + ".") if last else ""
|
initial = (last[0].upper() + ".") if last else ""
|
||||||
return f"{first} {initial}".strip()
|
res = f"{first} {initial}".strip()
|
||||||
|
return res if res else getattr(user, "username", "")
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,8 @@ def get_short_name(user):
|
||||||
first = getattr(user, "first_name", "") or ""
|
first = getattr(user, "first_name", "") or ""
|
||||||
last = getattr(user, "last_name", "") or ""
|
last = getattr(user, "last_name", "") or ""
|
||||||
initial = (last[0].upper() + ".") if last else ""
|
initial = (last[0].upper() + ".") if last else ""
|
||||||
return f"{first} {initial}".strip()
|
res = f"{first} {initial}".strip()
|
||||||
|
return res if res else getattr(user, "username", "")
|
||||||
|
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends base_template|default:"base.html" %}
|
{% extends base_template|default:"base.html" %}
|
||||||
{% load i18n static l10n %}
|
{% load i18n static l10n short_name %}
|
||||||
|
|
||||||
{% block title %}{% translate "Inspections d'assets" %}{% endblock %}
|
{% block title %}{% translate "Inspections d'assets" %}{% endblock %}
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if insp.inspector %}
|
{% if insp.inspector %}
|
||||||
<span><i class="bi bi-person me-1"></i>{{ insp.inspector.get_full_name|default:insp.inspector.username }}</span>
|
<span><i class="bi bi-person me-1"></i>{{ insp.inspector|short_name|default:insp.inspector.username }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -201,7 +201,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
||||||
<span class="text-muted"><i class="bi bi-person me-1"></i>{% translate "Inspecteur" %}</span>
|
<span class="text-muted"><i class="bi bi-person me-1"></i>{% translate "Inspecteur" %}</span>
|
||||||
<span class="fw-semibold">{{ insp.inspector.get_full_name|default:insp.inspector.username|default:"-" }}</span>
|
<span class="fw-semibold">{{ insp.inspector|short_name|default:insp.inspector.username|default:"-" }}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{% with leaf=insp.detailed_inspection %}
|
{% with leaf=insp.detailed_inspection %}
|
||||||
|
|
@ -454,7 +454,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
result: "{{ insp.get_result_status_display|escapejs }}",
|
result: "{{ insp.get_result_status_display|escapejs }}",
|
||||||
result_code: "{{ insp.result_status|escapejs }}",
|
result_code: "{{ insp.result_status|escapejs }}",
|
||||||
badge_class: "{{ insp.status_badge_class|escapejs }}",
|
badge_class: "{{ insp.status_badge_class|escapejs }}",
|
||||||
inspector: "{{ insp.inspector.get_full_name|default:insp.inspector.username|escapejs }}",
|
inspector: "{{ insp.inspector|short_name|default:insp.inspector.username|escapejs }}",
|
||||||
nature: "{{ insp.get_nature_display|escapejs }}",
|
nature: "{{ insp.get_nature_display|escapejs }}",
|
||||||
summary: "{{ insp.details_summary|escapejs }}"
|
summary: "{{ insp.details_summary|escapejs }}"
|
||||||
}{% if not forloop.last %},{% endif %}
|
}{% if not forloop.last %},{% endif %}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from django.utils import timezone
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from common.models import Thematic
|
from common.models import Thematic
|
||||||
|
from common.utils import get_short_name
|
||||||
from assets.models import AssetCategory
|
from assets.models import AssetCategory
|
||||||
from .models import (
|
from .models import (
|
||||||
Inspection, ParkingSpotInspection, GiepInspection, InspectionDocument,
|
Inspection, ParkingSpotInspection, GiepInspection, InspectionDocument,
|
||||||
|
|
@ -547,7 +548,7 @@ def inspections_geojson(request):
|
||||||
'result_status_display': insp.get_result_status_display(),
|
'result_status_display': insp.get_result_status_display(),
|
||||||
'status_badge_class': insp.status_badge_class,
|
'status_badge_class': insp.status_badge_class,
|
||||||
'nature_display': insp.get_nature_display(),
|
'nature_display': insp.get_nature_display(),
|
||||||
'inspector_name': insp.inspector.get_full_name() if insp.inspector else '-',
|
'inspector_name': get_short_name(insp.inspector) if insp.inspector else '-',
|
||||||
'inspector_role_display': insp.get_inspector_role_display() if insp.inspector_role else '',
|
'inspector_role_display': insp.get_inspector_role_display() if insp.inspector_role else '',
|
||||||
'details_summary': insp.details_summary,
|
'details_summary': insp.details_summary,
|
||||||
'notes': insp.notes or '',
|
'notes': insp.notes or '',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue