Skip to content
Browse files

set up the URL structure for the blog

Now, the blog lives at the root of the site. It follows a
/year/month/day/slug/ organization, with / being the overall site
index. The next step is templates.
  • Loading branch information...
1 parent 960d1f7 commit f3fa8b60c0a3e2235a1d8d9a1ccdb6d72fc5f153 @leafstorm leafstorm committed
Showing with 52 additions and 4 deletions.
  1. +2 −0 lug_blog/models.py
  2. +13 −0 lug_blog/urls.py
  3. +28 −1 lug_blog/views.py
  4. +6 −0 lug_site/settings.py
  5. +3 −3 lug_site/urls.py
View
2 lug_blog/models.py
@@ -11,6 +11,8 @@ def published(self):
class BlogPost(models.Model):
+ objects = BlogPostManager()
+
title = models.CharField("title", max_length=240,
help_text=u"The post's headline.")
slug = models.SlugField("slug", unique_for_date='pub_date',
View
13 lug_blog/urls.py
@@ -1,3 +1,16 @@
from django.conf.urls import patterns, include, url
+from .views import (archive_index, year_archive, month_archive, day_archive,
+ post_detail)
+YEAR = r'(?P<year>\d{4})/'
+MONTH = r'(?P<month>\d{1,2})/'
+DAY = r'(?P<day>\w{1,2})/'
+SLUG = r'(?P<slug>[\w-]+)/'
+urlpatterns = patterns('',
+ url('^' + YEAR + MONTH + DAY + SLUG, post_detail, name='blog_entry'),
+ url('^' + YEAR + MONTH + DAY, day_archive, name='blog_day'),
+ url('^' + YEAR + MONTH, month_archive, name='blog_month'),
+ url('^' + YEAR, year_archive, name='blog_year'),
+ url('^/?$', archive_index, name='index')
+)
View
29 lug_blog/views.py
@@ -1 +1,28 @@
-# Create your views here.
+from django.views.generic.dates import (ArchiveIndexView, YearArchiveView,
+ MonthArchiveView, DayArchiveView,
+ DateDetailView)
+from .models import BlogPost
+
+global_options = dict(
+ model = BlogPost,
+ queryset = BlogPost.objects.active(),
+ date_field = 'pub_date'
+)
+
+archive_options = global_options.copy()
+archive_options.update(
+ context_object_name = 'posts',
+ paginate_by = 10,
+ allow_empty = False
+)
+
+archive_index = ArchiveIndexView.as_view(**archive_options)
+year_archive = YearArchiveView.as_view(make_object_list=True,
+ **archive_options)
+month_archive = MonthArchiveView.as_view(month_format='%m',
+ **archive_options)
+day_archive = DayArchiveView.as_view(month_format='%m',
+ **archive_options)
+post_detail = DateDetailView.as_view(month_format='%m',
+ context_object_name='post',
+ **global_options)
View
6 lug_site/settings.py
@@ -151,6 +151,12 @@
GRAVATAR_DEFAULT_IMAGE = 'identicon'
GRAVATAR_IMG_CLASS = 'gravatar'
+INTERWIKIS = {
+ 'trilug': ('http://trilug.org/wiki/', '_'),
+ 'wikipedia': ('http://en.wikipedia.org/wiki/', '_')
+}
+
+
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
View
6 lug_site/urls.py
@@ -5,11 +5,11 @@
admin.autodiscover()
urlpatterns = patterns('',
- # General site views
- url(r'^$', TemplateView.as_view(template_name="index.html"), name='index'),
+ # Blog views
+ url(r'^', include('lug_blog.urls')),
# Profile and account views
- (r'^', include('lug_people.urls')),
+ url(r'^', include('lug_people.urls')),
# Admin interface and other internals
url(r'^admin/', include(admin.site.urls)),

0 comments on commit f3fa8b6

Please sign in to comment.
Something went wrong with that request. Please try again.