Pimp add book form
This commit is contained in:
parent
8040674be9
commit
f98bc4f14d
6 changed files with 92 additions and 8 deletions
|
@ -24,6 +24,7 @@ class EditBookForm(forms.ModelForm):
|
||||||
self.fields['teacher'].widget.attrs.update({'class': 'custom-select'})
|
self.fields['teacher'].widget.attrs.update({'class': 'custom-select'})
|
||||||
self.fields['editor'].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['previously_acquired'].widget.attrs.update({'class': 'custom-select'})
|
||||||
|
if 'level' in self.fields:
|
||||||
self.fields['level'].widget.attrs.update({'class': 'custom-select'})
|
self.fields['level'].widget.attrs.update({'class': 'custom-select'})
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
7
manuels/static/manuels/fetch-isbn.js
Normal file
7
manuels/static/manuels/fetch-isbn.js
Normal 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) {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
69
manuels/templates/manuels/add_book.html
Normal file
69
manuels/templates/manuels/add_book.html
Normal 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 %}
|
|
@ -20,7 +20,8 @@
|
||||||
<form action="" method="post" class="form">
|
<form action="" method="post" class="form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if form %}
|
{% if form %}
|
||||||
{% bootstrap_form form %}
|
{% block form %}
|
||||||
|
{% endblock %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% buttons %}
|
{% buttons %}
|
||||||
<button type="submit" class="btn btn-{{ button_class }}">{{ verb }}</button>
|
<button type="submit" class="btn btn-{{ button_class }}">{{ verb }}</button>
|
||||||
|
@ -29,7 +30,3 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block end_js %}
|
|
||||||
<script src="{% static 'manuels/no_book.js' %}"></script>
|
|
||||||
{% endblock %}
|
|
8
manuels/templates/manuels/add_supplies.html
Normal file
8
manuels/templates/manuels/add_supplies.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends 'manuels/add_item.html' %}
|
||||||
|
|
||||||
|
{% load bootstrap4 %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block form %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
{% endblock %}
|
|
@ -61,7 +61,6 @@ class ItemView(BaseTeacherView):
|
||||||
item_text_plural = None
|
item_text_plural = None
|
||||||
success_target = None
|
success_target = None
|
||||||
message_template = None
|
message_template = None
|
||||||
template_name = 'manuels/add_item.html'
|
|
||||||
verb = None
|
verb = None
|
||||||
button_class = 'primary'
|
button_class = 'primary'
|
||||||
|
|
||||||
|
@ -117,6 +116,7 @@ class BookView:
|
||||||
|
|
||||||
class AddBookView(BookView, AddItemView):
|
class AddBookView(BookView, AddItemView):
|
||||||
form_class = AddBookForm
|
form_class = AddBookForm
|
||||||
|
template_name = 'manuels/add_book.html'
|
||||||
|
|
||||||
def form_valid(self, form: AddBookForm):
|
def form_valid(self, form: AddBookForm):
|
||||||
self.add_another = form.cleaned_data['add_another']
|
self.add_another = form.cleaned_data['add_another']
|
||||||
|
@ -150,10 +150,10 @@ class SuppliesView:
|
||||||
class AddSuppliesView(SuppliesView, AddItemView):
|
class AddSuppliesView(SuppliesView, AddItemView):
|
||||||
form_class = AddSuppliesForm
|
form_class = AddSuppliesForm
|
||||||
message_template = 'manuels/supplies_message.html'
|
message_template = 'manuels/supplies_message.html'
|
||||||
|
template_name = 'manuels/add_supplies.html'
|
||||||
|
|
||||||
|
|
||||||
class EditItemView(ItemView, UpdateView):
|
class EditItemView(ItemView, UpdateView):
|
||||||
template_name = 'manuels/add_item.html'
|
|
||||||
teacher_field = 'teacher_pk'
|
teacher_field = 'teacher_pk'
|
||||||
item_text = None
|
item_text = None
|
||||||
item_text_plural = None
|
item_text_plural = None
|
||||||
|
@ -170,10 +170,12 @@ class EditItemView(ItemView, UpdateView):
|
||||||
|
|
||||||
class EditBookView(BookView, EditItemView):
|
class EditBookView(BookView, EditItemView):
|
||||||
form_class = EditBookForm
|
form_class = EditBookForm
|
||||||
|
template_name = 'manuels/add_book.html'
|
||||||
|
|
||||||
|
|
||||||
class EditSuppliesView(SuppliesView, EditItemView):
|
class EditSuppliesView(SuppliesView, EditItemView):
|
||||||
form_class = EditSuppliesForm
|
form_class = EditSuppliesForm
|
||||||
|
template_name = 'manuels/add_supplies.html'
|
||||||
|
|
||||||
|
|
||||||
class DeleteItemView(ItemView, DeleteView):
|
class DeleteItemView(ItemView, DeleteView):
|
||||||
|
|
Loading…
Reference in a new issue