From f98bc4f14d5b8a649357b833cadb6c75bb3ccb99 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 15 Jun 2018 20:41:29 +0200 Subject: [PATCH] Pimp add book form --- manuels/forms.py | 3 +- manuels/static/manuels/fetch-isbn.js | 7 +++ manuels/templates/manuels/add_book.html | 69 +++++++++++++++++++++ manuels/templates/manuels/add_item.html | 7 +-- manuels/templates/manuels/add_supplies.html | 8 +++ manuels/views.py | 6 +- 6 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 manuels/static/manuels/fetch-isbn.js create mode 100644 manuels/templates/manuels/add_book.html create mode 100644 manuels/templates/manuels/add_supplies.html diff --git a/manuels/forms.py b/manuels/forms.py index e4c95bc..e13bf89 100644 --- a/manuels/forms.py +++ b/manuels/forms.py @@ -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'] diff --git a/manuels/static/manuels/fetch-isbn.js b/manuels/static/manuels/fetch-isbn.js new file mode 100644 index 0000000..4c38526 --- /dev/null +++ b/manuels/static/manuels/fetch-isbn.js @@ -0,0 +1,7 @@ +document.addEventListener("DOMContentLoaded", function (event) { + console.log('document loaded'); + var isbn = document.querySelector('#id_isbn'); + isbn.addEventListener('change', function (event) { + + }); +}); diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html new file mode 100644 index 0000000..3df2f2e --- /dev/null +++ b/manuels/templates/manuels/add_book.html @@ -0,0 +1,69 @@ +{% extends 'manuels/add_item.html' %} + +{% load bootstrap4 %} +{% load static %} + +{% block form %} +
+
+ {% if form.levels %} + {% bootstrap_field form.levels %} + {% elif form.level %} + {% bootstrap_field form.level %} + {% endif %} +
+
+ {% bootstrap_field form.teacher %} + {% bootstrap_field form.field %} +
+
+
+
+ {% bootstrap_field form.no_book %} +
+
+ {% bootstrap_field form.see_later %} +
+
+
+
+ {% bootstrap_field form.isbn %} +
+
+
+
+ {% bootstrap_field form.title %} + {% bootstrap_field form.authors %} +
+
+ {% bootstrap_field form.publication_year %} + {% bootstrap_field form.price %} +
+
+ {% bootstrap_field form.editor %} + {% bootstrap_field form.other_editor %} +
+
+
+
+ {% bootstrap_field form.previously_acquired %} +
+
+
+
+ {% bootstrap_field form.comments %} +
+
+ {% if form.add_another %} +
+
+ {% bootstrap_field form.add_another %} +
+
+ {% endif %} +{% endblock %} + +{% block end_js %} + + +{% endblock %} \ No newline at end of file diff --git a/manuels/templates/manuels/add_item.html b/manuels/templates/manuels/add_item.html index 99688fd..52e8e41 100644 --- a/manuels/templates/manuels/add_item.html +++ b/manuels/templates/manuels/add_item.html @@ -20,7 +20,8 @@
{% csrf_token %} {% if form %} - {% bootstrap_form form %} + {% block form %} + {% endblock %} {% endif %} {% buttons %} @@ -29,7 +30,3 @@ {% endblock %} - -{% block end_js %} - -{% endblock %} \ No newline at end of file diff --git a/manuels/templates/manuels/add_supplies.html b/manuels/templates/manuels/add_supplies.html new file mode 100644 index 0000000..f8e2c4e --- /dev/null +++ b/manuels/templates/manuels/add_supplies.html @@ -0,0 +1,8 @@ +{% extends 'manuels/add_item.html' %} + +{% load bootstrap4 %} +{% load static %} + +{% block form %} + {% bootstrap_form form %} +{% endblock %} diff --git a/manuels/views.py b/manuels/views.py index 02d6fbf..43b0efc 100644 --- a/manuels/views.py +++ b/manuels/views.py @@ -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):