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>
|
||||
</h2>
|
||||
{% if message_template %}
|
||||
<div class="alert alert-info">
|
||||
{% include message_template %}
|
||||
</div>
|
||||
{% include message_template %}
|
||||
{% endif %}
|
||||
<form action="" method="post" class="form">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% if form %}
|
||||
{% bootstrap_form form %}
|
||||
{% endif %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-primary">Valider</button>
|
||||
<button type="submit" class="btn btn-{{ button_class }}">{{ verb }}</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
</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 %}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<a title="Modifier"
|
||||
href="{% url 'edit_book' teacher_pk=book.teacher.pk pk=book.pk %}"><i
|
||||
class="fas fa-edit"></i></a>
|
||||
<div class="btn-group">
|
||||
<a title="Modifier"
|
||||
href="{% url 'edit_book' teacher_pk=book.teacher.pk pk=book.pk %}"
|
||||
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>
|
||||
<td>{{ book.level }}</td>
|
||||
<td>{{ book.field }}</td>
|
||||
|
@ -92,9 +97,14 @@
|
|||
{% for supply in supplies %}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<a title="Modifier"
|
||||
href="{% url 'edit_supplies' teacher_pk=supply.teacher.pk pk=supply.pk %}"><i
|
||||
class="fas fa-edit"></i></a>
|
||||
<div class="btn-group">
|
||||
<a title="Modifier"
|
||||
href="{% url 'edit_supplies' teacher_pk=supply.teacher.pk pk=supply.pk %}"
|
||||
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>
|
||||
<td>{{ supply.level }}</td>
|
||||
<td>{{ supply.fields }}</td>
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
<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>
|
||||
</p>
|
||||
<ul class="mb-0">
|
||||
<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
|
||||
4 couleurs…)
|
||||
</li>
|
||||
<li>1 paire de ciseaux</li>
|
||||
<li>clé(s) USB</li>
|
||||
<li>1 agrafeuse</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
|
||||
fin d’année
|
||||
</li>
|
||||
</ul>
|
||||
<div class="alert alert-info">
|
||||
<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>
|
||||
</p>
|
||||
<ul class="mb-0">
|
||||
<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
|
||||
4 couleurs…)
|
||||
</li>
|
||||
<li>1 paire de ciseaux</li>
|
||||
<li>clé(s) USB</li>
|
||||
<li>1 agrafeuse</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
|
||||
fin d’année
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
|
@ -1,13 +1,15 @@
|
|||
from django.urls import path
|
||||
|
||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView, EditBookView,\
|
||||
EditSuppliesView
|
||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView, EditBookView, \
|
||||
EditSuppliesView, DeleteBookView, DeleteSuppliesView
|
||||
|
||||
urlpatterns = [
|
||||
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>', 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>/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>/delete', DeleteSuppliesView.as_view(), name='delete_supplies'),
|
||||
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.shortcuts import get_object_or_404, redirect
|
||||
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.models import Teacher, Book, SuppliesRequirement
|
||||
|
@ -68,6 +68,7 @@ class ItemView(BaseTeacherView):
|
|||
message_template = None
|
||||
template_name = 'manuels/add_item.html'
|
||||
verb = None
|
||||
button_class = 'primary'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
@ -75,6 +76,7 @@ class ItemView(BaseTeacherView):
|
|||
context['item_plural'] = self.item_text_plural
|
||||
context['message_template'] = self.message_template
|
||||
context['verb'] = self.verb
|
||||
context['button_class'] = self.button_class
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
|
@ -119,11 +121,11 @@ class SuppliesView:
|
|||
success_target = 'add_supplies'
|
||||
item_text = 'des fournitures'
|
||||
item_text_plural = 'fournitures'
|
||||
message_template = 'manuels/supplies_message.html'
|
||||
|
||||
|
||||
class AddSuppliesView(SuppliesView, AddItemView):
|
||||
form_class = AddSuppliesForm
|
||||
message_template = 'manuels/supplies_message.html'
|
||||
|
||||
|
||||
class EditItemView(ItemView, UpdateView):
|
||||
|
@ -150,6 +152,30 @@ class EditSuppliesView(SuppliesView, EditItemView):
|
|||
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):
|
||||
if request.session['teacher_pk']:
|
||||
del request.session['teacher_pk']
|
||||
|
|
Loading…
Reference in a new issue