From eece40afcd8bc0bd6c2616e3efe3b62f9e46d687 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Thu, 15 Aug 2024 10:17:58 -0500 Subject: [PATCH 1/3] refactor: Update thumbnail size to 400x350 pixels --- denig/models.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/denig/models.py b/denig/models.py index 27fc72a..2187f89 100644 --- a/denig/models.py +++ b/denig/models.py @@ -219,7 +219,6 @@ class Image(models.Model): choices=IMAGE_TYPES, default="recto", ) - thumbnail = ImageSpecField( source="image", processors=[ResizeToFill(400, 350)], @@ -233,7 +232,8 @@ def __str__(self): def image_preview(self): if self.image: return mark_safe( - '' % self.image.url + '' + % self.thumbnail.url ) else: return "No image attached" @@ -349,15 +349,6 @@ def file_url(self): if self.item_file and hasattr(self.item_file, "url"): return self.item_file.url - # def admin_thumbnails(self): - # """Return a thumbnail for the document.""" - # return Fragment.admin_thumbnails( - # images=[image["image"].size(height=200) for image in self.images], - # labels=[image["label"] for image in self.images], - # ) - - # admin_thumbnails.short_description = "Images" - class MusicScore(ImportExportMixin, models.Model): title = models.CharField(max_length=255, blank=True) From e234925a86894ef99bb7d4bbc9093a86a1f0f0e2 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Thu, 15 Aug 2024 10:18:12 -0500 Subject: [PATCH 2/3] refactor: Update dotenv configuration to load environment variables with verbose and override options --- config/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/settings.py b/config/settings.py index 1e1103b..f555f21 100644 --- a/config/settings.py +++ b/config/settings.py @@ -5,7 +5,7 @@ import environ from dotenv import load_dotenv -load_dotenv() +load_dotenv(verbose=True, override=True) # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve(strict=True).parent.parent From 1dfcf1ebe37df0655a2dbe6008c0032218231944 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Thu, 15 Aug 2024 10:18:52 -0500 Subject: [PATCH 3/3] feat: Forensic modal for viewing associated images --- denig/views.py | 45 ++++++++-------- templates/forensics_partial.html | 9 ++++ templates/manuscript.html | 71 ++++++++++++++++++------ templates/manuscript_musicscore.html | 28 ++++++++++ templates/manuscript_page.html | 81 +++++++++++++++++----------- 5 files changed, 168 insertions(+), 66 deletions(-) create mode 100644 templates/forensics_partial.html diff --git a/denig/views.py b/denig/views.py index fb4923e..c4a351c 100644 --- a/denig/views.py +++ b/denig/views.py @@ -1,7 +1,7 @@ from urllib.parse import parse_qs, urlencode, urlparse, urlunparse from django.http import HttpRequest -from django.shortcuts import render +from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.views import generic @@ -43,13 +43,10 @@ def education(request: HttpRequest): class DocumentListView(generic.ListView): - paginate_by = ( - # to get the first page layout to work, we need to offset by an odd number - 11 - ) model = Document context_object_name = "document_list" template_name = "manuscript.html" + paginate_by = 13 def get_queryset(self): # This method ensures the documents are ordered by 'document_id' @@ -63,6 +60,7 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) page_obj = context.get("page_obj") context["is_first_page"] = page_obj and page_obj.number == 1 + return context @@ -104,10 +102,7 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # Get the current document - try: - current_document = self.get_queryset().get(slug=self.kwargs["slug"]) - except Document.DoesNotExist: - current_document = None + current_document = get_object_or_404(Document, slug=self.kwargs["slug"]) # Get previous and next pages try: @@ -159,21 +154,29 @@ def get_context_data(self, **kwargs): if next_page.attached_images.all().exists(): next_image_url = next_page.attached_images.all()[0].image.url cleaned_next_image_url = self.clean_url(next_image_url) - print( - f"Next image URL: {next_image_url}, Cleaned next image URL: {cleaned_next_image_url}" - ) else: cleaned_next_image_url = None - context["previous_page"] = previous_page - context["next_page"] = next_page - context["next_page_id"] = next_page_id - context["current_page"] = current_page - context["page_number"] = page_number - context["cleaned_url"] = cleaned_url - context["next_image_url"] = cleaned_next_image_url - context["all_pages"] = Document.objects.all().order_by("document_id") - context["fragments"] = self.object.fragment_set.order_by("line_number") + # Provide the forensic images if available + if current_document.attached_images.filter(image_type="forensics").exists(): + forensic_images = current_document.attached_images.filter( + image_type="forensics" + ) + else: + forensic_images = None + + context = { + "previous_page": previous_page, + "next_page": next_page, + "next_page_id": next_page_id, + "current_page": current_page, + "page_number": page_number, + "cleaned_url": cleaned_url, + "next_image_url": cleaned_next_image_url, + "all_pages": Document.objects.all().order_by("document_id"), + "fragments": self.object.fragment_set.order_by("line_number"), + "forensic_images": forensic_images, + } return context diff --git a/templates/forensics_partial.html b/templates/forensics_partial.html new file mode 100644 index 0000000..5ef4c99 --- /dev/null +++ b/templates/forensics_partial.html @@ -0,0 +1,9 @@ +
+ {% for image in forensic_images %} +
+ + Forensic Image + +
+ {% endfor %} +
\ No newline at end of file diff --git a/templates/manuscript.html b/templates/manuscript.html index cd764bd..d8f3858 100644 --- a/templates/manuscript.html +++ b/templates/manuscript.html @@ -24,32 +24,73 @@

The Manuscript.

{% if page_obj %}
- {% for document in page_obj %} - {% if is_first_page and forloop.first %} -
{# Empty element for the left side #} + {% if is_first_page %} +
{# Empty element for the left side #} + {% if page_obj|length > 0 %} +
+ {% with document=page_obj.0 %} + {% if document.attached_images.all %} + {% for image in document.attached_images.all %} + + Cover page {{document.page_range}} + +

+ {{ document.page_range }} ({{document.docside}}) +

+ {% endfor %} + {% else %} + {# Handle case where no images are attached #} +

No images available

+ {% endif %} + {% endwith %} +
{% endif %} -
- {% if document.attached_images.all %} - {% for image in document.attached_images.all %} - + {% for document in page_obj|slice:"1:" %} +
+ {% if document.attached_images.all %} + {% for image in document.attached_images.all %} + {% if image.image_type == "recto" or image.image_type == "verso" %} + + Manuscript page {{document.page_range}} + +

+ Page {{ document.page_range }} ({{document.docside}}) +

+ {% endif %} + {% endfor %} + {% else %} + {# Handle case where no images are attached #} +

No images available

+ {% endif %} +
+ {% endfor %} + {% else %} + {% for document in page_obj %} +
+ {% if document.attached_images.all %} + {% for image in document.attached_images.all %} {% if image.image_type == "recto" or image.image_type == "verso" %} Manuscript page {{document.page_range}} + alt="Manuscript page {{document.page_range}}" loading="lazy" />

Page {{ document.page_range }} ({{document.docside}})

{% endif %} - {% endfor %} - {% else %} - {# Handle case where no images are attached #} -

No images available

- {% endif %} -
- {% endfor %} + {% endfor %} + {% else %} + {# Handle case where no images are attached #} +

No images available

+ {% endif %} +
+ {% endfor %} + {% endif %}
{% endif %} +