Skip to content

Commit 946f83b

Browse files
committedDec 21, 2024·
chore(profiles): fix url reverse and rename templates and views according to django best-practice
1 parent 1a57ed7 commit 946f83b

File tree

10 files changed

+34
-22
lines changed

10 files changed

+34
-22
lines changed
 

‎config/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# Templates
2929
path('products/', include('products.urls')),
3030
path('profiles/', include('profiles.urls')),
31+
path('documentation/', include('documentation.urls')),
3132
# APIs
3233
path('api/', include('products.api.urls'))
3334
]

‎profiles/templates/profiles/athlete_confirm_delete.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ <h1>Conferma Eliminazione</h1>
77
<form method="post">
88
{% csrf_token %}
99
<button type="submit">Elimina</button>
10-
<a href="{% url 'athletes_list' %}">Annulla</a>
10+
<a href="{% url 'athlete_list' %}">Annulla</a>
1111
</form>
1212

13-
<a href="{% url 'athletes_list' %}">Torna alla lista</a>
13+
<a href="{% url 'athlete_list' %}">Torna alla lista</a>
1414
{% endblock %}

‎profiles/templates/profiles/athletes_list.html ‎profiles/templates/profiles/athlete_list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1>Lista Atleti</h1>
55
<a href="{% url 'athlete_create' %}">Aggiungi un nuovo atleta</a>
66
<ul>
7-
{% for athlete in athletes_list %}
7+
{% for athlete in athlete_list %}
88
<li>
99
<a href="{% url 'athlete_detail' athlete.pk %}">
1010
{{ athlete.first_name }} {{ athlete.last_name }}

‎profiles/templates/profiles/trainer_confirm_delete.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ <h1>Conferma Eliminazione</h1>
77
<form method="post">
88
{% csrf_token %}
99
<button type="submit">Elimina</button>
10-
<a href="{% url 'trainers_list' %}">Annulla</a>
10+
<a href="{% url 'trainer_list' %}">Annulla</a>
1111
</form>
1212

13-
<a href="{% url 'trainers_list' %}">Torna alla lista</a>
13+
<a href="{% url 'trainer_list' %}">Torna alla lista</a>
1414
{% endblock %}

‎profiles/templates/profiles/trainers_list.html ‎profiles/templates/profiles/trainer_list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1>Lista Tecnici</h1>
55
<a href="{% url 'trainer_create' %}">Aggiungi un nuovo tecnico</a>
66
<ul>
7-
{% for trainer in trainers_list %}
7+
{% for trainer in trainer_list %}
88
<li>
99
<a href="{% url 'trainer_detail' trainer.pk %}">
1010
{{ trainer.first_name }} {{ trainer.last_name }}

‎profiles/urls.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@
66
TrainerListView, TrainerDetailView, TrainerCreateView, TrainerUpdateView, TrainerDeleteView
77
)
88

9+
from profiles.views.sport_doctors import (
10+
SportDoctorListView, SportDoctorDetailView, SportDoctorCreateView, SportDoctorUpdateView, SportDoctorDeleteView
11+
)
12+
913
urlpatterns = [
1014
# Athletes
11-
path("athletes/", AthleteListView.as_view(), name="athletes_list"),
15+
path("athletes/", AthleteListView.as_view(), name="athlete_list"),
1216
path("athletes/<int:pk>/", AthleteDetailView.as_view(), name="athlete_detail"),
1317
path("athletes/new/", AthleteCreateView.as_view(), name="athlete_create"),
1418
path("athletes/<int:pk>/edit/", AthleteUpdateView.as_view(), name="athlete_update"),
1519
path("athletes/<int:pk>/delete/", AthleteDeleteView.as_view(), name="athlete_delete"),
1620

1721
# Trainers
18-
path("trainers/", TrainerListView.as_view(), name="trainers_list"),
22+
path("trainers/", TrainerListView.as_view(), name="trainer_list"),
1923
path("trainers/<int:pk>/", TrainerDetailView.as_view(), name="trainer_detail"),
2024
path("trainers/new/", TrainerCreateView.as_view(), name="trainer_create"),
2125
path("trainers/<int:pk>/edit/", TrainerUpdateView.as_view(), name="trainer_update"),
2226
path("trainers/<int:pk>/delete/", TrainerDeleteView.as_view(), name="trainer_delete"),
27+
28+
# Sport Doctors
29+
path("sport_doctors/", SportDoctorListView.as_view(), name="sport_doctor_list"),
30+
path("sport_doctors/<int:pk>/", SportDoctorDetailView.as_view(), name="sport_doctor_detail"),
31+
path("sport_doctors/new/", SportDoctorCreateView.as_view(), name="sport_doctor_create"),
32+
path("sport_doctors/<int:pk>/edit/", SportDoctorUpdateView.as_view(), name="sport_doctor_update"),
33+
path("sport_doctors/<int:pk>/delete/", SportDoctorDeleteView.as_view(), name="sport_doctor_delete"),
2334
]

‎profiles/views/athletes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class AthleteListView(ListView):
88
"""View for listing all athletes."""
99
model = Athlete
10-
template_name = "profiles/athletes_list.html"
11-
context_object_name = "athletes_list"
10+
template_name = "profiles/athlete_list.html"
11+
context_object_name = "athlete_list"
1212

1313

1414
class AthleteDetailView(DetailView):
@@ -23,7 +23,7 @@ class AthleteCreateView(CreateView):
2323
model = Athlete
2424
form_class = AthleteForm
2525
template_name = "profiles/athlete_form.html"
26-
success_url = reverse_lazy("athletes_list")
26+
success_url = reverse_lazy("athlete_list")
2727

2828

2929
class AthleteUpdateView(UpdateView):
@@ -40,5 +40,5 @@ class AthleteDeleteView(DeleteView):
4040
"""View for deleting an athlete."""
4141
model = Athlete
4242
template_name = "profiles/athlete_confirm_delete.html"
43-
success_url = reverse_lazy("athletes_list")
43+
success_url = reverse_lazy("athlete_list")
4444

‎profiles/views/doctors.py

Whitespace-only changes.

‎profiles/views/trainers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class TrainerListView(ListView):
88
"""View for listing all trainers."""
99
model = Trainer
10-
template_name = "profiles/trainers_list.html"
11-
context_object_name = "trainers_list"
10+
template_name = "profiles/trainer_list.html"
11+
context_object_name = "trainer_list"
1212

1313

1414
class TrainerDetailView(DetailView):
@@ -23,7 +23,7 @@ class TrainerCreateView(CreateView):
2323
model = Trainer
2424
form_class = TrainerForm
2525
template_name = "profiles/trainer_form.html"
26-
success_url = reverse_lazy("trainers_list")
26+
success_url = reverse_lazy("trainer_list")
2727

2828

2929
class TrainerUpdateView(UpdateView):
@@ -40,4 +40,4 @@ class TrainerDeleteView(DeleteView):
4040
"""View for deleting an athlete."""
4141
model = Trainer
4242
template_name = "profiles/trainer_confirm_delete.html"
43-
success_url = reverse_lazy("trainers_list")
43+
success_url = reverse_lazy("trainer_list")

‎templates/includes/navbar.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
> Gestione Atleti
2626
</a>
2727
<ul class="dropdown-menu" aria-labelledby="athletes-handler">
28-
<li><a class="dropdown-item" href="{% url 'athletes_list' %}">Elenco Atleti</a></li>
28+
<li><a class="dropdown-item" href="{% url 'athlete_list' %}">Elenco Atleti</a></li>
2929
<li><a class="dropdown-item" href="{% url 'athlete_create' %}">Inserisci Nuovo Atleta</a></li>
3030
</ul>
3131
</li>
@@ -39,7 +39,7 @@
3939
> Gestione Tecnici
4040
</a>
4141
<ul class="dropdown-menu" aria-labelledby="trainers-handler">
42-
<li><a class="dropdown-item" href="{% url 'trainers_list' %}">Elenco Tecnici</a></li>
42+
<li><a class="dropdown-item" href="{% url 'trainer_list' %}">Elenco Tecnici</a></li>
4343
<li><a class="dropdown-item" href="{% url 'trainer_create' %}">Inserisci Nuovo Tecnico</a></li>
4444
</ul>
4545
</li>
@@ -53,8 +53,8 @@
5353
> Gestione Medici
5454
</a>
5555
<ul class="dropdown-menu" aria-labelledby="doctors-handler">
56-
<li><a class="dropdown-item" href="#">Elenco Medici</a></li>
57-
<li><a class="dropdown-item" href="#">Inserisci Nuovo Medico</a></li>
56+
<li><a class="dropdown-item" href="{% url 'sport_doctor_list' %}">Elenco Medici</a></li>
57+
<li><a class="dropdown-item" href="{% url 'sport_doctor_create' %}">Inserisci Nuovo Medico</a></li>
5858
</ul>
5959
</li>
6060

@@ -67,8 +67,8 @@
6767
> Documentazione
6868
</a>
6969
<ul class="dropdown-menu" aria-labelledby="documentation-handler">
70-
<li><a class="dropdown-item" href="#">Elenco Certificati Medici</a></li>
71-
<li><a class="dropdown-item" href="#">Inserisci Nuovo Certificato Medico</a></li>
70+
<li><a class="dropdown-item" href="{% url 'sport_certificate_list' %}">Elenco Certificati Medici</a></li>
71+
<li><a class="dropdown-item" href="{% url 'sport_certificate_create' %}">Inserisci Nuovo Certificato Medico</a></li>
7272
</ul>
7373
</li>
7474

0 commit comments

Comments
 (0)
Please sign in to comment.