diff --git a/biscuit/apps/exlibris/forms.py b/biscuit/apps/exlibris/forms.py index 5282795822ae85b154bb2fb23a9740a7ce9e121e..69b6be4d7cc4bab5971b1bcc7f0092d18bfd9850 100644 --- a/biscuit/apps/exlibris/forms.py +++ b/biscuit/apps/exlibris/forms.py @@ -11,6 +11,10 @@ class BookAddISBNForm(forms.ModelForm): model = Book fields = ['isbn'] +class BookGetCopyForm(forms.ModelForm): + class Meta: + model = BookCopy + fields = ['barcode'] class BookEditForm(forms.ModelForm): class Meta: diff --git a/biscuit/apps/exlibris/menus.py b/biscuit/apps/exlibris/menus.py index 7d6e965c4cb50f7fa6d54304dfa4b02b97daf8ef..5b7e4da8e382499f53b4fb843d9498b9557bac94 100644 --- a/biscuit/apps/exlibris/menus.py +++ b/biscuit/apps/exlibris/menus.py @@ -16,6 +16,11 @@ MENUS = { 'name': _('Add book'), 'url': 'add_book', 'validators': ['menu_generator.validators.is_authenticated'] + }, + { + 'name': _('Open copy'), + 'url': 'get_copy', + 'validators': ['menu_generator.validators.is_authenticated'] } ] } diff --git a/biscuit/apps/exlibris/templates/exlibris/copy_full.html b/biscuit/apps/exlibris/templates/exlibris/copy_full.html new file mode 100644 index 0000000000000000000000000000000000000000..b167241287188bf691566850568b423a2486cbe1 --- /dev/null +++ b/biscuit/apps/exlibris/templates/exlibris/copy_full.html @@ -0,0 +1,63 @@ +{% extends "core/base.html" %} +{% load bootstrap4 font_awesome i18n staticfiles %} +{% load render_table from django_tables2 %} + +{% block bootstrap4_extra_head %} + {{ block.super }} + <link rel="stylesheet" href="{% static 'css/exlibris/books.css' %}" /> +{% endblock %} + +{% block content %} + <div class="d-flex justify-content-between"> + <div> + <h1>{{ book_copy.book.title }}</h1> + </div> + <div class="btn-group" role="group" aria-label="Book actions"> + <a href="{% url 'edit_book_copy_by_id' id_=book_copy.id %}" class="btn btn-secondary"> + {% fa 'pencil' %} + </a> + </div> + </div> + + <table class="table table-responsive-xl table-border table-striped"> + <tr> + <td rowspan="4"> + {% if book_copy.book.cover %} + <img class="book-img" src="{{ book_copy.book.cover.url }}" alt="{{ book_copy.book.title }}" /> + {% else %} + <img class="book-img" src="{% static 'exlibris/img/fallback.png' %}" alt="{{ book_copy.book.title }}" /> + {% endif %} + </td> + <td>{% fa 'book' %}</td> + <td colspan="3">{{ book_copy.book.title }}</td> + </tr> + <tr> + <td>{% fa 'pencil' %}</td> + <td colspan="3">{{ book_copy.book.author }}</td> + </tr> + <tr> + <td>{% fa 'building' %}</td> + <td colspan="3">{{ book_copy.book.publisher }}</td> + </tr> + <tr> + <td>{% fa 'hashtag' %}</td> + <td>{{ book_copy.book.edition }}</td> + <td>{% fa 'calendar-edit' %}</td> + <td>{{ book_copy.book.year }}</td> + </tr> + </table> + + <h3>{% blocktrans %}Information about the borrower{% endblocktrans %}</h3> + <table class="table table-responsive-xl table-border table-striped"> + <tr> + <td>{% fa 'user' %}</td> + <td colspan="3">{{ book_copy.borrower.Person.first_name }} {{ book_copy.borrower.Person.last_name }}</td> + </tr> + <tr> + <td>{% fa 'medal' %}</td> + <td colspan="3">{{ book_copy.get_condition_display }}</td> + </tr> + </table> + + +{% endblock %} diff --git a/biscuit/apps/exlibris/templates/exlibris/get_copy.html b/biscuit/apps/exlibris/templates/exlibris/get_copy.html new file mode 100644 index 0000000000000000000000000000000000000000..96a46584af45eda72d422b7101c6c00aa2892391 --- /dev/null +++ b/biscuit/apps/exlibris/templates/exlibris/get_copy.html @@ -0,0 +1,10 @@ +{% extends "core/base.html" %} +{% load bootstrap4 %} + +{% block content %} +<form method="post"> + {% csrf_token %} + {% bootstrap_form book_copy_form %} + <input type="submit" value="Get" /> +</form> +{% endblock %} diff --git a/biscuit/apps/exlibris/urls.py b/biscuit/apps/exlibris/urls.py index 6b22ba61c8ba16ee0af9234c4c9e3711bab2883f..03693a9d68c63ae0646b85fa60e2c2f1467c4154 100644 --- a/biscuit/apps/exlibris/urls.py +++ b/biscuit/apps/exlibris/urls.py @@ -10,6 +10,9 @@ urlpatterns = [ {'template': 'card'}, name='book_card_by_id'), path('book/<int:id_>/edit', views.edit_book, name='edit_book_by_id'), path('book/<int:id_>/delete', views.delete_book, name='delete_book_by_id'), + path('book/get_copy', views.get_copy, name='get_copy'), + path('book/copy/<barcode>', views.book_copy, + {'template': 'full'}, name='book_copy_by_barcode'), path('book/<int:id_>/copies/labels', views.book_copies_labels, name='copies_labels_by_book_id'), path('book/copy/<int:id_>/edit', views.edit_book_copy, diff --git a/biscuit/apps/exlibris/views.py b/biscuit/apps/exlibris/views.py index 114a48345f4592bc86983befcd708878f7e66759..412f81a2020d5f8145ab1f4715868a1051c84fb0 100644 --- a/biscuit/apps/exlibris/views.py +++ b/biscuit/apps/exlibris/views.py @@ -15,7 +15,7 @@ from reportlab.graphics import barcode, shapes from biscuit.core.util import messages -from .forms import BookAddISBNForm, BookEditForm, BookCopiesBulkAddForm, BookCopyEditForm +from .forms import BookAddISBNForm, BookEditForm, BookCopiesBulkAddForm, BookCopyEditForm, BookGetCopyForm from .models import Book, BookCopy from .tables import BooksTable, BookCopiesTable from .util import get_book_meta @@ -228,3 +228,28 @@ def book_copies_labels(request, id_): sheet.save(pdf_file) return FileResponse(open(pdf_file, 'rb'), as_attachment=True) + + +@login_required +def get_copy(request): + context = {} + + book_copy_form = BookGetCopyForm(request.POST or None) + + if request.method == 'POST': + if book_copy_form.is_valid(): + return redirect('book_copy_by_barcode', barcode=book_copy_form.cleaned_data['barcode']) + + context['book_copy_form'] = book_copy_form + + return render(request, 'exlibris/get_copy.html', context) + + +@login_required +def book_copy(request, barcode, template): + context = {} + + book_copy = get_object_or_404(BookCopy, barcode=barcode) + context['book_copy'] = book_copy + + return render(request, 'exlibris/copy_%s.html' % template, context)