Allow no book for a level/field. Close #4

This commit is contained in:
Gabriel Augendre 2018-05-31 08:16:22 +02:00
parent b77384a8b5
commit 8c54fce37e
4 changed files with 31 additions and 1 deletions

View file

@ -6,9 +6,11 @@ from manuels.models import Book, SuppliesRequirement
class AddBookForm(forms.ModelForm): class AddBookForm(forms.ModelForm):
class Meta: class Meta:
model = Book model = Book
exclude = ['done'] fields = ['teacher', 'level', 'field', 'no_book', 'title', 'authors', 'editor', 'publication_year',
'isbn', 'price', 'previously_acquired', 'comments', 'add_another']
add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True) add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True)
no_book = forms.BooleanField(label='Pas de livre pour cette classe/matière', required=False, initial=False)
class AddSuppliesForm(forms.ModelForm): class AddSuppliesForm(forms.ModelForm):

View file

@ -0,0 +1,20 @@
document.addEventListener("DOMContentLoaded", function (event) {
var _selector = document.querySelector('#id_no_book');
_selector.addEventListener('change', function (event) {
if (_selector.checked) {
document.querySelector('#id_title').value = "PAS DE LIVRE POUR CETTE CLASSE";
document.querySelector('#id_authors').value = "N/A";
document.querySelector('#id_editor').value = 1;
document.querySelector('#id_publication_year').value = 1900;
document.querySelector('#id_isbn').value = "0000000000";
document.querySelector('#id_price').value = 0;
} else {
document.querySelector('#id_title').value = "";
document.querySelector('#id_authors').value = "";
document.querySelector('#id_editor').value = "";
document.querySelector('#id_publication_year').value = "";
document.querySelector('#id_isbn').value = "";
document.querySelector('#id_price').value = "";
}
});
});

View file

@ -1,6 +1,7 @@
{% extends 'manuels/base.html' %} {% extends 'manuels/base.html' %}
{% load bootstrap4 %} {% load bootstrap4 %}
{% load static %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
@ -25,3 +26,7 @@
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block end_js %}
<script src="{% static 'manuels/no_book.js' %}"></script>
{% endblock %}

View file

@ -17,5 +17,8 @@
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</div> </div>
{% block end_js %}
{% endblock %}
</body> </body>
</html> </html>