Allow librarian to specify common supplies in the DB

This commit is contained in:
Gabriel Augendre 2019-06-15 11:18:37 +02:00
parent 523dff135b
commit cb5837a0cf
7 changed files with 91 additions and 15 deletions

View file

@ -2,7 +2,7 @@ from django.contrib import admin, messages
from import_export import resources from import_export import resources
from import_export.admin import ExportMixin 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): class TeacherResource(resources.ModelResource):
@ -75,6 +75,12 @@ class EditorAdmin(admin.ModelAdmin):
pass pass
@admin.register(CommonSupply)
class CommonSupplyAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'order']
list_display_links = ['id', 'name']
class SuppliesResource(resources.ModelResource): class SuppliesResource(resources.ModelResource):
class Meta: class Meta:
model = SuppliesRequirement model = SuppliesRequirement

View file

@ -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',
},
),
]

View file

@ -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,
),
]

View file

@ -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'},
),
]

View file

@ -233,3 +233,16 @@ class SuppliesRequirement(BaseModel):
def __str__(self): def __str__(self):
return f'{self.supplies} pour {self.level} ({self.teacher})' 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

View file

@ -4,18 +4,8 @@
<strong>Merci de ne pas re-saisir les fournitures communes à tous les élèves, à savoir :</strong> <strong>Merci de ne pas re-saisir les 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> {% for supply in common_supplies %}
<li>trousse complète (y compris gomme, taille-crayons, blanc correcteur, bâtons de colle, règle 30 cm., <li>{{ supply.name }}</li>
surligneurs {% endfor %}
4 couleurs&#8230;)
</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, &#8230;) pour les éventuels dossiers
de
fin dannée
</li>
</ul> </ul>
</div> </div>

View file

@ -11,7 +11,7 @@ from django.views.decorators.cache import cache_page
from django.views.generic import CreateView, UpdateView, DeleteView, TemplateView from django.views.generic import CreateView, UpdateView, DeleteView, TemplateView
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, CommonSupply
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -156,6 +156,11 @@ class AddSuppliesView(SuppliesView, AddItemView):
message_template = 'manuels/supplies_message.html' message_template = 'manuels/supplies_message.html'
template_name = 'manuels/add_supplies.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): def form_valid(self, form: AddBookForm):
for level in form.cleaned_data['levels']: for level in form.cleaned_data['levels']:
supplies = SuppliesRequirement.objects.create( supplies = SuppliesRequirement.objects.create(