From cb5837a0cfcc4448f42628abc12bac1926aee63c Mon Sep 17 00:00:00 2001
From: Gabriel Augendre
Date: Sat, 15 Jun 2019 11:18:37 +0200
Subject: [PATCH] Allow librarian to specify common supplies in the DB
---
manuels/admin.py | 8 +++++-
manuels/migrations/0034_commonsupply.py | 26 +++++++++++++++++++
manuels/migrations/0035_commonsupply_order.py | 19 ++++++++++++++
manuels/migrations/0036_auto_20190615_1114.py | 17 ++++++++++++
manuels/models.py | 13 ++++++++++
.../templates/manuels/supplies_message.html | 16 +++---------
manuels/views.py | 7 ++++-
7 files changed, 91 insertions(+), 15 deletions(-)
create mode 100644 manuels/migrations/0034_commonsupply.py
create mode 100644 manuels/migrations/0035_commonsupply_order.py
create mode 100644 manuels/migrations/0036_auto_20190615_1114.py
diff --git a/manuels/admin.py b/manuels/admin.py
index 61b6f01..d5d6f36 100644
--- a/manuels/admin.py
+++ b/manuels/admin.py
@@ -2,7 +2,7 @@ from django.contrib import admin, messages
from import_export import resources
from import_export.admin import ExportMixin
-from manuels.models import Teacher, Book, Level, Editor, SuppliesRequirement
+from manuels.models import Teacher, Book, Level, Editor, SuppliesRequirement, CommonSupply
class TeacherResource(resources.ModelResource):
@@ -75,6 +75,12 @@ class EditorAdmin(admin.ModelAdmin):
pass
+@admin.register(CommonSupply)
+class CommonSupplyAdmin(admin.ModelAdmin):
+ list_display = ['id', 'name', 'order']
+ list_display_links = ['id', 'name']
+
+
class SuppliesResource(resources.ModelResource):
class Meta:
model = SuppliesRequirement
diff --git a/manuels/migrations/0034_commonsupply.py b/manuels/migrations/0034_commonsupply.py
new file mode 100644
index 0000000..cbeb924
--- /dev/null
+++ b/manuels/migrations/0034_commonsupply.py
@@ -0,0 +1,26 @@
+# Generated by Django 2.2.1 on 2019-06-15 09:05
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('manuels', '0033_auto_20190406_1919'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='CommonSupply',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='créé le')),
+ ('updated_at', models.DateTimeField(auto_now=True, verbose_name='mis à jour le')),
+ ('name', models.CharField(max_length=200, verbose_name='nom')),
+ ],
+ options={
+ 'verbose_name': 'fourniture commune',
+ 'verbose_name_plural': 'fournitures communes',
+ },
+ ),
+ ]
diff --git a/manuels/migrations/0035_commonsupply_order.py b/manuels/migrations/0035_commonsupply_order.py
new file mode 100644
index 0000000..c2d4f0b
--- /dev/null
+++ b/manuels/migrations/0035_commonsupply_order.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2.1 on 2019-06-15 09:13
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('manuels', '0034_commonsupply'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='commonsupply',
+ name='order',
+ field=models.IntegerField(default=0, verbose_name='ordre'),
+ preserve_default=False,
+ ),
+ ]
diff --git a/manuels/migrations/0036_auto_20190615_1114.py b/manuels/migrations/0036_auto_20190615_1114.py
new file mode 100644
index 0000000..78adc3f
--- /dev/null
+++ b/manuels/migrations/0036_auto_20190615_1114.py
@@ -0,0 +1,17 @@
+# Generated by Django 2.2.1 on 2019-06-15 09:14
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('manuels', '0035_commonsupply_order'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='commonsupply',
+ options={'ordering': ('order',), 'verbose_name': 'fourniture commune', 'verbose_name_plural': 'fournitures communes'},
+ ),
+ ]
diff --git a/manuels/models.py b/manuels/models.py
index 374fe8a..802edb2 100644
--- a/manuels/models.py
+++ b/manuels/models.py
@@ -233,3 +233,16 @@ class SuppliesRequirement(BaseModel):
def __str__(self):
return f'{self.supplies} pour {self.level} ({self.teacher})'
+
+
+class CommonSupply(BaseModel):
+ class Meta:
+ verbose_name = 'fourniture commune'
+ verbose_name_plural = 'fournitures communes'
+ ordering = ('order',)
+
+ name = models.CharField('nom', max_length=200)
+ order = models.IntegerField('ordre')
+
+ def __str__(self):
+ return self.name
diff --git a/manuels/templates/manuels/supplies_message.html b/manuels/templates/manuels/supplies_message.html
index 5d53bc3..b2cc35a 100644
--- a/manuels/templates/manuels/supplies_message.html
+++ b/manuels/templates/manuels/supplies_message.html
@@ -4,18 +4,8 @@
Merci de ne pas re-saisir les fournitures communes à tous les élèves, à savoir :
- - cahier de textes ou agenda
- - trousse complète (y compris gomme, taille-crayons, blanc correcteur, bâtons de colle, règle 30 cm.,
- surligneurs
- 4 couleurs…)
-
- - 1 paire de ciseaux
- - clé(s) USB
- - 1 agrafeuse
- - crayons de couleurs (minimum 12)
- - système de reliure (baguettes sans perçage, transparents, papier épais, …) pour les éventuels dossiers
- de
- fin d’année
-
+ {% for supply in common_supplies %}
+ - {{ supply.name }}
+ {% endfor %}
\ No newline at end of file
diff --git a/manuels/views.py b/manuels/views.py
index 4e9cd9e..855f03f 100644
--- a/manuels/views.py
+++ b/manuels/views.py
@@ -11,7 +11,7 @@ from django.views.decorators.cache import cache_page
from django.views.generic import CreateView, UpdateView, DeleteView, TemplateView
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
-from manuels.models import Teacher, Book, SuppliesRequirement
+from manuels.models import Teacher, Book, SuppliesRequirement, CommonSupply
logger = logging.getLogger(__name__)
@@ -156,6 +156,11 @@ class AddSuppliesView(SuppliesView, AddItemView):
message_template = 'manuels/supplies_message.html'
template_name = 'manuels/add_supplies.html'
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['common_supplies'] = CommonSupply.objects.all()
+ return context
+
def form_valid(self, form: AddBookForm):
for level in form.cleaned_data['levels']:
supplies = SuppliesRequirement.objects.create(