From fd8af82a71e1b31fbd3720a4fc53ad67c7749011 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 6 Apr 2019 19:25:04 +0200 Subject: [PATCH] Add consumable notion for books --- manuels/admin.py | 6 ++-- manuels/forms.py | 5 ++-- manuels/migrations/0028_auto_20190406_1901.py | 28 +++++++++++++++++++ manuels/migrations/0029_auto_20190406_1904.py | 18 ++++++++++++ manuels/models.py | 14 ++++++++++ manuels/templates/manuels/add_book.html | 5 +++- .../manuels/list_books_supplies.html | 9 ++++-- 7 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 manuels/migrations/0028_auto_20190406_1901.py create mode 100644 manuels/migrations/0029_auto_20190406_1904.py diff --git a/manuels/admin.py b/manuels/admin.py index df61695..88124c5 100644 --- a/manuels/admin.py +++ b/manuels/admin.py @@ -34,9 +34,11 @@ class BookResource(resources.ModelResource): class Meta: model = Book fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor', - 'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field') + 'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field', + 'consumable') export_order = ('level__name', 'field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price', - 'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments') + 'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments', + 'consumable') @admin.register(Book) diff --git a/manuels/forms.py b/manuels/forms.py index 16549ce..f2e417e 100644 --- a/manuels/forms.py +++ b/manuels/forms.py @@ -8,7 +8,7 @@ class EditBookForm(forms.ModelForm): class Meta: model = Book fields = ['teacher', 'level', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'other_editor', - 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments'] + 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'consumable'] no_book = forms.BooleanField(label='Pas de livre pour cette classe/matière', required=False, initial=False) see_later = forms.BooleanField( @@ -24,6 +24,7 @@ class EditBookForm(forms.ModelForm): self.fields['teacher'].widget.attrs.update({'class': 'custom-select'}) self.fields['editor'].widget.attrs.update({'class': 'custom-select'}) self.fields['previously_acquired'].widget.attrs.update({'class': 'custom-select'}) + self.fields['consumable'].widget.attrs.update({'class': 'custom-select'}) if 'level' in self.fields: self.fields['level'].widget.attrs.update({'class': 'custom-select'}) @@ -55,7 +56,7 @@ class EditBookForm(forms.ModelForm): class AddBookForm(EditBookForm): class Meta(EditBookForm.Meta): fields = ['teacher', 'levels', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'other_editor', - 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'add_another'] + 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'add_another', 'consumable'] add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True) levels = forms.ModelMultipleChoiceField( diff --git a/manuels/migrations/0028_auto_20190406_1901.py b/manuels/migrations/0028_auto_20190406_1901.py new file mode 100644 index 0000000..809c119 --- /dev/null +++ b/manuels/migrations/0028_auto_20190406_1901.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2 on 2019-04-06 17:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0027_auto_20190401_2036'), + ] + + operations = [ + migrations.AlterModelOptions( + name='level', + options={'ordering': ['order', 'name'], 'verbose_name': 'classe', 'verbose_name_plural': 'classes'}, + ), + migrations.AddField( + model_name='book', + name='consumable', + field=models.BooleanField(default=False, help_text="Exemple : un cahier d'exercices est un consommable", verbose_name='consommable'), + preserve_default=False, + ), + migrations.AddField( + model_name='level', + name='order', + field=models.IntegerField(default=0, verbose_name='ordre'), + ), + ] diff --git a/manuels/migrations/0029_auto_20190406_1904.py b/manuels/migrations/0029_auto_20190406_1904.py new file mode 100644 index 0000000..a1ce6d9 --- /dev/null +++ b/manuels/migrations/0029_auto_20190406_1904.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-06 17:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0028_auto_20190406_1901'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='consumable', + field=models.BooleanField(choices=[(None, '------------'), (False, 'Non'), (True, 'Oui')], default=None, help_text="Exemple : un cahier d'exercices est un consommable", verbose_name='consommable'), + ), + ] diff --git a/manuels/models.py b/manuels/models.py index 6210ccd..26f14ff 100644 --- a/manuels/models.py +++ b/manuels/models.py @@ -184,6 +184,13 @@ class Book(BaseModel): blank=True, help_text="Ce message sera visible par la documentaliste." ) + consumable = models.BooleanField( + 'consommable', + help_text="Exemple : un cahier d'exercices est un consommable", + choices=YES_NO_CHOICE, + blank=False, + default=None, + ) @property def previously_acquired_text(self): @@ -192,6 +199,13 @@ class Book(BaseModel): else: return 'Non' + @property + def consumable_text(self): + if self.previously_acquired: + return 'Oui' + else: + return 'Non' + def __str__(self): return f'{self.title} ({self.authors}) - {self.isbn}' diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html index 75e5c43..faca794 100644 --- a/manuels/templates/manuels/add_book.html +++ b/manuels/templates/manuels/add_book.html @@ -77,9 +77,12 @@
-
+
{% bootstrap_field form.previously_acquired %}
+
+ {% bootstrap_field form.consumable %} +
diff --git a/manuels/templates/manuels/list_books_supplies.html b/manuels/templates/manuels/list_books_supplies.html index 9652542..77a6f91 100644 --- a/manuels/templates/manuels/list_books_supplies.html +++ b/manuels/templates/manuels/list_books_supplies.html @@ -54,6 +54,7 @@ ISBN Prix Déjà acheté par l'élève + Consommable @@ -85,6 +86,10 @@ {{ book.previously_acquired_text }} + + + {{ book.consumable_text }} + {% endfor %} @@ -110,7 +115,7 @@ Modifier {% endif %} Classe - Disciplines + Discipline Liste de fournitures @@ -130,7 +135,7 @@ {% endif %} {{ supply.level }} - {{ supply.fields }} + {{ supply.field }} {{ supply.supplies|linebreaksbr }} {% endfor %}