From 8b73562314685b0588d2ee1c5a61436d8d1e4e20 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Tue, 4 May 2010 02:40:18 -0400 Subject: [PATCH] Initial skeleton of penfield application, and partial implementation of Entry and Blog models. --- contrib/penfield/__init__.py | 0 contrib/penfield/admin.py | 6 +++ contrib/penfield/models.py | 91 ++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 contrib/penfield/__init__.py create mode 100644 contrib/penfield/admin.py create mode 100644 contrib/penfield/models.py diff --git a/contrib/penfield/__init__.py b/contrib/penfield/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/contrib/penfield/admin.py b/contrib/penfield/admin.py new file mode 100644 index 0000000..5fc9dcc --- /dev/null +++ b/contrib/penfield/admin.py @@ -0,0 +1,6 @@ +from models import Entry, Blog +from django.contrib import admin +from philo.admin import EntityAdmin + +admin.site.register(Entry, EntityAdmin) +admin.site.register(Blog) \ No newline at end of file diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py new file mode 100644 index 0000000..374fb49 --- /dev/null +++ b/contrib/penfield/models.py @@ -0,0 +1,91 @@ +from django.db import models +from philo.models import Entity, Collection, MultiNode, Template, register_value_model +from django.contrib.auth.models import User +from django.conf.urls.defaults import url, patterns +from django.http import Http404, HttpResponse + + +class Entry(Entity): + author = models.ForeignKey(User, related_name='blogpost_author') + pub_date = models.DateTimeField(auto_now_add=True) + mod_date = models.DateTimeField(auto_now=True) + title = models.CharField(max_length=255) + slug = models.SlugField() + content = models.TextField() + excerpt = models.TextField() + + +register_value_model(Entry) + + +class Blog(MultiNode): + PERMALINK_STYLE_CHOICES = ( + ('D', 'Year, month, and day'), + ('M', 'Year and month'), + ('Y', 'Year'), + ('B', 'Custom base'), + ('N', 'No base') + ) + + posts = models.ForeignKey(Collection, related_name='blogs') + index_template = models.ForeignKey(Template, related_name='blog_index_related') + archive_template = models.ForeignKey(Template, related_name='blog_archive_related') + tag_template = models.ForeignKey(Template, related_name='blog_tag_related') + post_template = models.ForeignKey(Template, related_name='blog_post_related') + + post_permalink_style = models.CharField(max_length=1, choices=PERMALINK_STYLE_CHOICES) + post_permalink_base = models.CharField(max_length=255, blank=False, default='posts') + tag_permalink_base = models.CharField(max_length=255, blank=False, default='tags') + + @property + def post_queryset(self): + # this won't be ordered according to the collection member indexes + return self.posts.members.with_model(Entry) + + @property + def urlpatterns(self): + base_patterns = patterns('', + url(r'^$', self.index_view), + url((r'^(?:%s)/?' % self.tag_permalink_base), self.tag_view), + url((r'^(?:%s)/(?P\w+)/?' % self.tag_permalink_base), self.tag_view) + ) + if self.post_permalink_style == 'D': + post_patterns = patterns('', + url(r'^(?P\d{4})/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\d{2})/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\d{2})/(?P\d+)/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\d{2})/(?P\d+)/(?P\w+)/?', self.archive_view) + ) + elif self.post_permalink_style == 'M': + post_patterns = patterns('', + url(r'^(?P\d{4})/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\d{2})/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\d{2})/(?P\w+)/?', self.archive_view) + ) + elif self.post_permalink_style == 'Y': + post_patterns = patterns('', + url(r'^(?P\d{4})/?$', self.archive_view), + url(r'^(?P\d{4})/(?P\w+)/?', self.post_view) + ) + elif self.post_permalink_style == 'B': + post_patterns = patterns('', + url((r'^(?:%s)/?' % self.post_permalink_base), self.archive_view), + url((r'^(?:%s)/(?P\w+)/?' % self.post_permalink_base), self.post_view) + ) + else: + post_patterns = patterns('', + url(r'^(?P\w+)/?', self.post_view) + ) + return base_patterns + post_patterns + + def index_view(self, request): + raise Http404 + + def archive_view(self, request, year=None, month=None, day=None): + raise Http404 + + def tag_view(self, request, tag=None): + raise Http404 + + def post_view(self, request, year=None, month=None, day=None, slug=None): + raise Http404 -- 2.20.1