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

[Reformat] Update with line length 100

parent 4c6c0c0b
No related branches found
No related tags found
No related merge requests found
......@@ -9,9 +9,7 @@ class Book(models.Model):
title = models.CharField(verbose_name=_("Book title"), max_length=50)
author = models.CharField(verbose_name=_("Author name"), max_length=50, blank=True)
publisher = models.CharField(
verbose_name=_("Publishing company"), max_length=50, blank=True
)
publisher = models.CharField(verbose_name=_("Publishing company"), max_length=50, blank=True)
edition = models.PositiveSmallIntegerField(
verbose_name=_("Number of edition"), blank=True, null=True
......@@ -61,11 +59,7 @@ class BookCopy(models.Model):
"Book", blank=True, null=True, on_delete=models.CASCADE, related_name="copies"
)
borrower = models.ForeignKey(
"core.Person",
blank=True,
null=True,
on_delete=models.CASCADE,
related_name="books",
"core.Person", blank=True, null=True, on_delete=models.CASCADE, related_name="books",
)
copy_num = models.PositiveSmallIntegerField(
......
......@@ -7,9 +7,7 @@ from django_tables2.utils import A
class BooksTable(tables.Table):
class Meta:
attrs = {
"class": "table table-striped table-bordered table-hover table-responsive-xl"
}
attrs = {"class": "table table-striped table-bordered table-hover table-responsive-xl"}
isbn = tables.LinkColumn("book_by_id", args=[A("id")])
......@@ -18,9 +16,7 @@ class BooksTable(tables.Table):
args=[A("id")],
attrs={
"td": {
"data-poload": lambda record: reverse(
"book_card_by_id", kwargs={"id_": record.id}
)
"data-poload": lambda record: reverse("book_card_by_id", kwargs={"id_": record.id})
}
},
)
......@@ -28,9 +24,7 @@ class BooksTable(tables.Table):
num_copies = tables.Column(verbose_name=_("Copies"), accessor="copies.count")
edit = tables.LinkColumn(
"edit_book_by_id", args=[A("id")], verbose_name="", text=_("Edit")
)
edit = tables.LinkColumn("edit_book_by_id", args=[A("id")], verbose_name="", text=_("Edit"))
delete = tables.LinkColumn(
"delete_book_by_id", args=[A("id")], verbose_name="", text=_("Delete")
)
......@@ -38,9 +32,7 @@ class BooksTable(tables.Table):
class BookCopiesTable(tables.Table):
class Meta:
attrs = {
"class": "table table-striped table-bordered table-hover table-responsive-xl"
}
attrs = {"class": "table table-striped table-bordered table-hover table-responsive-xl"}
copy_num = tables.Column()
borrower = tables.Column()
......
......@@ -4,32 +4,19 @@ from . import views
urlpatterns = [
path("book/<int:id_>", views.book, {"template": "full"}, name="book_by_id"),
path(
"book/<int:id_>/card", views.book, {"template": "card"}, name="book_card_by_id"
),
path("book/<int:id_>/card", views.book, {"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",
"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",
"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, name="edit_book_copy_by_id"),
path(
"book/copy/<int:id_>/delete",
views.delete_book_copy,
name="delete_book_copy_by_id",
),
path(
"book/<int:id_>/copies/add", views.add_book_copies, name="add_copies_by_book_id"
),
path("book/copy/<int:id_>/delete", views.delete_book_copy, name="delete_book_copy_by_id",),
path("book/<int:id_>/copies/add", views.add_book_copies, name="add_copies_by_book_id"),
path("book/add", views.add_book, name="add_book"),
path("book/isbn/<isbn>", views.edit_book, name="edit_book_by_isbn"),
path("books", views.books, name="books"),
......
......@@ -53,9 +53,7 @@ def add_book(request: HttpRequest) -> HttpResponse:
if request.method == "POST":
if book_add_isbn_form.is_valid():
return redirect(
"edit_book_by_isbn", isbn=book_add_isbn_form.cleaned_data["isbn"]
)
return redirect("edit_book_by_isbn", isbn=book_add_isbn_form.cleaned_data["isbn"])
context["book_add_isbn_form"] = book_add_isbn_form
......@@ -72,9 +70,7 @@ def edit_book(
# If an id is passed, get this book to edit it
book = get_object_or_404(Book, pk=id_)
book_edit_form = BookEditForm(
request.POST or None, request.FILES or None, instance=book
)
book_edit_form = BookEditForm(request.POST or None, request.FILES or None, instance=book)
context["book"] = book
else:
......@@ -89,9 +85,7 @@ def edit_book(
else:
messages.warning(request, _("No information found for this ISBN."))
book_edit_form = BookEditForm(
request.POST or None, request.FILES or None, initial=initial
)
book_edit_form = BookEditForm(request.POST or None, request.FILES or None, initial=initial)
if request.method == "POST":
if book_edit_form.is_valid():
......@@ -114,9 +108,7 @@ def delete_book(request: HttpRequest, id_: int) -> HttpResponse:
book.delete()
messages.success(request, _("Book %s has been deleted.") % title)
else:
messages.error(
request, _("Books with copies that have been borrowed cannot be deleted.")
)
messages.error(request, _("Books with copies that have been borrowed cannot be deleted."))
return redirect("books")
......@@ -150,15 +142,12 @@ def add_book_copies(request: HttpRequest, id_: int) -> HttpResponse:
if request.method == "POST":
if bulk_add_form.is_valid():
new_copies = [
BookCopy(book=book) for _ in range(bulk_add_form.cleaned_data["count"])
]
new_copies = [BookCopy(book=book) for _ in range(bulk_add_form.cleaned_data["count"])]
for new_copy in new_copies:
new_copy.save()
messages.success(
request,
_("%d copies have been created.") % bulk_add_form.cleaned_data["count"],
request, _("%d copies have been created.") % bulk_add_form.cleaned_data["count"],
)
return redirect("book_by_id", id_=book.pk)
......@@ -198,9 +187,7 @@ def delete_book_copy(request: HttpRequest, id_: int) -> HttpResponse:
book_copy.delete()
messages.success(request, _("Book copy of %s has been deleted.") % book.title)
else:
messages.error(
request, _("Book copies that have been borrowed cannot be deleted.")
)
messages.error(request, _("Book copies that have been borrowed cannot be deleted."))
return redirect("book_by_id", id_=book.id)
......@@ -227,9 +214,7 @@ def book_copies_labels(request: HttpRequest, id_: int) -> HttpResponse:
barcode_image = PIL.Image.open(BytesIO(barcode_raw))
barcode_file = os.path.join(temp_dir, "%s.png" % obj.barcode)
barcode_image.save(barcode_file, "png")
label.add(
shapes.Image(0, 30, width, 30, os.path.join(temp_dir, barcode_file))
)
label.add(shapes.Image(0, 30, width, 30, os.path.join(temp_dir, barcode_file)))
school = shapes.String(0, 8, School.objects.first().name, fontSize=10)
label.add(school)
......@@ -269,9 +254,7 @@ def get_copy(request: HttpRequest) -> HttpResponse:
if request.method == "POST":
if book_copy_form.is_valid():
return redirect(
"book_copy_by_barcode", barcode=book_copy_form.cleaned_data["barcode"]
)
return redirect("book_copy_by_barcode", barcode=book_copy_form.cleaned_data["barcode"])
context["book_copy_form"] = book_copy_form
......@@ -298,16 +281,12 @@ def person_borrow(request: HttpRequest) -> HttpResponse:
if person_borrow_form.is_valid():
person = person_borrow_form.cleaned_data["borrower"]
for barcode_line in person_borrow_form.cleaned_data[
"barcodes"
].splitlines():
for barcode_line in person_borrow_form.cleaned_data["barcodes"].splitlines():
try:
book_copy = BookCopy.objects.get(barcode=barcode_line)
except BookCopy.DoesNotExist:
messages.error(
request,
_("Barcode %(barcode)s is invalid.")
% {"barcode": barcode_line},
request, _("Barcode %(barcode)s is invalid.") % {"barcode": barcode_line},
)
continue
......
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