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) 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): 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( diff --git a/denig/views.py b/denig/views.py index 8202900..d1e1567 100644 --- a/denig/views.py +++ b/denig/views.py @@ -191,21 +191,6 @@ def get_context_data(self, **kwargs): 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 = ( 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) 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 @@
by {{ post.specific.author }}
{% endif %} @@ -36,5 +39,4 @@