]> git.sommitrealweird.co.uk Git - sommitrealweird.git/commitdiff
Blog enhancements
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 29 Mar 2009 12:05:43 +0000 (13:05 +0100)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 29 Mar 2009 12:05:43 +0000 (13:05 +0100)
sommitrealweird/blog/feeds.py
sommitrealweird/blog/templates/blog/blog_index.html
sommitrealweird/blog/urls.py
sommitrealweird/blog/views.py

index d08456f1564ea3aaf98368a119f050ab9851f521..be04190f7b07d19f52b3d8699895cb82ffe864e5 100644 (file)
@@ -18,5 +18,11 @@ class LatestBlogEntries(Feed):
         except:
             return BlogEntry.objects.all().order_by('-publish_date')
 
         except:
             return BlogEntry.objects.all().order_by('-publish_date')
 
+    def author_name(self, obj):
+        return "Brett Parker"
+
+    def author_email(self, obj):
+        return "iDunno@sommitrealweird.co.uk"
+
     def item_pubdate(self, obj):
         return obj.publish_date
     def item_pubdate(self, obj):
         return obj.publish_date
index e43cc647ac523eea114abaeacc4678e49c8b2159..395c8e83d9d67db0a8a7c3a5c211dba1e888e841 100644 (file)
@@ -20,7 +20,7 @@
                 {% endfor %}
                 <a href="{{ entry.get_absolute_url }}">permalink</a></p>
         {% endfor %}
                 {% endfor %}
                 <a href="{{ entry.get_absolute_url }}">permalink</a></p>
         {% endfor %}
-        {% if paginated %}
+        {% if paginated and has_more_than_one_page %}
             <p class="paginator">Pages: 
             {% if has_prev %}
                 <a href="?page={{ prev }}">Previous</a> |
             <p class="paginator">Pages: 
             {% if has_prev %}
                 <a href="?page={{ prev }}">Previous</a> |
index f41ed25632470d3624692dbce6c7e8c645ce8265..2ec24bd5da34fa2c9dc9103a25e5e07d47e43ee5 100644 (file)
@@ -5,6 +5,9 @@ urlpatterns = patterns('',
     (r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<slug>[^/]+)(/|)$', 'blog.views.blog_view'),
     (r'^(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})-(?P<slug>[^/]+)\.html$', 'blog.views.blog_view'),
     (r'^(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})(?P<hour>[0-9]{2})(?P<minutes>[0-9]{2})-(?P<slug>[^/]+)\.html$', 'blog.views.blog_view'),
     (r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<slug>[^/]+)(/|)$', 'blog.views.blog_view'),
     (r'^(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})-(?P<slug>[^/]+)\.html$', 'blog.views.blog_view'),
     (r'^(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})(?P<hour>[0-9]{2})(?P<minutes>[0-9]{2})-(?P<slug>[^/]+)\.html$', 'blog.views.blog_view'),
+    (r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', 'blog.views.blog_view'),
+    (r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', 'blog.views.blog_view'),
+    (r'^(?P<year>[0-9]{4})/$', 'blog.views.blog_view'),
     (r'^section/(?P<section>[^/]*)/$', 'blog.views.blog_index'),
     (r'^$', 'blog.views.blog_index'),
 )
     (r'^section/(?P<section>[^/]*)/$', 'blog.views.blog_index'),
     (r'^$', 'blog.views.blog_index'),
 )
index b01bec8dcbffaf5bf3de08e7450a0869df19458d..08b52670cb00ce3c15507d9e500e8b7631d7e7e8 100644 (file)
@@ -26,6 +26,7 @@ def blog_index(request, section=None):
                 "page": page,
                 "pages": pages,
                 "paginated": 1,
                 "page": page,
                 "pages": pages,
                 "paginated": 1,
+                "has_more_than_one_page": (len(pages) > 1),
                 "has_next": paginated_entries.has_next(),
                 "has_prev": paginated_entries.has_previous(),
                 "next": page + 1,
                 "has_next": paginated_entries.has_next(),
                 "has_prev": paginated_entries.has_previous(),
                 "next": page + 1,
@@ -52,3 +53,44 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None,
                 }
             )
             return HttpResponse(t.render(c))
                 }
             )
             return HttpResponse(t.render(c))
+    else:
+        entries = BlogEntry.objects.all()
+        if year and month and day:
+            year = int(year)
+            month = int(month)
+            day = int(day)
+            entries = entries.filter(publish_date__year=year, publish_date__month=month, publish_date__day=day)
+        elif year and month:
+            year = int(year)
+            month = int(month)
+            entries = entries.filter(publish_date__year=year, publish_date__month=month)
+        elif year:
+            year = int(year)
+            entries = entries.filter(publish_date__year=year)
+        if entries:
+            entries = entries.order_by('-publish_date')
+            paginate_by=20
+            paginator = Paginator(entries, paginate_by)
+            try:
+                page = int(request.GET.get('page', 1))
+            except ValueError:
+                page = 1
+            paginated_entries = paginator.page(page)
+            pages = paginator.page_range
+            t = loader.get_template("blog/blog_index.html")
+            c = RequestContext(request,
+                {
+                    "entries": paginated_entries.object_list,
+                    "title": settings.BLOG_TITLE,
+                    "page": page,
+                    "pages": pages,
+                    "paginated": 1,
+                    "has_more_than_one_page": (len(pages) > 1),
+                    "has_next": paginated_entries.has_next(),
+                    "has_prev": paginated_entries.has_previous(),
+                    "next": page + 1,
+                    "prev": page - 1
+                })
+            return HttpResponse(t.render(c))
+        else:
+            raise Http404