From 1a05c6391c1cab084f44cc0b4e5970d57f6fcd42 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Fri, 26 Apr 2024 16:06:48 +1000 Subject: [PATCH] podjango: Upload icon per podcast --- conservancy/podjango/feeds.py | 10 +++++----- .../podjango/migrations/0006_podcast_icon.py | 18 ++++++++++++++++++ conservancy/podjango/models.py | 1 + ..._description.html => feed_description.html} | 0 .../podcast_title.html => feed_title.html} | 0 conservancy/urls.py | 10 +++++++++- requirements.txt | 1 + 7 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 conservancy/podjango/migrations/0006_podcast_icon.py rename conservancy/podjango/templates/podjango/{feeds/podcast_description.html => feed_description.html} (100%) rename conservancy/podjango/templates/podjango/{feeds/podcast_title.html => feed_title.html} (100%) diff --git a/conservancy/podjango/feeds.py b/conservancy/podjango/feeds.py index 1f75a40a..72fc1612 100644 --- a/conservancy/podjango/feeds.py +++ b/conservancy/podjango/feeds.py @@ -61,13 +61,13 @@ class CastFeedBase(Feed): def for_podcast_feed_extra_kwargs(self, obj): return { 'managingEditorNames': 'Bradley and Karen', - 'rssImage': {'url': 'https://sfconservancy.org/static/podjango/img/cast/tcs_300x300.jpg', - 'width': '144', 'height': '144'}, + 'rssImage': {'url': add_domain(self.current_site.domain, obj.icon.url, self.is_secure), + 'width': '300', 'height': '300'}, 'webMaster': 'oggcast@faif.us (Bradley and Karen)', 'dcCreator': 'oggcast@faif.us (Bradley and Karen)', 'iTunesExplicit': 'No', 'iTunesBlock': 'No', - 'iTunesImage': {'url': 'https://sfconservancy.org/static/podjango/img/cast/tcs_300x300.jpg', + 'iTunesImage': {'url': add_domain(self.current_site.domain, obj.icon.url, self.is_secure), 'title': 'The Corresponding Source (formerly Free as in Freedom)', 'link': self.author_link, 'type': 'video/jpg'}, @@ -192,8 +192,8 @@ class CastFeed(CastFeedBase): author_email = "podcast@faif.us" author_link = "https://sfconservancy.org/" author_name = "Software Freedom Conservancy" - title_template = "feeds/podcast_title.html" - description_template = "feeds/podcast_description.html" + title_template = "feed_title.html" + description_template = "feed_description.html" def get_feed(self, obj, request): # Enclosure (media) URLs don't automatically get the protocol and diff --git a/conservancy/podjango/migrations/0006_podcast_icon.py b/conservancy/podjango/migrations/0006_podcast_icon.py new file mode 100644 index 00000000..b7d76572 --- /dev/null +++ b/conservancy/podjango/migrations/0006_podcast_icon.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-26 01:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('podjango', '0005_podcast_long_description'), + ] + + operations = [ + migrations.AddField( + model_name='podcast', + name='icon', + field=models.ImageField(null=True, upload_to=''), + ), + ] diff --git a/conservancy/podjango/models.py b/conservancy/podjango/models.py index ad33cb2b..5a3d9752 100644 --- a/conservancy/podjango/models.py +++ b/conservancy/podjango/models.py @@ -27,6 +27,7 @@ class Podcast(models.Model): title = models.CharField(max_length=50) slug = models.SlugField(unique=True) long_description = models.TextField(blank=True) + icon = models.ImageField(null=True) def __str__(self): return self.title diff --git a/conservancy/podjango/templates/podjango/feeds/podcast_description.html b/conservancy/podjango/templates/podjango/feed_description.html similarity index 100% rename from conservancy/podjango/templates/podjango/feeds/podcast_description.html rename to conservancy/podjango/templates/podjango/feed_description.html diff --git a/conservancy/podjango/templates/podjango/feeds/podcast_title.html b/conservancy/podjango/templates/podjango/feed_title.html similarity index 100% rename from conservancy/podjango/templates/podjango/feeds/podcast_title.html rename to conservancy/podjango/templates/podjango/feed_title.html diff --git a/conservancy/urls.py b/conservancy/urls.py index 110fb723..0c0a8080 100644 --- a/conservancy/urls.py +++ b/conservancy/urls.py @@ -17,8 +17,10 @@ # along with this program in a file in the toplevel directory called # "AGPLv3". If not, see . -from django.urls import include, path, re_path +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin +from django.urls import include, path, re_path from . import feeds, frontpage, sponsors from .fundgoal import views as fundgoal_views @@ -59,3 +61,9 @@ urlpatterns = [ re_path(r'^projects/', static_views.index), re_path(r'^sustainer/', static_views.index), ] + +# Serve uploaded media. Works only when DEBUG == True. Using '/media/' +# explicitly here because MEDIA_URL include scheme/host/port, which would +# otherwise break debug media serving. +# https://docs.djangoproject.com/en/4.0/howto/static-files/#serving-files-uploaded-by-a-user-during-development +urlpatterns += static('/media/', document_root=settings.MEDIA_ROOT) diff --git a/requirements.txt b/requirements.txt index b5b1a073..a43fd3a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ Django==4.2.11 beautifulsoup4==4.11.2 html5lib==1.1 django-countries==7.3.2 +Pillow==9.4.0 \ No newline at end of file