Skip to content
Snippets Groups Projects
Commit ad8af3fe authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'issue8' into 'master'

Add function to quick open a copy. Closes #8.

Closes #8

See merge request Teckids/BiscuIT/BiscuIT-App-Exlibris!3
parents c5fc8d14 d1342fe0
No related branches found
No related tags found
1 merge request!3Add function to quick open a copy. Closes #8.
......@@ -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:
......
......@@ -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']
}
]
}
......
{% 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 %}
{% 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 %}
......@@ -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,
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment