Add supplies management + fix "previously acquired"
This commit is contained in:
parent
53285953ad
commit
7709be0701
10 changed files with 153 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from manuels.models import Teacher, Book, Level, Editor
|
||||
from manuels.models import Teacher, Book, Level, Editor, SuppliesRequirement
|
||||
|
||||
|
||||
@admin.register(Teacher)
|
||||
|
@ -35,3 +35,9 @@ class BookAdmin(admin.ModelAdmin):
|
|||
@admin.register(Editor)
|
||||
class EditorAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(SuppliesRequirement)
|
||||
class SuppliesRequirementAdmin(admin.ModelAdmin):
|
||||
list_display = ['teacher', 'level', 'supplies']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django import forms
|
||||
|
||||
from manuels.models import Book, Teacher
|
||||
from manuels.models import Book, SuppliesRequirement
|
||||
|
||||
|
||||
class AddBookForm(forms.ModelForm):
|
||||
|
@ -8,4 +8,12 @@ class AddBookForm(forms.ModelForm):
|
|||
model = Book
|
||||
fields = '__all__'
|
||||
|
||||
add_another = forms.BooleanField(label='Ajouter un autre livre', required=False)
|
||||
add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True)
|
||||
|
||||
|
||||
class AddSuppliesForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = SuppliesRequirement
|
||||
fields = '__all__'
|
||||
|
||||
add_another = forms.BooleanField(label="Ajouter d'autres fournitures", required=False, initial=True)
|
||||
|
|
29
manuels/migrations/0005_suppliesrequirement.py
Normal file
29
manuels/migrations/0005_suppliesrequirement.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 2.0.5 on 2018-05-22 07:34
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0004_auto_20180522_0148'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SuppliesRequirement',
|
||||
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')),
|
||||
('supplies', models.TextField(verbose_name='fournitures')),
|
||||
('level', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Level', verbose_name='classe')),
|
||||
('teacher', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Teacher', verbose_name='enseignant')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'demande de fournitures',
|
||||
'verbose_name_plural': 'demandes de fournitures',
|
||||
},
|
||||
),
|
||||
]
|
18
manuels/migrations/0006_auto_20180522_1009.py
Normal file
18
manuels/migrations/0006_auto_20180522_1009.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.5 on 2018-05-22 08:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0005_suppliesrequirement'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='previously_acquired',
|
||||
field=models.BooleanField(choices=[(True, 'Oui'), (False, 'Non')], default=False, verbose_name="manuel acquis précédemment par l'élève"),
|
||||
),
|
||||
]
|
|
@ -80,10 +80,15 @@ class Book(BaseModel):
|
|||
isbn = models.CharField('ISBN/EAN', max_length=20, validators=[isbn_validator])
|
||||
price = models.PositiveIntegerField('prix')
|
||||
YES_NO_CHOICE = (
|
||||
(True, 'Oui'),
|
||||
(False, 'Non'),
|
||||
(True, 'Oui'),
|
||||
)
|
||||
previously_acquired = models.BooleanField(
|
||||
"manuel acquis précédemment par l'élève",
|
||||
choices=YES_NO_CHOICE,
|
||||
blank=False,
|
||||
default=False,
|
||||
)
|
||||
previously_acquired = models.BooleanField("manuel acquis précédemment par l'élève", choices=YES_NO_CHOICE, blank=False)
|
||||
|
||||
@property
|
||||
def previously_acquired_emoji(self):
|
||||
|
@ -94,3 +99,16 @@ class Book(BaseModel):
|
|||
|
||||
def __str__(self):
|
||||
return f'{self.title} ({self.authors}) - {self.isbn}'
|
||||
|
||||
|
||||
class SuppliesRequirement(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'demande de fournitures'
|
||||
verbose_name_plural = 'demandes de fournitures'
|
||||
|
||||
teacher = models.ForeignKey(verbose_name='enseignant', to=Teacher, on_delete=models.SET_NULL, null=True)
|
||||
level = models.ForeignKey(verbose_name='classe', to=Level, on_delete=models.SET_NULL, null=True)
|
||||
supplies = models.TextField('fournitures')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.supplies} pour {self.level} ({self.teacher})'
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<div class="col-12">
|
||||
<h1>Bienvenue {{ teacher.full_name }}</h1>
|
||||
<h2>
|
||||
{% block title %}Ajouter un livre{% endblock %}
|
||||
{% block title %}Ajouter {{ item }}{% endblock %}
|
||||
<a href="{% url 'list_books' teacher.pk %}" class="btn btn-secondary">Retour à la liste</a>
|
||||
</h2>
|
||||
<form action="" method="post" class="form">
|
|
@ -2,6 +2,7 @@
|
|||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Manuels - {% block title %}{% endblock %}</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
{% load bootstrap4 %}
|
||||
|
||||
{% block title %}Livres et fournitures demandés{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
@ -21,7 +23,7 @@
|
|||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h2>
|
||||
{% block title %}Liste des livres demandés{% endblock %}
|
||||
Liste des livres demandés
|
||||
<a href="{% url 'add_book' pk=teacher.pk %}" class="btn btn-primary">Ajouter un livre</a>
|
||||
</h2>
|
||||
<table class="table table-hover table-sm">
|
||||
|
@ -60,4 +62,32 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h2>
|
||||
Liste des fournitures demandées
|
||||
<a href="{% url 'add_supplies' pk=teacher.pk %}" class="btn btn-primary">Ajouter des fournitures</a>
|
||||
</h2>
|
||||
<table class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Classe</th>
|
||||
<th scope="col">Matière</th>
|
||||
<th scope="col">Liste de fournitures</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for supply in supplies %}
|
||||
<tr>
|
||||
<th scope="row">{{ forloop.counter }}</th>
|
||||
<td>{{ supply.level }}</td>
|
||||
<td>{{ supply.field }}</td>
|
||||
<td>{{ supply.supplies|linebreaksbr }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,9 +1,10 @@
|
|||
from django.urls import path
|
||||
|
||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view
|
||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView
|
||||
|
||||
urlpatterns = [
|
||||
path('teacher/<uuid:pk>/add', 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>', ListBooksView.as_view(), name='list_books'),
|
||||
path('clear', clear_teacher_view, name='clear_teacher'),
|
||||
]
|
||||
|
|
|
@ -8,8 +8,8 @@ from django.template.loader import render_to_string
|
|||
from django.urls import reverse
|
||||
from django.views.generic import CreateView, ListView
|
||||
|
||||
from manuels.forms import AddBookForm
|
||||
from manuels.models import Teacher, Book
|
||||
from manuels.forms import AddBookForm, AddSuppliesForm
|
||||
from manuels.models import Teacher, Book, SuppliesRequirement
|
||||
|
||||
|
||||
class HomePageView(CreateView):
|
||||
|
@ -62,18 +62,27 @@ class BaseTeacherView:
|
|||
|
||||
class ListBooksView(BaseTeacherView, ListView):
|
||||
model = Book
|
||||
template_name = 'manuels/list_books.html'
|
||||
template_name = 'manuels/list_books_supplies.html'
|
||||
context_object_name = 'books'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['supplies'] = SuppliesRequirement.objects.filter(teacher=self.teacher)
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
return Book.objects.filter(teacher=self.teacher)
|
||||
|
||||
|
||||
class AddBookView(BaseTeacherView, CreateView):
|
||||
model = Book
|
||||
template_name = 'manuels/add_book.html'
|
||||
form_class = AddBookForm
|
||||
class AddItemView(BaseTeacherView, CreateView):
|
||||
add_another = False
|
||||
item_text = None
|
||||
success_target = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['item'] = self.item_text
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
return {
|
||||
|
@ -92,11 +101,27 @@ class AddBookView(BaseTeacherView, CreateView):
|
|||
def get_success_url(self):
|
||||
messages.success(self.request, f'"{self.object}" a été ajouté.')
|
||||
if self.add_another:
|
||||
return reverse('add_book', args=[str(self.teacher.pk)])
|
||||
return reverse(self.success_target, args=[str(self.teacher.pk)])
|
||||
else:
|
||||
return reverse('list_books', args=[str(self.teacher.pk)])
|
||||
|
||||
|
||||
class AddBookView(AddItemView):
|
||||
model = Book
|
||||
template_name = 'manuels/add_item.html'
|
||||
form_class = AddBookForm
|
||||
success_target = 'add_book'
|
||||
item_text = 'un livre'
|
||||
|
||||
|
||||
class AddSuppliesView(AddItemView):
|
||||
model = SuppliesRequirement
|
||||
template_name = 'manuels/add_item.html'
|
||||
form_class = AddSuppliesForm
|
||||
success_target = 'add_supplies'
|
||||
item_text = 'des fournitures'
|
||||
|
||||
|
||||
def clear_teacher_view(request):
|
||||
if request.session['teacher_pk']:
|
||||
del request.session['teacher_pk']
|
||||
|
|
Loading…
Reference in a new issue