Allow item deletion. Close #18
This commit is contained in:
parent
975775b05f
commit
b7d50b16ea
6 changed files with 84 additions and 32 deletions
|
@ -12,15 +12,15 @@
|
||||||
<a href="{% url 'list_books' teacher.pk %}" class="btn btn-secondary">Retour à la liste des {{ item_plural }}</a>
|
<a href="{% url 'list_books' teacher.pk %}" class="btn btn-secondary">Retour à la liste des {{ item_plural }}</a>
|
||||||
</h2>
|
</h2>
|
||||||
{% if message_template %}
|
{% if message_template %}
|
||||||
<div class="alert alert-info">
|
|
||||||
{% include message_template %}
|
{% include message_template %}
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form action="" method="post" class="form">
|
<form action="" method="post" class="form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{% if form %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
|
{% endif %}
|
||||||
{% buttons %}
|
{% buttons %}
|
||||||
<button type="submit" class="btn btn-primary">Valider</button>
|
<button type="submit" class="btn btn-{{ button_class }}">{{ verb }}</button>
|
||||||
{% endbuttons %}
|
{% endbuttons %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
10
manuels/templates/manuels/confirm_delete.html
Normal file
10
manuels/templates/manuels/confirm_delete.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Danger</h4>
|
||||||
|
<p class="mb-0">
|
||||||
|
<strong>Êtes-vous certain·e de vouloir supprimer cet élément ?
|
||||||
|
Cette action est définitive : vous ne pourrez plus le récupérer ensuite.</strong>
|
||||||
|
</p>
|
||||||
|
<p class="mb-0">
|
||||||
|
{{ object }}
|
||||||
|
</p>
|
||||||
|
</div>
|
|
@ -48,9 +48,14 @@
|
||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
|
<div class="btn-group">
|
||||||
<a title="Modifier"
|
<a title="Modifier"
|
||||||
href="{% url 'edit_book' teacher_pk=book.teacher.pk pk=book.pk %}"><i
|
href="{% url 'edit_book' teacher_pk=book.teacher.pk pk=book.pk %}"
|
||||||
class="fas fa-edit"></i></a>
|
class="btn btn-sm btn-secondary"><i class="fas fa-edit"></i></a>
|
||||||
|
<a title="Supprimer"
|
||||||
|
href="{% url 'delete_book' teacher_pk=book.teacher.pk pk=book.pk %}"
|
||||||
|
class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></a>
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<td>{{ book.level }}</td>
|
<td>{{ book.level }}</td>
|
||||||
<td>{{ book.field }}</td>
|
<td>{{ book.field }}</td>
|
||||||
|
@ -92,9 +97,14 @@
|
||||||
{% for supply in supplies %}
|
{% for supply in supplies %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
|
<div class="btn-group">
|
||||||
<a title="Modifier"
|
<a title="Modifier"
|
||||||
href="{% url 'edit_supplies' teacher_pk=supply.teacher.pk pk=supply.pk %}"><i
|
href="{% url 'edit_supplies' teacher_pk=supply.teacher.pk pk=supply.pk %}"
|
||||||
class="fas fa-edit"></i></a>
|
class="btn btn-sm btn-secondary"><i class="fas fa-edit"></i></a>
|
||||||
|
<a title="Supprimer"
|
||||||
|
href="{% url 'delete_supplies' teacher_pk=supply.teacher.pk pk=supply.pk %}"
|
||||||
|
class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></a>
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<td>{{ supply.level }}</td>
|
<td>{{ supply.level }}</td>
|
||||||
<td>{{ supply.fields }}</td>
|
<td>{{ supply.fields }}</td>
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Information</h4>
|
<div class="alert alert-info">
|
||||||
<p class="mb-0">
|
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Information</h4>
|
||||||
|
<p class="mb-0">
|
||||||
<strong>En complément des fournitures communes à tous les élèves, à savoir :</strong>
|
<strong>En complément des fournitures communes à tous les élèves, à savoir :</strong>
|
||||||
</p>
|
</p>
|
||||||
<ul class="mb-0">
|
<ul class="mb-0">
|
||||||
<li>cahier de textes ou agenda</li>
|
<li>cahier de textes ou agenda</li>
|
||||||
<li>trousse complète (y compris gomme, taille-crayons, blanc correcteur, bâtons de colle, règle 30 cm., surligneurs
|
<li>trousse complète (y compris gomme, taille-crayons, blanc correcteur, bâtons de colle, règle 30 cm.,
|
||||||
|
surligneurs
|
||||||
4 couleurs…)
|
4 couleurs…)
|
||||||
</li>
|
</li>
|
||||||
<li>1 paire de ciseaux</li>
|
<li>1 paire de ciseaux</li>
|
||||||
<li>clé(s) USB</li>
|
<li>clé(s) USB</li>
|
||||||
<li>1 agrafeuse</li>
|
<li>1 agrafeuse</li>
|
||||||
<li>crayons de couleurs (minimum 12)</li>
|
<li>crayons de couleurs (minimum 12)</li>
|
||||||
<li>système de reliure (baguettes sans perçage, transparents, papier épais, …) pour les éventuels dossiers de
|
<li>système de reliure (baguettes sans perçage, transparents, papier épais, …) pour les éventuels dossiers
|
||||||
|
de
|
||||||
fin d’année
|
fin d’année
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
|
@ -1,13 +1,15 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView, EditBookView,\
|
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView, EditBookView, \
|
||||||
EditSuppliesView
|
EditSuppliesView, DeleteBookView, DeleteSuppliesView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('teacher/<uuid:pk>/add_book', AddBookView.as_view(), name='add_book'),
|
path('teacher/<uuid:pk>/add_book', AddBookView.as_view(), name='add_book'),
|
||||||
path('teacher/<uuid:pk>/add_supplies', AddSuppliesView.as_view(), name='add_supplies'),
|
path('teacher/<uuid:pk>/add_supplies', AddSuppliesView.as_view(), name='add_supplies'),
|
||||||
path('teacher/<uuid:pk>', ListBooksView.as_view(), name='list_books'),
|
path('teacher/<uuid:pk>', ListBooksView.as_view(), name='list_books'),
|
||||||
path('teacher/<uuid:teacher_pk>/book/<int:pk>', EditBookView.as_view(), name='edit_book'),
|
path('teacher/<uuid:teacher_pk>/book/<int:pk>', EditBookView.as_view(), name='edit_book'),
|
||||||
|
path('teacher/<uuid:teacher_pk>/book/<int:pk>/delete', DeleteBookView.as_view(), name='delete_book'),
|
||||||
path('teacher/<uuid:teacher_pk>/supplies/<int:pk>', EditSuppliesView.as_view(), name='edit_supplies'),
|
path('teacher/<uuid:teacher_pk>/supplies/<int:pk>', EditSuppliesView.as_view(), name='edit_supplies'),
|
||||||
|
path('teacher/<uuid:teacher_pk>/supplies/<int:pk>/delete', DeleteSuppliesView.as_view(), name='delete_supplies'),
|
||||||
path('clear', clear_teacher_view, name='clear_teacher'),
|
path('clear', clear_teacher_view, name='clear_teacher'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views.generic import CreateView, ListView, UpdateView
|
from django.views.generic import CreateView, ListView, UpdateView, DeleteView
|
||||||
|
|
||||||
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
|
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
|
||||||
from manuels.models import Teacher, Book, SuppliesRequirement
|
from manuels.models import Teacher, Book, SuppliesRequirement
|
||||||
|
@ -68,6 +68,7 @@ class ItemView(BaseTeacherView):
|
||||||
message_template = None
|
message_template = None
|
||||||
template_name = 'manuels/add_item.html'
|
template_name = 'manuels/add_item.html'
|
||||||
verb = None
|
verb = None
|
||||||
|
button_class = 'primary'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
@ -75,6 +76,7 @@ class ItemView(BaseTeacherView):
|
||||||
context['item_plural'] = self.item_text_plural
|
context['item_plural'] = self.item_text_plural
|
||||||
context['message_template'] = self.message_template
|
context['message_template'] = self.message_template
|
||||||
context['verb'] = self.verb
|
context['verb'] = self.verb
|
||||||
|
context['button_class'] = self.button_class
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
@ -119,11 +121,11 @@ class SuppliesView:
|
||||||
success_target = 'add_supplies'
|
success_target = 'add_supplies'
|
||||||
item_text = 'des fournitures'
|
item_text = 'des fournitures'
|
||||||
item_text_plural = 'fournitures'
|
item_text_plural = 'fournitures'
|
||||||
message_template = 'manuels/supplies_message.html'
|
|
||||||
|
|
||||||
|
|
||||||
class AddSuppliesView(SuppliesView, AddItemView):
|
class AddSuppliesView(SuppliesView, AddItemView):
|
||||||
form_class = AddSuppliesForm
|
form_class = AddSuppliesForm
|
||||||
|
message_template = 'manuels/supplies_message.html'
|
||||||
|
|
||||||
|
|
||||||
class EditItemView(ItemView, UpdateView):
|
class EditItemView(ItemView, UpdateView):
|
||||||
|
@ -150,6 +152,30 @@ class EditSuppliesView(SuppliesView, EditItemView):
|
||||||
form_class = EditSuppliesForm
|
form_class = EditSuppliesForm
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteItemView(ItemView, DeleteView):
|
||||||
|
teacher_field = 'teacher_pk'
|
||||||
|
item_text = None
|
||||||
|
item_text_plural = None
|
||||||
|
message_template = 'manuels/confirm_delete.html'
|
||||||
|
verb = 'Supprimer'
|
||||||
|
button_class = 'danger'
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return self.model.objects.filter(teacher=self.teacher)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
messages.success(self.request, f'"{self.object}" a été supprimé.')
|
||||||
|
return reverse('list_books', args=[str(self.teacher.pk)])
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteBookView(BookView, DeleteItemView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteSuppliesView(SuppliesView, DeleteItemView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def clear_teacher_view(request):
|
def clear_teacher_view(request):
|
||||||
if request.session['teacher_pk']:
|
if request.session['teacher_pk']:
|
||||||
del request.session['teacher_pk']
|
del request.session['teacher_pk']
|
||||||
|
|
Loading…
Reference in a new issue