Skip to content

Commit 1a57ed7

Browse files
committed
feat(profiles): add sport-doctorso templates, views and form
1 parent f31e8cc commit 1a57ed7

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

profiles/forms/sport_doctors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django import forms
2+
from profiles.models.sport_doctors import SportDoctor
3+
4+
5+
class SportDoctorForm(forms.ModelForm):
6+
class Meta:
7+
model = SportDoctor
8+
fields = "__all__"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>Conferma Eliminazione</h1>
5+
<p>Sei sicuro di voler eliminare il medico "{{ sport_doctor }}"?</p>
6+
7+
<form method="post">
8+
{% csrf_token %}
9+
<button type="submit">Elimina</button>
10+
<a href="{% url 'sport_doctor_list' %}">Annulla</a>
11+
</form>
12+
13+
<a href="{% url 'sport_doctor_list' %}">Torna alla lista</a>
14+
{% endblock %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>Dettaglio Medico Sportivo</h1>
5+
<p><strong>Nome:</strong> {{ sport_doctor.first_name }}</p>
6+
<p><strong>Cognome:</strong> {{ sport_doctor.last_name }}</p>
7+
<p><strong>Partita IVA:</strong> {{ sport_doctor.vat_number }}</p>
8+
9+
<a href="{% url 'sport_doctor_list' %}">Torna alla lista</a>
10+
{% endblock %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>{% if form.instance.pk %}Modifica Medico Sportivo{% else %}Aggiungi Medico Sportivo{% endif %}</h1>
5+
<form method="post">
6+
{% csrf_token %}
7+
{{ form.as_p }}
8+
<button type="submit">Salva</button>
9+
</form>
10+
{% endblock %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>Lista Medici Sportivi</h1>
5+
<a href="{% url 'sport_doctor_create' %}">Aggiungi un nuovo medico sportivo</a>
6+
<ul>
7+
{% for sport_doctor in sport_doctor_list %}
8+
<li>
9+
<a href="{% url 'sport_doctor_detail' sport_doctor.pk %}">
10+
{{ sport_doctor.first_name }} {{ sport_doctor.last_name }} ({{ sport_doctor.vat_number }})
11+
</a>
12+
(<a href="{% url 'sport_doctor_update' sport_doctor.pk %}">Modifica</a> |
13+
<a href="{% url 'sport_doctor_delete' sport_doctor.pk %}">Elimina</a>)
14+
</li>
15+
{% endfor %}
16+
</ul>
17+
{% endblock %}

profiles/views/sport_doctors.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from django.urls import reverse_lazy
2+
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
3+
from profiles.models.sport_doctors import SportDoctor
4+
from profiles.forms.sport_doctors import SportDoctorForm
5+
6+
7+
class SportDoctorListView(ListView):
8+
"""View for listing all sport doctors."""
9+
model = SportDoctor
10+
template_name = "profiles/sport_doctor_list.html"
11+
context_object_name = "sport_doctor_list"
12+
13+
14+
class SportDoctorDetailView(DetailView):
15+
"""View for displaying a single sport doctor."""
16+
model = SportDoctor
17+
template_name = "profiles/sport_doctor_detail.html"
18+
context_object_name = "sport_doctor_detail"
19+
20+
21+
class SportDoctorCreateView(CreateView):
22+
"""View for creating a new sport doctor."""
23+
model = SportDoctor
24+
form_class = SportDoctorForm
25+
template_name = "profiles/sport_doctor_form.html"
26+
success_url = reverse_lazy("sport_doctor_list")
27+
28+
29+
class SportDoctorUpdateView(UpdateView):
30+
"""View for updating a sport doctor."""
31+
model = SportDoctor
32+
form_class = SportDoctorForm
33+
template_name = "profiles/sport_doctor_form.html"
34+
35+
def get_success_url(self):
36+
return reverse_lazy("sport_doctor_detail", kwargs={"pk": self.object.pk})
37+
38+
39+
class SportDoctorDeleteView(DeleteView):
40+
"""View for deleting a sport doctor."""
41+
model = SportDoctor
42+
template_name = "profiles/sport_doctor_confirm_delete.html"
43+
success_url = reverse_lazy("sport_doctor_list")

0 commit comments

Comments
 (0)