add feed image attribution to rss

This commit is contained in:
Trent Palmer 2021-07-16 13:34:47 -07:00
parent 70900bca6b
commit aa4951c430
2 changed files with 13 additions and 2 deletions

View File

@ -5,7 +5,7 @@ from django.utils.feedgenerator import Rss201rev2Feed
from tp.settings import IMAGES_URL, MP3_URL from tp.settings import IMAGES_URL, MP3_URL
from .models import Feed from .models import Feed
from datetime import datetime from datetime import datetime
from .rss_utils import get_rss_item_desc from .rss_utils import get_rss_item_desc, get_feed_image_desc
class AudioRssFeedGenerator(Rss201rev2Feed): class AudioRssFeedGenerator(Rss201rev2Feed):
@ -92,5 +92,5 @@ class AudioRssFeed(RSSFeed):
x['image_url'] = f'{IMAGES_URL}{obj.image.name}' x['image_url'] = f'{IMAGES_URL}{obj.image.name}'
x['image_title'] = obj.title x['image_title'] = obj.title
x['image_link'] = f'{get_current_site(obj.request)}{self.link(obj)}' x['image_link'] = f'{get_current_site(obj.request)}{self.link(obj)}'
x['image_desc'] = f'Image for: {obj.title}' x['image_desc'] = get_feed_image_desc(obj)
return x return x

View File

@ -1,6 +1,17 @@
from tp.settings import IMAGES_URL from tp.settings import IMAGES_URL
def get_feed_image_desc(feed):
d = f'<p>Photo <a href="{feed.original_image_url}">{feed.image_title}</a> by '
if feed.image_attribution_url == '':
e = f'{feed.image_attribution}'
else:
e = f'<a href="{feed.image_attribution_url}">{feed.image_attribution}</a>'
f = f' is licensed <a href="{feed.image_license_url}">{feed.image_license_name}</a>'
g = f' {feed.image_license_jurisdiction}.</p>'
return f'{d}{e}{f}{g}'
def get_rss_item_desc(item): def get_rss_item_desc(item):
a = f'<h1>{item}</h1>' a = f'<h1>{item}</h1>'
b = f'<img src="{IMAGES_URL}{item.image.name}">' b = f'<img src="{IMAGES_URL}{item.image.name}">'