Implement teacher lists confirmation. #19
This commit is contained in:
parent
f548eb711b
commit
68de1aefea
7 changed files with 128 additions and 28 deletions
18
manuels/migrations/0022_teacher_has_confirmed_list.py
Normal file
18
manuels/migrations/0022_teacher_has_confirmed_list.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.5 on 2018-06-02 15:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0021_auto_20180602_1638'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='teacher',
|
||||
name='has_confirmed_list',
|
||||
field=models.BooleanField(default=False, verbose_name='a confirmé les listes'),
|
||||
),
|
||||
]
|
|
@ -48,6 +48,11 @@ class Teacher(BaseModel):
|
|||
help_text='Utilisée pour vous transmettre votre lien personnel',
|
||||
unique=True
|
||||
)
|
||||
has_confirmed_list = models.BooleanField(
|
||||
'a confirmé les listes',
|
||||
default=False,
|
||||
blank=True
|
||||
)
|
||||
|
||||
def get_absolute_url(self):
|
||||
from django.urls import reverse
|
||||
|
|
29
manuels/templates/manuels/confirm_teacher.html
Normal file
29
manuels/templates/manuels/confirm_teacher.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
{% extends 'manuels/base.html' %}
|
||||
|
||||
{% load bootstrap4 %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-8 offset-2">
|
||||
<h1>Bienvenue {{ teacher.full_name }}</h1>
|
||||
<h2>
|
||||
{% block title %}Confirmer les listes{% endblock %}
|
||||
<a href="{% url 'list_books' teacher.pk %}" class="btn btn-secondary">Retour à vos listes</a>
|
||||
</h2>
|
||||
<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 confirmer vos listes ?
|
||||
Cette action est définitive : vous ne pourrez plus les modifier ensuite.</strong>
|
||||
</p>
|
||||
</div>
|
||||
<form action="" method="post" class="form">
|
||||
{% csrf_token %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-danger">Confirmer</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -7,8 +7,15 @@
|
|||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Bienvenue {{ teacher.full_name }} <a href="{% url 'clear_teacher' %}" class="btn btn-warning">Se
|
||||
déconnecter</a></h1>
|
||||
<h1>Bienvenue {{ teacher.full_name }}
|
||||
<a href="{% url 'clear_teacher' %}" class="btn btn-warning">
|
||||
<i class="fas fa-sign-out-alt"></i> Se déconnecter</a>
|
||||
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<a href="{% url 'confirm_teacher' pk=teacher.pk %}" class="btn btn-danger">
|
||||
<i class="fas fa-check-circle"></i> Confirmer ma liste</a>
|
||||
{% endif %}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-warning" role="alert">
|
||||
|
@ -25,13 +32,19 @@
|
|||
<div class="col-12">
|
||||
<h2>
|
||||
Liste des livres demandés
|
||||
<a href="{% url 'add_book' pk=teacher.pk %}" class="btn btn-primary">Ajouter un livre</a>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<a href="{% url 'add_book' pk=teacher.pk %}" class="btn btn-primary">
|
||||
<i class="fas fa-plus-circle"></i> Ajouter un livre
|
||||
</a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<th scope="col">Modifier</th>
|
||||
{% endif %}
|
||||
<th scope="col">Classe</th>
|
||||
<th scope="col">Discipline</th>
|
||||
<th scope="col">Titre</th>
|
||||
|
@ -47,6 +60,7 @@
|
|||
<tbody>
|
||||
{% for book in books %}
|
||||
<tr>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<th scope="row">
|
||||
<div class="btn-group">
|
||||
<a title="Modifier"
|
||||
|
@ -57,6 +71,7 @@
|
|||
class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></a>
|
||||
</div>
|
||||
</th>
|
||||
{% endif %}
|
||||
<td>{{ book.level }}</td>
|
||||
<td>{{ book.field }}</td>
|
||||
<td>{{ book.title }}</td>
|
||||
|
@ -81,13 +96,19 @@
|
|||
<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>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<a href="{% url 'add_supplies' pk=teacher.pk %}" class="btn btn-primary">
|
||||
<i class="fas fa-plus-circle"></i> Ajouter des fournitures
|
||||
</a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<th scope="col">Modifier</th>
|
||||
{% endif %}
|
||||
<th scope="col">Classe</th>
|
||||
<th scope="col">Disciplines</th>
|
||||
<th scope="col">Liste de fournitures</th>
|
||||
|
@ -96,6 +117,7 @@
|
|||
<tbody>
|
||||
{% for supply in supplies %}
|
||||
<tr>
|
||||
{% if not teacher.has_confirmed_list %}
|
||||
<th scope="row">
|
||||
<div class="btn-group">
|
||||
<a title="Modifier"
|
||||
|
@ -106,6 +128,7 @@
|
|||
class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></a>
|
||||
</div>
|
||||
</th>
|
||||
{% endif %}
|
||||
<td>{{ supply.level }}</td>
|
||||
<td>{{ supply.fields }}</td>
|
||||
<td>{{ supply.supplies|linebreaksbr }}</td>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from manuels.views import AddBookView, ListBooksView, clear_teacher_view, AddSuppliesView, EditBookView, \
|
||||
EditSuppliesView, DeleteBookView, DeleteSuppliesView
|
||||
EditSuppliesView, DeleteBookView, DeleteSuppliesView, ConfirmTeacherView
|
||||
|
||||
urlpatterns = [
|
||||
path('teacher/<uuid:pk>/add_book', AddBookView.as_view(), name='add_book'),
|
||||
|
@ -11,5 +11,6 @@ urlpatterns = [
|
|||
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('teacher/<uuid:pk>/confirm', ConfirmTeacherView.as_view(), name='confirm_teacher'),
|
||||
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, DeleteView
|
||||
from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView
|
||||
|
||||
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
|
||||
from manuels.models import Teacher, Book, SuppliesRequirement
|
||||
|
@ -70,6 +70,13 @@ class ItemView(BaseTeacherView):
|
|||
verb = None
|
||||
button_class = 'primary'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
response = super().dispatch(request, *args, **kwargs)
|
||||
if self.teacher.has_confirmed_list:
|
||||
messages.error(request, "Vous avez déjà confirmé vos listes. Il n'est plus possible de les modifier.")
|
||||
return redirect('list_books', pk=self.teacher.pk)
|
||||
return response
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['item'] = self.item_text
|
||||
|
@ -180,3 +187,15 @@ def clear_teacher_view(request):
|
|||
if request.session['teacher_pk']:
|
||||
del request.session['teacher_pk']
|
||||
return redirect('home_page')
|
||||
|
||||
|
||||
class ConfirmTeacherView(BaseTeacherView, UpdateView):
|
||||
model = Teacher
|
||||
fields = []
|
||||
template_name = 'manuels/confirm_teacher.html'
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
self.object.has_confirmed_list = True
|
||||
self.object.save()
|
||||
return response
|
||||
|
|
|
@ -14,6 +14,7 @@ import os
|
|||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import dj_database_url
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -165,3 +166,7 @@ ANYMAIL = {
|
|||
}
|
||||
|
||||
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
|
||||
|
||||
MESSAGE_TAGS = {
|
||||
messages.ERROR: 'danger',
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue