From cbf6c942b9b81d6c22e861b084401fd4bcb49a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Sun, 22 Dec 2024 18:53:47 +0100 Subject: [PATCH] Complete Catalogs with code refactoring --- ram/bookshelf/admin.py | 2 + .../0016_basebook_book_catalogue.py | 2 - ram/bookshelf/models.py | 18 +++-- ram/portal/templates/bookshelf/book.html | 29 +++++++-- ram/portal/templates/bookshelf/books.html | 8 ++- ram/portal/templates/cards.html | 2 +- ram/portal/templates/cards/book.html | 18 ++++- ram/portal/templatetags/dynamic_url.py | 19 ++++++ ram/portal/urls.py | 14 ++-- ram/portal/views.py | 65 +++++++++---------- 10 files changed, 118 insertions(+), 59 deletions(-) create mode 100644 ram/portal/templatetags/dynamic_url.py diff --git a/ram/bookshelf/admin.py b/ram/bookshelf/admin.py index 5c297b8..f2d7e70 100644 --- a/ram/bookshelf/admin.py +++ b/ram/bookshelf/admin.py @@ -35,6 +35,7 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin): "number_of_pages", "published", ) + autocomplete_fields = ("authors", "publisher") readonly_fields = ("creation_time", "updated_time") search_fields = ("title", "publisher__name", "authors__last_name") list_filter = ("publisher__name", "authors") @@ -101,6 +102,7 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin): "get_scales", "published", ) + autocomplete_fields = ("manufacturer",) readonly_fields = ("creation_time", "updated_time") search_fields = ("manufacturer__name", "years", "scales__scale") list_filter = ("manufacturer__name", "publication_year", "scales__scale") diff --git a/ram/bookshelf/migrations/0016_basebook_book_catalogue.py b/ram/bookshelf/migrations/0016_basebook_book_catalogue.py index 0be21a2..5e44540 100644 --- a/ram/bookshelf/migrations/0016_basebook_book_catalogue.py +++ b/ram/bookshelf/migrations/0016_basebook_book_catalogue.py @@ -127,8 +127,6 @@ class Migration(migrations.Migration): ( "manufacturer", models.ForeignKey( - blank=True, - null=True, on_delete=django.db.models.deletion.CASCADE, to="metadata.manufacturer", ), diff --git a/ram/bookshelf/models.py b/ram/bookshelf/models.py index 83c32c9..a632bdf 100644 --- a/ram/bookshelf/models.py +++ b/ram/bookshelf/models.py @@ -108,15 +108,16 @@ class Book(BaseBook): return self.publisher.name def get_absolute_url(self): - return reverse("book", kwargs={"uuid": self.uuid}) + return reverse( + "bookshelf_item", + kwargs={"selector": "book", "uuid": self.uuid} + ) class Catalog(BaseBook): manufacturer = models.ForeignKey( Manufacturer, on_delete=models.CASCADE, - null=True, - blank=True, ) years = models.CharField(max_length=12) scales = models.ManyToManyField(Scale) @@ -125,8 +126,15 @@ class Catalog(BaseBook): ordering = ["manufacturer", "publication_year"] def __str__(self): - scales = "/".join([s.scale for s in self.scales.all()]) + scales = self.get_scales return "%s %s %s" % (self.manufacturer.name, self.years, scales) def get_absolute_url(self): - return reverse("catalog", kwargs={"uuid": self.uuid}) + return reverse( + "bookshelf_item", + kwargs={"selector": "catalog", "uuid": self.uuid} + ) + + @property + def get_scales(self): + return "/".join([s.scale for s in self.scales.all()]) diff --git a/ram/portal/templates/bookshelf/book.html b/ram/portal/templates/bookshelf/book.html index 23f73fd..4d4fc43 100644 --- a/ram/portal/templates/bookshelf/book.html +++ b/ram/portal/templates/bookshelf/book.html @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% load dynamic_url %} {% block header %} {% if book.tags.all %} @@ -57,24 +58,39 @@ {{ book.description | safe }} + {% if type == "catalog" %} + Catalog + {% elif type == "book" %} Book + {% endif %} + {% if type == "catalog" %} + + Manufacturer + {{ book.manufacturer }} + + + Scales + {{ book.get_scales }} + + {% elif type == "book" %} Title {{ book.title }} - Authors - - - + Authors + + + - Publisher + Publisher {{ book.publisher }} + {% endif %} ISBN {{ book.ISBN|default:"-" }} @@ -120,7 +136,8 @@
- {% if request.user.is_staff %}Edit{% endif %} + FIXME: {{ type }} + {% if request.user.is_staff %}Edit{% endif %}
diff --git a/ram/portal/templates/bookshelf/books.html b/ram/portal/templates/bookshelf/books.html index 049c7b0..a2e3e2e 100644 --- a/ram/portal/templates/bookshelf/books.html +++ b/ram/portal/templates/bookshelf/books.html @@ -1,11 +1,13 @@ {% extends "cards.html" %} +{% load dynamic_url %} + {% block pagination %} {% if data.has_other_pages %}