Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

Commit

Permalink
filter rss feed by branch
Browse files Browse the repository at this point in the history
  • Loading branch information
anniejocain committed Mar 17, 2015
1 parent 69d5d84 commit be843cb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django/awesome/templates/landing_org_default.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2 class="subhead" {% if num_items > 0 and user.id == organization.user_id and
{% csrf_token %}<button class='btn btn-custom btn-xs' type='submit'>No thanks</button></form>" data-original-title="Seeing too many grey boxes?" {% endif %}>at the {{ organization.name }}</h2>
</div>
<div class="col-md-2 col-md-offset-2" id="feeds">
<a href="feed" target="_blank">
<a href="feed{% if branch %}/{{branch}}{%endif%}" target="_blank">
<img src="{{ STATIC_PREFIX }}images/rss-flat.png" class="rssIcon" alt="Awesome RSS" />
</a>
{% if twitter_username %}
Expand Down
2 changes: 1 addition & 1 deletion django/awesome/templates/landing_org_original.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<header id="branding">
<span id="feeds">
<a href="feed" target="_blank">
<a href="feed{% if branch %}/{{branch}}{%endif%}" target="_blank">
<img src="{{ STATIC_PREFIX }}images/rss.png" class="rssIcon" alt="Awesome RSS" />
</a>
{% if twitter_username %}
Expand Down
3 changes: 2 additions & 1 deletion django/awesome/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf.urls.defaults import patterns, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib.auth import views as auth_views
from awesome.views.feed import LatestEntriesFeed
from awesome.views.feed import LatestEntriesFeed, BranchLatestEntriesFeed


admin.autodiscover()
Expand All @@ -15,6 +15,7 @@
url(r'^discover/$', 'landing.discover', name='landing_discover'),
url(r'^scan/$', 'scan.scan', name='scan'),
url(r'^feed/$', LatestEntriesFeed()),
url(r'^feed/(?P<branch_slug>[0-9A-Za-z:]+)/$', BranchLatestEntriesFeed()),
url(r'^widget/$', 'widget.widget', name='widget'),
url(r'^catalog-include/(?P<isbn>[0-9A-Za-z:]+)$', 'widget.catalog_include', name='widget_catalog_include'),
url(r'^control/$', 'control.home', name='control_home'),
Expand Down
56 changes: 55 additions & 1 deletion django/awesome/views/feed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import logging

from django.contrib.syndication.views import Feed
from awesome.models import Organization, Item
from awesome.models import Organization, Item, Branch

from django.shortcuts import get_object_or_404

from django.http import HttpRequest

logger = logging.getLogger(__name__)

class LatestEntriesFeed(Feed):

def get_object(self, request):
Expand Down Expand Up @@ -43,6 +47,56 @@ def item_description(self, item):
else:
return item.title + ' by' + item.creator

# item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
library = get_object_or_404(Organization, slug=item.slug)
value = ''
if library.catalog_query == 'isbn':
value = item.catalog_id
elif library.catalog_query == 'title':
value = item.title
elif library.catalog_query == 'titleauthor':
value = item.title + '+' + item.creator
elif library.catalog_query == 'landing' or library.catalog_query == 'notset':
value = ''
return library.catalog_base_url + value


class BranchLatestEntriesFeed(Feed):

def get_object(self, request, branch_slug):
return Branch.objects.get(organization__slug=request.META['subdomain'], slug=branch_slug)

def link(self, obj):
return 'http://' + obj.organization.slug + '.awesomebox.io'

def title(self, obj):
return 'Recently Awesome at ' + obj.organization.name + ' ' + obj.name + ' branch'

def description(self, obj):
return 'Keep up with the latest awesome items at ' + obj.organization.name + ' ' + obj.name + ' branch'

def link(self, obj):
return 'http://' + obj.organization.slug + '.awesomebox.io/'

def items(self, obj):
result = Item.objects.filter(branch=obj.id).order_by('-latest_checkin')[:15]
for entry in result:
entry.slug = obj.organization.slug
return result

def item_title(self, item):
return item.title

def item_description(self, item):
if item.cover_art:
return '<img class="item-cover" src="' + item.cover_art + '" />' + item.title + ' by ' + item.creator
else:
if item.isbn:
return '<img src="http://covers.openlibrary.org/b/isbn/' + item.isbn + '-M.jpg" />' + item.title + ' by ' + item.creator
else:
return item.title + ' by' + item.creator

# item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
library = get_object_or_404(Organization, slug=item.slug)
Expand Down

0 comments on commit be843cb

Please sign in to comment.