diff --git a/requirements.txt b/requirements.txt index 6ef90a1..97207da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ beautifulsoup4==4.9.3 lxml==4.9.0 more-itertools==8.13.0 requests==2.27.1 +wagtail-generic-chooser==0.4.1 diff --git a/website/blog/migrations/0010_bloglistpage_hero_unsplash_photo_and_more.py b/website/blog/migrations/0010_bloglistpage_hero_unsplash_photo_and_more.py new file mode 100644 index 0000000..6e03bda --- /dev/null +++ b/website/blog/migrations/0010_bloglistpage_hero_unsplash_photo_and_more.py @@ -0,0 +1,35 @@ +# Generated by Django 4.0.5 on 2022-07-12 13:04 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("unsplash", "0001_initial"), + ("blog", "0009_alter_bloglistpage_body_alter_blogpostpage_body"), + ] + + operations = [ + migrations.AddField( + model_name="bloglistpage", + name="hero_unsplash_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="unsplash.unsplashphoto", + ), + ), + migrations.AddField( + model_name="blogpostpage", + name="hero_unsplash_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="unsplash.unsplashphoto", + ), + ), + ] diff --git a/website/common/migrations/0011_contentpage_hero_unsplash_photo_and_more.py b/website/common/migrations/0011_contentpage_hero_unsplash_photo_and_more.py new file mode 100644 index 0000000..9f45e66 --- /dev/null +++ b/website/common/migrations/0011_contentpage_hero_unsplash_photo_and_more.py @@ -0,0 +1,35 @@ +# Generated by Django 4.0.5 on 2022-07-12 13:04 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("unsplash", "0001_initial"), + ("common", "0010_alter_contentpage_body_alter_listingpage_body"), + ] + + operations = [ + migrations.AddField( + model_name="contentpage", + name="hero_unsplash_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="unsplash.unsplashphoto", + ), + ), + migrations.AddField( + model_name="listingpage", + name="hero_unsplash_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="unsplash.unsplashphoto", + ), + ), + ] diff --git a/website/common/models.py b/website/common/models.py index d9ffb95..722e005 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -10,6 +10,7 @@ from wagtail.images import get_image_model_string from wagtail.models import Page from website.common.utils import count_words +from website.contrib.unsplash.widgets import UnsplashPhotoChooser from .streamfield import add_heading_anchors, get_blocks, get_content_html from .utils import TocEntry, extract_text, get_table_of_contents, truncate_string @@ -39,11 +40,15 @@ class BaseContentMixin(models.Model): hero_image = models.ForeignKey( get_image_model_string(), null=True, blank=True, on_delete=models.SET_NULL ) + hero_unsplash_photo = models.ForeignKey( + "unsplash.UnsplashPhoto", null=True, blank=True, on_delete=models.SET_NULL + ) body = StreamField(get_blocks(), blank=True, use_json_field=True) content_panels = [ FieldPanel("subtitle"), FieldPanel("hero_image"), + FieldPanel("hero_unsplash_photo", widget=UnsplashPhotoChooser), FieldPanel("body"), ] diff --git a/website/contrib/unsplash/models.py b/website/contrib/unsplash/models.py index fb3c4fc..c1d725a 100644 --- a/website/contrib/unsplash/models.py +++ b/website/contrib/unsplash/models.py @@ -4,3 +4,6 @@ from django.db import models class UnsplashPhoto(models.Model): unsplash_id = models.CharField(unique=True, max_length=11, db_index=True) data = models.JSONField() + + def get_description(self) -> str: + return self.data["description"] diff --git a/website/contrib/unsplash/templates/unsplash/results.html b/website/contrib/unsplash/templates/unsplash/results.html new file mode 100644 index 0000000..71f9f66 --- /dev/null +++ b/website/contrib/unsplash/templates/unsplash/results.html @@ -0,0 +1,31 @@ +{# Adapted from generic_chooser/_results.html #} + +{% load i18n %} + +
{% trans "Unsplash ID" %} | +{% trans "Description" %} | +
---|---|
+ {{ row.item.unsplash_id }}+ |
+ + {{ row.item.get_description }} + | +