mirror of
https://github.com/pinry/pinry.git
synced 2025-11-18 10:50:38 +01:00
Adding rss feed for latest pins.
This commit is contained in:
55
pinry/core/feeds.py
Normal file
55
pinry/core/feeds.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.contrib.syndication.views import Feed
|
||||||
|
from django.contrib.sites.models import get_current_site
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
from django_images.models import Thumbnail
|
||||||
|
|
||||||
|
from .models import Pin
|
||||||
|
|
||||||
|
|
||||||
|
def filter_generator_for(size):
|
||||||
|
def wrapped_func(obj):
|
||||||
|
return Thumbnail.objects.get_or_create_at_size(obj.pk, size)
|
||||||
|
return wrapped_func
|
||||||
|
|
||||||
|
|
||||||
|
class LatestPins(Feed):
|
||||||
|
title = 'Latest Pins'
|
||||||
|
link = '/'
|
||||||
|
description = 'The latest pins from around the internet.'
|
||||||
|
|
||||||
|
domain_name = None
|
||||||
|
item_enclosure_mime_type = 'image/jpeg'
|
||||||
|
|
||||||
|
def get_object(self, request):
|
||||||
|
"""
|
||||||
|
Doing this as a fix for Django's not including the domain name in enclosure urls.
|
||||||
|
"""
|
||||||
|
request_type = 'http'
|
||||||
|
if request.is_secure(): request_type = 'https'
|
||||||
|
self.domain_name = ''.join([request_type, '://', get_current_site(request).domain])
|
||||||
|
return get_object_or_404(Pin)
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Pin.objects.order_by('-published')[:15]
|
||||||
|
|
||||||
|
def item_pubdate(self, item):
|
||||||
|
return item.published
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return item.url
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.url
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
tags = ', '.join(tag.name for tag in item.tags.all())
|
||||||
|
return ''.join(['Description: ', item.description or 'None', ' | Tags: ', tags or 'None'])
|
||||||
|
|
||||||
|
def item_enclosure_url(self, item):
|
||||||
|
return self.domain_name + unicode(filter_generator_for('standard')(item.image).image.url)
|
||||||
|
|
||||||
|
def item_enclosure_length(self, item):
|
||||||
|
return filter_generator_for('standard')(item.image).image.size
|
||||||
@@ -4,6 +4,7 @@ from django.views.generic import TemplateView
|
|||||||
from tastypie.api import Api
|
from tastypie.api import Api
|
||||||
|
|
||||||
from .api import ImageResource, ThumbnailResource, PinResource, UserResource
|
from .api import ImageResource, ThumbnailResource, PinResource, UserResource
|
||||||
|
from .feeds import LatestPins
|
||||||
from .views import CreateImage
|
from .views import CreateImage
|
||||||
|
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ v1_api.register(UserResource())
|
|||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^api/', include(v1_api.urls, namespace='api')),
|
url(r'^api/', include(v1_api.urls, namespace='api')),
|
||||||
|
|
||||||
|
url(r'feeds/latest-pins/', LatestPins()),
|
||||||
|
|
||||||
url(r'^pins/pin-form/$', TemplateView.as_view(template_name='core/pin_form.html'),
|
url(r'^pins/pin-form/$', TemplateView.as_view(template_name='core/pin_form.html'),
|
||||||
name='pin-form'),
|
name='pin-form'),
|
||||||
url(r'^pins/create-image/$', CreateImage.as_view(), name='create-image'),
|
url(r'^pins/create-image/$', CreateImage.as_view(), name='create-image'),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
|
||||||
|
<link rel="alternate" type="application/rss+xml" href="/feeds/latest-pins/" />
|
||||||
|
|
||||||
<!-- ___ ___ ___
|
<!-- ___ ___ ___
|
||||||
/ /\ ___ /__/\ / /\ ___
|
/ /\ ___ /__/\ / /\ ___
|
||||||
|
|||||||
Reference in New Issue
Block a user