+ def index_view(self, request, node=None, extra_context=None):
+ context = {}
+ context.update(extra_context or {})
+ context.update({'blog': self.blog})
+ return self.index_page.render_to_response(node, request, extra_context=context)
+
+ def archive_view(self, request, year=None, month=None, day=None, node=None, extra_context=None):
+ entries = self.blog.entries.all()
+ if year:
+ entries = entries.filter(date__year=year)
+ if month:
+ entries = entries.filter(date__month=month)
+ if day:
+ entries = entries.filter(date__day=day)
+ context = {}
+ context.update(extra_context or {})
+ context.update({'blog': self.blog, 'year': year, 'month': month, 'day': day, 'entries': entries})
+ return self.archive_page.render_to_response(node, request, extra_context=context)
+
+ def tag_view(self, request, tag=None, node=None, extra_context=None):
+ entries = self.blog.entries.filter(tags__slug=tag)
+ context = {}
+ context.update(extra_context or {})
+ context.update({'blog': self.blog, 'tag': tag, 'entries': entries})
+ return self.tag_page.render_to_response(node, request, extra_context=context)
+
+ def entry_view(self, request, slug, year=None, month=None, day=None, node=None, extra_context=None):
+ entries = self.blog.entries.all()
+ if year:
+ entries = entries.filter(date__year=year)
+ if month:
+ entries = entries.filter(date__month=month)
+ if day:
+ entries = entries.filter(date__day=day)
+ try:
+ entry = entries.get(slug=slug)
+ except:
+ raise Http404
+ context = {}
+ context.update(extra_context or {})
+ context.update({'blog': self.blog, 'entry': entry})
+ return self.entry_page.render_to_response(node, request, extra_context=context)
+
+
+class Newsletter(Entity, Titled):
+ pass
+
+
+class NewsletterArticle(Entity, Titled):
+ newsletter = models.ForeignKey(Newsletter, related_name='articles')
+ authors = models.ManyToManyField(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='newsletterarticles')
+ date = models.DateTimeField(default=datetime.now)
+ lede = models.TextField(null=True, blank=True)
+ full_text = models.TextField()
+
+
+register_value_model(NewsletterArticle)
+
+
+class NewsletterIssue(Entity, Titled):
+ newsletter = models.ForeignKey(Newsletter, related_name='issues')
+ number = models.PositiveIntegerField()
+ articles = models.ManyToManyField(NewsletterArticle)
+
+
+class NewsletterView(MultiView):
+ newsletter = models.ForeignKey(Newsletter, related_name='newsletterviews')
+
+ index_page = models.ForeignKey(Page, related_name='newsletter_index_related')
+ article_page = models.ForeignKey(Page, related_name='newsletter_article_related')
+ issue_page = models.ForeignKey(Page, related_name='newsletter_issue_related')
+
+ @property
+ def urlpatterns(self):
+ base_patterns = patterns('',
+ url(r'^$', self.index_view),
+ url(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/(?P<slug>[-\w]+)/?', self.article_view),
+ url(r'^issues/(?P<number>\d+)/?', self.issue_view),
+ )
+ return base_patterns