diff options
author | Tom Willemse | 2013-05-23 00:35:46 +0200 |
---|---|---|
committer | Tom Willemse | 2013-05-23 00:39:41 +0200 |
commit | c14ccf7079c8d68473e80df9c20aaac735f69447 (patch) | |
tree | ba2f807fd16aa606d5e624b33ae065d96ffb426d | |
parent | 91283adebd1531fc7e676fcd29734b46a989525f (diff) | |
download | ryuslash.org-c14ccf7079c8d68473e80df9c20aaac735f69447.tar.gz ryuslash.org-c14ccf7079c8d68473e80df9c20aaac735f69447.zip |
Add the all category and show feeds on page
-rw-r--r-- | ryuslash/aggregator/models.py | 7 | ||||
-rw-r--r-- | ryuslash/aggregator/templates/aggregator/base.html | 9 | ||||
-rw-r--r-- | ryuslash/aggregator/templates/aggregator/posts.html | 13 | ||||
-rw-r--r-- | ryuslash/aggregator/views.py | 27 | ||||
-rw-r--r-- | 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 @@ <div class="container"> <img class="pull-left" src="/static/logo.png" alt="ryuslash.org" title="ryuslash.org" /> - <a class="brand" href="http://ryuslash.org">ryuslash</a> + <a class="brand" href="{% url 'index' %}">ryuslash</a> <ul class="nav pull-right"> + <li {% if category == 'all' %}class="active"{%endif%}> + <a href="{% url 'index' %}">all</a> + </li> <li {% if category == 'post' %}class="active"{% endif %}> - <a href="/post/">posts</a> + <a href="{% url 'index' cat='post' %}">posts</a> </li> <li {% if category == 'activity' %}class="active"{% endif %}> - <a href="/activity/">activities</a> + <a href="{% url 'index' cat='activity' %}">activities</a> </li> </ul> </div> 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 @@ <div class="span3"> <img src="https://secure.gravatar.com/avatar/d3af11dc82b44c4f78517c2036271d5c?s=210" /> <br /> + <br /> + Feeds: + {% for feed in feeds %} + <a href="{{ feed.base_url }}" class="btn btn-block"> + {{ feed.name }} + </a> + {% empty %} + <br />None... + {% endfor %} </div> <div class="span9"> {% for post in list.object_list %} @@ -44,7 +53,7 @@ <ul> {% if list.has_previous %} <li> - <a href="/{{ category }}/{{ list.previous_page_number }}/"> + <a href="{% url 'index' cat=category page=list.previous_page_number %}"> Prev </a> </li> @@ -54,7 +63,7 @@ {% if list.has_next %} <li> - <a href="/{{ category }}/{{ list.next_page_number }}"> + <a href="{% url 'index' cat=category page=list.next_page_number %}"> Next </a> </li> 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<page>\d+)/$', 'posts', name='index'), url(r'^admin/', include(admin.site.urls)), - url(r'^((?P<cat>[a-z_-]+)/)?((?P<page>\d+)/)?$', 'aggregator.views.posts'), + url(r'^(?P<cat>[a-z_-]+)/$', 'posts', name='index'), + url(r'^(?P<cat>[a-z_-]+)/(?P<page>\d+)/$', 'posts', name='index'), url(r'^feed/posts/$', LatestPostsFeed()), ) |