From d12b57cf57347d84a2c34fe2bce0634ff26e1259 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:22:02 -0500 Subject: [PATCH 01/10] refactor: Rearrange URL patterns for Wagtail --- config/urls.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/urls.py b/config/urls.py index 6058028..b13fb0e 100644 --- a/config/urls.py +++ b/config/urls.py @@ -9,9 +9,10 @@ urlpatterns = [ path("", include("denig.urls")), path("admin/", admin.site.urls), - path("cms/", include(wagtailadmin_urls)), - path("essays/", include(wagtail_urls)), path("accounts/", include("authuser.urls")), path("prose/", include("prose.urls")), path("__debug__/", include("debug_toolbar.urls")), + # Wagtial URLs + path("cms/", include(wagtailadmin_urls)), + path("essays/", include(wagtail_urls)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From 066398ab3386d1e9dd179a4a3c615dfc7e91df60 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:22:42 -0500 Subject: [PATCH 02/10] refactor: Update get_absolute_url() to use "manuscript_page" instead of "document" --- denig/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/denig/models.py b/denig/models.py index b1d940c..d88c2c9 100644 --- a/denig/models.py +++ b/denig/models.py @@ -338,8 +338,7 @@ def alphabetize_tags(self): def get_absolute_url(self): """Return the URL for this document.""" - """changed from return reverse("document", args=[str(self.id)]) """ - return reverse("document", kwargs={"slug": self.slug}) + return reverse("manuscript_page", kwargs={"slug": self.slug}) @property def permalink(self): From 3a6a35115240c816bed8161523f4aa6410f0d6f6 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:23:04 -0500 Subject: [PATCH 03/10] refactor: Remove old forensics page --- denig/urls.py | 1 - 1 file changed, 1 deletion(-) diff --git a/denig/urls.py b/denig/urls.py index 549e068..9ccb6c0 100644 --- a/denig/urls.py +++ b/denig/urls.py @@ -5,7 +5,6 @@ urlpatterns = [ path("", views.index, name="index"), path("about/", views.about, name="about"), - path("forensics/", views.ForensicsListView.as_view(), name="forensics"), path("music/", views.MusicListView.as_view(), name="music"), path("manuscript/", views.DocumentListView.as_view(), name="manuscript"), path( From 2da7dc6429cbd5f277b9e39f982c92389eaad38f Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:23:41 -0500 Subject: [PATCH 04/10] refactor: Remove old forensic images code in DocumentDetailView --- denig/views.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/denig/views.py b/denig/views.py index 8202900..cb03f6b 100644 --- a/denig/views.py +++ b/denig/views.py @@ -165,14 +165,6 @@ def get_context_data(self, **kwargs): else: cleaned_next_image_url = None - # 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.update( { "previous_page": previous_page, @@ -184,28 +176,12 @@ def get_context_data(self, **kwargs): "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 -class ForensicsListView(generic.View): - def get(self, request, *args, **kwargs): - image_list = Image.objects.filter(image_type="forensics").order_by("id") - document_list = ( - Document.objects.filter(attached_images__image_type="forensics") - .order_by("id") - .distinct() - ) - return render( - request, - "forensics.html", - {"image_list": image_list, "document_list": document_list}, - ) - - class MusicListView(generic.View): def get(self, request, *args, **kwargs): hymnal_list = ( From 6c2ea961f432d524db991720e1ee113379c1ebf1 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:27:28 -0500 Subject: [PATCH 05/10] refactor: Remove old forensic images code in DocumentDetailView --- denig/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/denig/views.py b/denig/views.py index cb03f6b..d1e1567 100644 --- a/denig/views.py +++ b/denig/views.py @@ -165,6 +165,14 @@ def get_context_data(self, **kwargs): else: cleaned_next_image_url = None + # 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.update( { "previous_page": previous_page, @@ -176,6 +184,7 @@ def get_context_data(self, **kwargs): "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, } ) From 08ccc2f70c25e2150fc27355f08bb63c75a67679 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:28:00 -0500 Subject: [PATCH 06/10] refactor: Update ForensicPage model and add DocumentChooserPanel and GalleryImage --- .../0022_forensicpage_galleryimage.py | 90 +++++++++++++++++++ ...icpage_related_manuscript_page_and_more.py | 38 ++++++++ essays/models.py | 56 +++++++++++- 3 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 essays/migrations/0022_forensicpage_galleryimage.py create mode 100644 essays/migrations/0023_forensicpage_related_manuscript_page_and_more.py diff --git a/essays/migrations/0022_forensicpage_galleryimage.py b/essays/migrations/0022_forensicpage_galleryimage.py new file mode 100644 index 0000000..35887fe --- /dev/null +++ b/essays/migrations/0022_forensicpage_galleryimage.py @@ -0,0 +1,90 @@ +# Generated by Django 4.2.13 on 2024-10-17 20:41 + +import django.db.models.deletion +import modelcluster.fields +import wagtail.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("wagtailcore", "0093_uploadedfile"), + ("wagtailimages", "0026_delete_uploadedimage"), + ("essays", "0021_essaypage_preview_image"), + ] + + operations = [ + migrations.CreateModel( + name="ForensicPage", + fields=[ + ( + "page_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="wagtailcore.page", + ), + ), + ("body", wagtail.fields.RichTextField(blank=True)), + ("link_to_manuscript_page", models.URLField(blank=True)), + ( + "preview_image", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="wagtailimages.image", + ), + ), + ], + options={ + "abstract": False, + }, + bases=("wagtailcore.page",), + ), + migrations.CreateModel( + name="GalleryImage", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ("caption", models.CharField(blank=True, max_length=250)), + ( + "image", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="wagtailimages.image", + ), + ), + ( + "page", + modelcluster.fields.ParentalKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="gallery_images", + to="essays.forensicpage", + ), + ), + ], + options={ + "ordering": ["sort_order"], + "abstract": False, + }, + ), + ] diff --git a/essays/migrations/0023_forensicpage_related_manuscript_page_and_more.py b/essays/migrations/0023_forensicpage_related_manuscript_page_and_more.py new file mode 100644 index 0000000..cbcb500 --- /dev/null +++ b/essays/migrations/0023_forensicpage_related_manuscript_page_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.13 on 2024-10-18 14:23 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("denig", "0043_alter_image_caption"), + ("wagtailimages", "0026_delete_uploadedimage"), + ("essays", "0022_forensicpage_galleryimage"), + ] + + operations = [ + migrations.AddField( + model_name="forensicpage", + name="related_manuscript_page", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="denig.document", + ), + ), + migrations.AlterField( + model_name="forensicpage", + name="preview_image", + field=models.ForeignKey( + blank=True, + help_text="If no preview image is provided, the first image in the gallery will be used.", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="wagtailimages.image", + ), + ), + ] diff --git a/essays/models.py b/essays/models.py index 52dcf5b..743737a 100644 --- a/essays/models.py +++ b/essays/models.py @@ -5,11 +5,63 @@ from modelcluster.fields import ParentalKey from prose.models import Document from taggit_selectize.managers import TaggableManager -from wagtail.admin.panels import FieldPanel -from wagtail.fields import RichTextField +from wagtail.admin.panels import FieldPanel, InlinePanel, PageChooserPanel +from wagtail.fields import RichTextField, StreamField +from wagtail.images.blocks import ImageChooserBlock from wagtail.models import Orderable, Page from wagtail.search import index +from denig.models import Document + + +class OrderedDocumentChooserPanel(PageChooserPanel): + def get_form_class(self): + form_class = super().get_form_class() + form_class.base_fields[self.field_name].queryset = Document.objects.order_by( + "document_id" + ) + return form_class + + +class GalleryImage(Orderable): + page = ParentalKey("ForensicPage", related_name="gallery_images") + image = models.ForeignKey( + "wagtailimages.Image", + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name="+", + ) + caption = models.CharField(blank=True, max_length=250) + + panels = [ + FieldPanel("image"), + FieldPanel("caption"), + ] + + +class ForensicPage(Page): + body = RichTextField(blank=True) + preview_image = models.ForeignKey( + "wagtailimages.Image", + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name="+", + help_text="If no preview image is provided, the first image in the gallery will be used.", + ) + link_to_manuscript_page = models.URLField(blank=True) + related_manuscript_page = models.ForeignKey( + Document, null=True, blank=True, on_delete=models.SET_NULL, related_name="+" + ) + + content_panels = Page.content_panels + [ + FieldPanel("body"), + FieldPanel("preview_image"), + OrderedDocumentChooserPanel("related_manuscript_page"), + InlinePanel("gallery_images", label="Gallery images"), + ] + class EssayIndexPage(Page): intro = RichTextField(blank=True) From 62c8f7caa8f927d0bc610d2f49b95e9f7dfad20b Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:28:13 -0500 Subject: [PATCH 07/10] refactor: Update essay_index_page.html to display gallery image if available --- essays/templates/essays/essay_index_page.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/essays/templates/essays/essay_index_page.html b/essays/templates/essays/essay_index_page.html index d9f19a9..48c1fa9 100644 --- a/essays/templates/essays/essay_index_page.html +++ b/essays/templates/essays/essay_index_page.html @@ -20,10 +20,13 @@

{{ page.title }}.

{% image post.specific.preview_image width-400 %}
+ {% else %} +
+ {% image post.specific.gallery_images.first.image width-400 %} +
{% endif %}
-

{{ post.title }}

+

{{ post.title }}

{% if post.specific.author %}

by {{ post.specific.author }}

{% endif %} @@ -36,5 +39,4 @@

- -{% endblock content %} \ No newline at end of file +{% endblock content %} From ef9cabb95aed8f836dcb86b94569f5c97890b01b Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:28:34 -0500 Subject: [PATCH 08/10] feat: forensic_page.html for Wagtail forensic images --- essays/templates/essays/forensic_page.html | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 essays/templates/essays/forensic_page.html diff --git a/essays/templates/essays/forensic_page.html b/essays/templates/essays/forensic_page.html new file mode 100644 index 0000000..2665a95 --- /dev/null +++ b/essays/templates/essays/forensic_page.html @@ -0,0 +1,73 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags %} +{% load wagtailimages_tags %} + +{% block body_class %}essay-page top{% endblock %} + +{% block content %} +
+ +
+

{{ page.title }}

+
+ +
+ + {% if page.intro %} +
{{ page.intro }}
+ {% endif %} + + {{ page.body|richtext }} + {% if page.related_manuscript_page %} +
← + View manuscript page + · Click an image below to view a larger version. + {% endif %} + + + {% if page.gallery_images %} +
+ {% for item in page.gallery_images.all %} + {% image item.image width-1200 as large_img %} +
+ {% image item.image fill-400x300 as img %} + {{ item.image.title }} +
+ {% endfor %} +
+ {% endif %} + +
+ + +
+
+ +
+ Large version +
+
+

+
+
+
+
+{% endblock %} \ No newline at end of file From bf61ff5a95b0fec4ee1b33789f52fa67b29c0f7a Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:28:56 -0500 Subject: [PATCH 09/10] refactor: Update URL for the new forensic images page --- templates/base.html | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/templates/base.html b/templates/base.html index 20edb81..4f18659 100644 --- a/templates/base.html +++ b/templates/base.html @@ -64,7 +64,7 @@ class="text-gray-300 hover:bg-winterthur-dk-blue hover:text-white px-3 py-2 rounded-md text-sm font-medium">Manuscript Scholarship - Forensics Music @@ -84,7 +84,7 @@ class="text-gray-300 hover:bg-winterthur-dk-blue hover:text-white px-3 py-2 rounded-md text-sm font-medium">Manuscript Scholarship - Forensics Music @@ -101,28 +101,31 @@
-
-
- +
+ + Winterthur Library, Museum and Garden - - - - +
+ + + +
+ + Roy Rosenzweig Center for History and New Media
-
- +
{% include 'partials/citation.html' %} -
-
-
- + + \ No newline at end of file From 9795e84011c4ddc6fe955ffaf98f750a268d714f Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 18 Oct 2024 10:29:16 -0500 Subject: [PATCH 10/10] chore: Linting citation.html formatting and URL --- templates/partials/citation.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/templates/partials/citation.html b/templates/partials/citation.html index fef9a67..bbc2c9f 100644 --- a/templates/partials/citation.html +++ b/templates/partials/citation.html @@ -1,7 +1,5 @@

- The Denig Manuscript, Winterthur Museum, Garden & Library and the Roy - Rosenzweig Center for History and New Media (2024). - https://dev.winterthur.rrchnm.org -

+ The Denig Manuscript, Winterthur Museum, Garden & Library and the Roy Rosenzweig Center for History and New + Media (2024). https://dev.winterthur.rrchnm.org +

\ No newline at end of file