Added Image to RSS feed using Yahoo thumbnail standard
This commit is contained in:
parent
b9513e59af
commit
e835ea0c20
|
@ -1,7 +1,35 @@
|
|||
from django.contrib.syndication.views import Feed
|
||||
from django.urls import reverse
|
||||
from django.utils.feedgenerator import Rss201rev2Feed
|
||||
|
||||
from mhackspace.feeds.models import Article
|
||||
|
||||
|
||||
class MediaRssFeed(Rss201rev2Feed):
|
||||
"""
|
||||
Implement thumbnails which adhere to Yahoo Media RSS (mrss) feed.
|
||||
|
||||
@see http://djangosnippets.org/snippets/1648/
|
||||
"""
|
||||
def rss_attributes(self):
|
||||
attrs = super(MediaRssFeed, self).rss_attributes()
|
||||
attrs['xmlns:dc'] = "http://purl.org/dc/elements/1.1/"
|
||||
attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
|
||||
return attrs
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
super(MediaRssFeed, self).add_item_elements(handler, item)
|
||||
|
||||
thumbnail = {'url': item['thumbnail_url']}
|
||||
|
||||
if 'thumbnail_width' in item:
|
||||
thumbnail['width'] = str(item['thumbnail_width'])
|
||||
|
||||
if 'thumbnail_height' in item:
|
||||
thumbnail['height'] = str(item['thumbnail_height'])
|
||||
|
||||
handler.addQuickElement(u"media:thumbnail", '', thumbnail)
|
||||
|
||||
|
||||
class LatestEntriesFeed(Feed):
|
||||
title = "Maidstone hackspace site news"
|
||||
link = "/latest/"
|
||||
|
|
|
@ -1,38 +1,47 @@
|
|||
from django.contrib.syndication.views import Feed
|
||||
from django.utils import timezone
|
||||
|
||||
from mhackspace.base.feeds import MediaRssFeed
|
||||
from mhackspace.blog.models import Category, Post
|
||||
|
||||
|
||||
class BlogFeed(Feed):
|
||||
title = "Maidstone Hackspace Blog"
|
||||
link = "/blog/"
|
||||
feed_type = MediaRssFeed
|
||||
description = "The latest blog posts and news from the Maidstone Hackspace site"
|
||||
|
||||
def items(self, category):
|
||||
return Post.objects.select_related('author').filter(active=True, members_only=False, published_date__lte=timezone.now())[:20]
|
||||
|
||||
def item_title(self, item):
|
||||
return item.title
|
||||
def item_title(self, post):
|
||||
return post.title
|
||||
|
||||
def item_description(self, item):
|
||||
return item.description
|
||||
def item_description(self, post):
|
||||
return post.description
|
||||
|
||||
def item_author_name(self, item):
|
||||
return item.author.name
|
||||
def item_author_name(self, post):
|
||||
return post.author.name
|
||||
|
||||
def item_author_email(self, item):
|
||||
if item.author.public:
|
||||
return item.author.email
|
||||
def item_author_email(self, post):
|
||||
if post.author.public:
|
||||
return post.author.email
|
||||
|
||||
def item_categories(self, item):
|
||||
return item.categories.all()
|
||||
def item_categories(self, post):
|
||||
return post.categories.all()
|
||||
|
||||
def item_pubdate(self, item):
|
||||
return item.published_date
|
||||
def item_pubdate(self, post):
|
||||
return post.published_date
|
||||
|
||||
def item_updateddate(self, item):
|
||||
return item.updated_date
|
||||
def item_updateddate(self, post):
|
||||
return post.updated_date
|
||||
|
||||
def item_extra_kwargs(self, post):
|
||||
return {
|
||||
'thumbnail_url': post.image.full.url,
|
||||
'thumbnail_width': post.image.full.width,
|
||||
'thumbnail_height': post.image.full.height,
|
||||
}
|
||||
|
||||
|
||||
class BlogCategoryFeed(BlogFeed):
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.core.mail import EmailMessage
|
|||
from django.contrib import messages
|
||||
from mhackspace.contact.forms import ContactForm
|
||||
|
||||
# add to your views
|
||||
|
||||
def contact(request):
|
||||
form_class = ContactForm
|
||||
if request.method == 'POST':
|
||||
|
@ -15,14 +15,12 @@ def contact(request):
|
|||
data['message'],
|
||||
data['contact_email'],
|
||||
to=['contact@maidstone-hackspace.org.uk'],
|
||||
headers = {'Reply-To': data['contact_email']})
|
||||
headers={'Reply-To': data['contact_email']})
|
||||
email.send()
|
||||
messages.add_message(request, messages.INFO, 'E-Mail sent')
|
||||
else:
|
||||
form = form_class()
|
||||
|
||||
|
||||
return render(request, 'pages/contact.html', {
|
||||
'form': form,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue