Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Got author urls working.
Browse files Browse the repository at this point in the history
  • Loading branch information
myles committed Jan 21, 2013
1 parent c955e82 commit 79bf24d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
21 changes: 11 additions & 10 deletions blog/templates/blog/author/detail.html
Expand Up @@ -8,28 +8,29 @@ <h2>Blog posts <a href="{% url blog_authors_list %}">written</a> by {% if author

{% block content %}
<div id="blog_posts">
{% for post in posts.object_list %}{% include "blog/_post.html" %}{% endfor %}
{% for post in post_list %}{% include "blog/_post.html" %}{% endfor %}
</div>

{% if posts.has_other_pages %}
{% if page_obj.has_other_pages %}
<ul id="pagination">
{% if posts.has_previous %}
<li class="previous on"><a href="{% url blog_categories_detail_paginated category.slug posts.previous_page_number %}" title="Page {{ posts.previous_page_number }}">Previous</a></li>
{% if page_obj.has_previous %}
<li class="previous on"><a href="{% url blog_authors_detail_paginated author.username page_obj.previous_page_number %}" title="Page {{ page_obj.previous_page_number }}">Previous</a></li>
{% else %}
<li class="previous off">Previous</li>
{% endif %}
{% for page in posts.page_range %}
{% ifequal page posts.page_number %}
{% for page in page_obj.page_range %}
{% ifequal page page_obj.page_number %}
<li class="active">{{ page }}</li>
{% else %}
<li><a href="{% url blog_categories_detail_paginated category.slug page %}">{{ page }}</a></li>
<li><a href="{% url blog_authors_detail_paginated author.username page %}">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if posts.has_next %}
<li class="next on"><a href="{% url blog_categories_detail_paginated category.slug posts.next_page_number %}" title="Page {{ posts.next_page_number }}">Next</a></li>
{% if page_obj.has_next %}
<li class="next on"><a href="{% url blog_authors_detail_paginated author.username page_obj.next_page_number %}" title="Page {{ page_obj.next_page_number }}">Next</a></li>
{% else %}
<li class="next off">Next</li>
{% endif %}
</ul>
{% endif %}
{% endblock %}
{% endblock %}

12 changes: 12 additions & 0 deletions blog/urls.py
Expand Up @@ -91,6 +91,18 @@
view = feeds.BlogAuthorPostFeed(),
name = 'blog_author_post_feed'
),
url(r'^author/(?P<username>[-\w]+)/page/(?P<page>\d+)/$',
view = views.BlogPostAuthorDetailView.as_view(),
name = 'blog_authors_detail_paginated',
),
url(r'^author/(?P<username>[-\w]+)/$',
view = views.BlogPostAuthorDetailView.as_view(),
name = 'blog_authors_detail',
),
url(r'^author/$',
view = views.BlogPostAuthorListView.as_view(),
name = 'blog_authors_list'
),

#
# Index
Expand Down
3 changes: 3 additions & 0 deletions blog/views/__init__.py
Expand Up @@ -7,6 +7,7 @@
from blog.views.category import BlogCategoryDetailView, BlogCategoryListView
from blog.views.archive import BlogPostYearArchiveView, BlogPostMonthArchiveView, BlogPostWeekArchiveView, BlogPostWeekDayArchiveView, BlogPostDayArchiveView, BlogPostUpdatedArchiveView, BlogPostArchiveView
from blog.views.search import BlogPostSearchFormListView
from blog.views.author import BlogPostAuthorListView, BlogPostAuthorDetailView

__all__ = [
'BlogPostListView',
Expand All @@ -21,6 +22,8 @@
'BlogPostUpdatedArchiveView',
'BlogPostArchiveView',
'BlogPostSearchFormListView',
'BlogPostAuthorListView',
'BlogPostAuthorDetailView'
]

class BlogPostListView(ListView):
Expand Down
28 changes: 28 additions & 0 deletions blog/views/author.py
@@ -0,0 +1,28 @@
from django.views.generic import ListView
from django.contrib.auth.models import User

from blog.models import Post
from blog.settings import BLOG_PAGINATE_BY

class BlogPostAuthorListView(ListView):

context_object_name = "authors"
template_name = "blog/author/list.html"

def get_queryset(self):
return User.objects.filter(is_staff=True)

class BlogPostAuthorDetailView(ListView):

context_object_name = "post_list"
template_name = "blog/author/detail.html"
paginate_by = BLOG_PAGINATE_BY

def get_context_data(self, **kwargs):
context = super(BlogPostAuthorDetailView, self).get_context_data(**kwargs)
context['author'] = self.author
return context

def get_queryset(self):
self.author = User.objects.get(username__iexact=self.kwargs['username'])
return Post.objects.published(author=self.author)

0 comments on commit 79bf24d

Please sign in to comment.