Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ class DefectInline(admin.TabularInline):
"solution_date",
"reporter_name",
"status",
"severity",
)
readonly_fields = ["creation_date", "solution_date"]


@admin.display(description="Nombre d'anomalies ouvertes")
def open_defect_count(obj: Vehicle):
return obj.defect_set.filter(status=Defect.DefectStatus.OPEN).count()
return obj.open_defects.count()


@admin.register(Vehicle)
Expand Down
8 changes: 3 additions & 5 deletions main/fixtures/main/initial_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"pk": 1,
"fields": {
"vehicle": "94deae57-cbac-4911-bcdf-14aa4b10448d",
"type": "engine",
"status": "OPEN",
"creation_date": "2024-05-28",
"solution_date": null,
Expand All @@ -93,11 +92,11 @@
"pk": 2,
"fields": {
"vehicle": "3a8798e8-c193-4e75-868c-982e2f24b576",
"type": "bulb",
"status": "OPEN",
"status": "CONFIRMED",
"creation_date": "2024-05-28",
"solution_date": null,
"comment": "Clignotant AVG",
"comment": "Clignotant AVG non fonctionnel",
"severity": "MAJOR",
"reporter_name": "Baptiste"
}
},
Expand All @@ -106,7 +105,6 @@
"pk": 3,
"fields": {
"vehicle": "3a8798e8-c193-4e75-868c-982e2f24b576",
"type": "bulb",
"status": "SOLVED",
"creation_date": "2024-05-28",
"solution_date": null,
Expand Down
24 changes: 24 additions & 0 deletions main/migrations/0015_defect_severity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.2.8 on 2026-06-23 13:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("main", "0014_remove_defect_type"),
]

operations = [
migrations.AddField(
model_name="defect",
name="severity",
field=models.CharField(
blank=True,
choices=[("MAJOR", "Majeure"), ("MINOR", "Mineure")],
max_length=255,
null=True,
verbose_name="gravité",
),
),
]
14 changes: 14 additions & 0 deletions main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def public_url(self) -> str:
def __str__(self):
return self.name

@property
def open_defects(self) -> models.QuerySet[Defect]:
return self.defect_set.filter(
models.Q(status=Defect.DefectStatus.OPEN)
| models.Q(status=Defect.DefectStatus.CONFIRMED)
)


class Defect(models.Model):
class Meta:
Expand All @@ -98,10 +105,17 @@ class DefectStatus(models.TextChoices):
SOLVED = "SOLVED", _("Résolu")
CANCELLED = "CANCELLED", _("Annulé")

class DefectSeverity(models.TextChoices):
MAJOR = "MAJOR", _("Majeure")
MINOR = "MINOR", _("Mineure")

vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE)
status = models.CharField(
_("statut"), max_length=255, choices=DefectStatus, default=DefectStatus.OPEN
)
severity = models.CharField(
_("gravité"), max_length=255, choices=DefectSeverity, null=True, blank=True
)
creation_date = models.DateField(_("date de création"), auto_now_add=True)
solution_date = models.DateField(
_("date de résolution"), null=True, blank=True, editable=False
Expand Down
26 changes: 26 additions & 0 deletions main/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,30 @@ input:not([type=submit], [type=button], [type=reset])[readonly] {
a {
margin-top: var(--spacing);
margin-bottom: var(--spacing);
}

.status-tag {
padding: 5px 20px;
border-radius: 20px;
white-space: nowrap;
font-size: 20px;
font-weight: var(--font-weight);
line-height: var(--line-height);
color: var(--contrast);
margin-left: var(--spacing);
}

.status-operational {
color: #1bc5bd;
background-color: #c9f7f5;
}

.status-in_repair {
color: #f64e60;
background-color: #ffe2e5;
}

.status-out_of_order {
color: #f64e60;
background-color: #ffe2e5;
}
22 changes: 16 additions & 6 deletions main/templates/main/vehicle_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
{% block title %}{{ block.super }} - {{ vehicle.name }}{% endblock %}
{% block body %}
<main class="container">
<h1>{{ vehicle.name }}</h1>
{% if trip_started %}<p class="warning">Un trajet est en cours, pensez à le clôturer avant d'en commencer un nouveau</p>{% endif %}
<h1>{{ vehicle.name }} <span class="status-tag status-{{ vehicle.status|lower }}">{{ vehicle.get_status_display }}</span></h1>
{% if messages %}
{% for message in messages %}
<p {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</p>
{% endfor %}
{% for message in messages %}
<p {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</p>
{% endfor %}
{% endif %}
{% if trip_started %}
<p class="warning">Un trajet est en cours, pensez à le clôturer avant d'en commencer un nouveau</p>
{% endif %}
{% for defect in open_defects %}
{% if defect.severity == "MAJOR" %}
<p class="warning"><strong>Anomalie connue :</strong>
<br/>⚠️ {{ defect.comment }}
</p>
{% endif %}
{% endfor %}
<details>
<summary role="button">Détails du véhicule</summary>
<section>
Expand Down Expand Up @@ -78,6 +87,7 @@ <h1>{{ vehicle.name }}</h1>
<tr>
<th>Commentaire</th>
<th>Statut</th>
<th>Gravité</th>
<th>Date</th>
</tr>
</thead>
Expand All @@ -86,11 +96,11 @@ <h1>{{ vehicle.name }}</h1>
<tr>
<td>{{ defect.comment }}</td>
<td>{{ defect.get_status_display }}</td>
<td>{{ defect.get_severity_display|default:"-"}}</td>
<td>{{ defect.creation_date }}</td>
</tr>
{% endfor %}
</tbody>

</table>

</details>
Expand Down
9 changes: 2 additions & 7 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import django.urls
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.translation import gettext as _
import django.shortcuts
from django.forms import BooleanField, HiddenInput, ModelForm
from django.db.models import Q
from django.utils.translation import gettext as _
from django.views.generic import CreateView, DetailView, ListView, UpdateView

from . import forms, models
Expand All @@ -31,10 +29,7 @@ def get_context_data(self, **kwargs):
self.object: models.Vehicle
context = super().get_context_data(**kwargs)

context["open_defects"] = context["vehicle"].defect_set.filter(
Q(status=models.Defect.DefectStatus.OPEN)
| Q(status=models.Defect.DefectStatus.CONFIRMED)
)
context["open_defects"] = context["vehicle"].open_defects.all()

delegated_forms: dict[str, type[ModelForm]] = {
"defect_form": forms.DefectForm,
Expand Down
Loading