Pimp add book form

This commit is contained in:
Gabriel Augendre 2018-06-15 20:41:29 +02:00
parent 8040674be9
commit f98bc4f14d
6 changed files with 92 additions and 8 deletions

View file

@ -24,7 +24,8 @@ class EditBookForm(forms.ModelForm):
self.fields['teacher'].widget.attrs.update({'class': 'custom-select'})
self.fields['editor'].widget.attrs.update({'class': 'custom-select'})
self.fields['previously_acquired'].widget.attrs.update({'class': 'custom-select'})
self.fields['level'].widget.attrs.update({'class': 'custom-select'})
if 'level' in self.fields:
self.fields['level'].widget.attrs.update({'class': 'custom-select'})
def clean(self):
editor = self.cleaned_data['editor']

View file

@ -0,0 +1,7 @@
document.addEventListener("DOMContentLoaded", function (event) {
console.log('document loaded');
var isbn = document.querySelector('#id_isbn');
isbn.addEventListener('change', function (event) {
});
});

View file

@ -0,0 +1,69 @@
{% extends 'manuels/add_item.html' %}
{% load bootstrap4 %}
{% load static %}
{% block form %}
<div class="form-row">
<div class="col-lg-6">
{% if form.levels %}
{% bootstrap_field form.levels %}
{% elif form.level %}
{% bootstrap_field form.level %}
{% endif %}
</div>
<div class="col-lg-6">
{% bootstrap_field form.teacher %}
{% bootstrap_field form.field %}
</div>
</div>
<div class="form-row">
<div class="col-lg-6">
{% bootstrap_field form.no_book %}
</div>
<div class="col-lg-6">
{% bootstrap_field form.see_later %}
</div>
</div>
<div class="form-row">
<div class="col-12">
{% bootstrap_field form.isbn %}
</div>
</div>
<div class="form-row">
<div class="col-lg-4">
{% bootstrap_field form.title %}
{% bootstrap_field form.authors %}
</div>
<div class="col-lg-4">
{% bootstrap_field form.publication_year %}
{% bootstrap_field form.price %}
</div>
<div class="col-lg-4">
{% bootstrap_field form.editor %}
{% bootstrap_field form.other_editor %}
</div>
</div>
<div class="form-row">
<div class="col-12">
{% bootstrap_field form.previously_acquired %}
</div>
</div>
<div class="form-row">
<div class="col-12">
{% bootstrap_field form.comments %}
</div>
</div>
{% if form.add_another %}
<div class="form-row">
<div class="col-12">
{% bootstrap_field form.add_another %}
</div>
</div>
{% endif %}
{% endblock %}
{% block end_js %}
<script src="{% static 'manuels/no_book.js' %}"></script>
<script src="{% static 'manuels/fetch-isbn.js' %}"></script>
{% endblock %}

View file

@ -20,7 +20,8 @@
<form action="" method="post" class="form">
{% csrf_token %}
{% if form %}
{% bootstrap_form form %}
{% block form %}
{% endblock %}
{% endif %}
{% buttons %}
<button type="submit" class="btn btn-{{ button_class }}">{{ verb }}</button>
@ -29,7 +30,3 @@
</div>
</div>
{% endblock %}
{% block end_js %}
<script src="{% static 'manuels/no_book.js' %}"></script>
{% endblock %}

View file

@ -0,0 +1,8 @@
{% extends 'manuels/add_item.html' %}
{% load bootstrap4 %}
{% load static %}
{% block form %}
{% bootstrap_form form %}
{% endblock %}

View file

@ -61,7 +61,6 @@ class ItemView(BaseTeacherView):
item_text_plural = None
success_target = None
message_template = None
template_name = 'manuels/add_item.html'
verb = None
button_class = 'primary'
@ -117,6 +116,7 @@ class BookView:
class AddBookView(BookView, AddItemView):
form_class = AddBookForm
template_name = 'manuels/add_book.html'
def form_valid(self, form: AddBookForm):
self.add_another = form.cleaned_data['add_another']
@ -150,10 +150,10 @@ class SuppliesView:
class AddSuppliesView(SuppliesView, AddItemView):
form_class = AddSuppliesForm
message_template = 'manuels/supplies_message.html'
template_name = 'manuels/add_supplies.html'
class EditItemView(ItemView, UpdateView):
template_name = 'manuels/add_item.html'
teacher_field = 'teacher_pk'
item_text = None
item_text_plural = None
@ -170,10 +170,12 @@ class EditItemView(ItemView, UpdateView):
class EditBookView(BookView, EditItemView):
form_class = EditBookForm
template_name = 'manuels/add_book.html'
class EditSuppliesView(SuppliesView, EditItemView):
form_class = EditSuppliesForm
template_name = 'manuels/add_supplies.html'
class DeleteItemView(ItemView, DeleteView):