From c14ccf7079c8d68473e80df9c20aaac735f69447 Mon Sep 17 00:00:00 2001
From: Tom Willemse
Date: Thu, 23 May 2013 00:35:46 +0200
Subject: Add the all category and show feeds on page
---
ryuslash/aggregator/models.py | 7 ++++--
ryuslash/aggregator/templates/aggregator/base.html | 9 +++++---
.../aggregator/templates/aggregator/posts.html | 13 +++++++++--
ryuslash/aggregator/views.py | 27 +++++++++++-----------
ryuslash/urls.py | 7 ++++--
5 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/ryuslash/aggregator/models.py b/ryuslash/aggregator/models.py
index 3ca7df2..9a39600 100644
--- a/ryuslash/aggregator/models.py
+++ b/ryuslash/aggregator/models.py
@@ -1,5 +1,7 @@
from django.db import models
+CATEGORIES = ['post', 'activity']
+
class Feed(models.Model):
name = models.CharField(max_length=300)
@@ -9,8 +11,9 @@ class Feed(models.Model):
uses_markdown = models.BooleanField()
uses_titles = models.BooleanField()
convert_newlines = models.BooleanField()
- category = models.SmallIntegerField(choices=((0, 'post'),
- (1, 'activity')))
+ category = models.SmallIntegerField(
+ choices=[(CATEGORIES.index(c), c) for c in CATEGORIES]
+ )
def __unicode__(self):
return self.name
diff --git a/ryuslash/aggregator/templates/aggregator/base.html b/ryuslash/aggregator/templates/aggregator/base.html
index 1b674aa..499e02a 100644
--- a/ryuslash/aggregator/templates/aggregator/base.html
+++ b/ryuslash/aggregator/templates/aggregator/base.html
@@ -16,13 +16,16 @@
diff --git a/ryuslash/aggregator/templates/aggregator/posts.html b/ryuslash/aggregator/templates/aggregator/posts.html
index 851a95e..0a97729 100644
--- a/ryuslash/aggregator/templates/aggregator/posts.html
+++ b/ryuslash/aggregator/templates/aggregator/posts.html
@@ -11,6 +11,15 @@
+
+ Feeds:
+ {% for feed in feeds %}
+
+ {{ feed.name }}
+
+ {% empty %}
+
None...
+ {% endfor %}
{% for post in list.object_list %}
@@ -44,7 +53,7 @@
{% if list.has_previous %}
-
-
+
Prev
@@ -54,7 +63,7 @@
{% if list.has_next %}
-
-
+
Next
diff --git a/ryuslash/aggregator/views.py b/ryuslash/aggregator/views.py
index e16be11..f621ae8 100644
--- a/ryuslash/aggregator/views.py
+++ b/ryuslash/aggregator/views.py
@@ -2,20 +2,19 @@ from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import Http404
from django.shortcuts import render
-from aggregator.models import Post
+from aggregator.models import CATEGORIES, Feed, Post
-def _get_category(cat):
- if cat == 'activity':
- return 1
- else:
- return 0
+def posts(request, cat=None, page=1):
+ category = cat or 'all'
+ posts = Post.objects.all()
+ feeds = Feed.objects.all()
+ if category != 'all':
+ posts = posts.filter(feed__category=CATEGORIES.index(category))
+ feeds = feeds.filter(category=CATEGORIES.index(category))
-def posts(request, cat, page=1):
- category = _get_category(cat)
- queryset = Post.objects.filter(feed__category=category)
- paginator = Paginator(queryset, 20)
+ paginator = Paginator(posts, 20)
if page is None:
page = 1
@@ -25,6 +24,8 @@ def posts(request, cat, page=1):
except (EmptyPage, InvalidPage):
raise Http404
- return render(request, 'aggregator/posts.html',
- {'list': object_list,
- 'category': category})
+ ctx = {'list': object_list,
+ 'category': category,
+ 'feeds': feeds}
+
+ return render(request, 'aggregator/posts.html', ctx)
diff --git a/ryuslash/urls.py b/ryuslash/urls.py
index a81f4c7..9224c64 100644
--- a/ryuslash/urls.py
+++ b/ryuslash/urls.py
@@ -7,9 +7,12 @@ from aggregator.feeds import LatestPostsFeed
admin.autodiscover()
urlpatterns = patterns(
- '',
+ 'aggregator.views',
+ url(r'^$', 'posts', name='index'),
+ url(r'^(?P\d+)/$', 'posts', name='index'),
url(r'^admin/', include(admin.site.urls)),
- url(r'^((?P[a-z_-]+)/)?((?P\d+)/)?$', 'aggregator.views.posts'),
+ url(r'^(?P[a-z_-]+)/$', 'posts', name='index'),
+ url(r'^(?P[a-z_-]+)/(?P\d+)/$', 'posts', name='index'),
url(r'^feed/posts/$', LatestPostsFeed()),
)
--
cgit v1.2.3-54-g00ecf