from django.conf import settings
from django.conf.urls.defaults import url, patterns, include
-from django.contrib.sites.models import Site, RequestSite
-from django.contrib.syndication.views import add_domain
from django.db import models
from django.http import Http404, HttpResponse
-from django.template import RequestContext, Template as DjangoTemplate
-from django.utils import feedgenerator, tzinfo
-from django.utils.datastructures import SortedDict
-from django.utils.encoding import smart_unicode, force_unicode
-from django.utils.html import escape
-from philo.contrib.penfield.exceptions import HttpNotAcceptable
-from philo.contrib.penfield.middleware import http_not_acceptable
-from philo.contrib.penfield.validators import validate_pagination_count
+from philo.contrib.winer.models import FeedView
from philo.exceptions import ViewCanNotProvideSubpath
-from philo.models import Tag, Entity, MultiView, Page, register_value_model, TemplateField, Template
+from philo.models import Tag, Entity, Page, register_value_model
+from philo.models.fields import TemplateField
from philo.utils import paginate
-try:
- import mimeparse
-except:
- mimeparse = None
-
-
-ATOM = feedgenerator.Atom1Feed.mime_type
-RSS = feedgenerator.Rss201rev2Feed.mime_type
-FEEDS = SortedDict([
- (ATOM, feedgenerator.Atom1Feed),
- (RSS, feedgenerator.Rss201rev2Feed),
-])
-FEED_CHOICES = (
- (ATOM, "Atom"),
- (RSS, "RSS"),
-)
-
-
-class FeedView(MultiView):
- """
- The FeedView expects to handle a number of different feeds for the
- same object - i.e. patterns for a blog to handle all entries or
- just entries for a certain year/month/day.
-
- This class would subclass django.contrib.syndication.views.Feed, but
- that would make it callable, which causes problems.
- """
- feed_type = models.CharField(max_length=50, choices=FEED_CHOICES, default=ATOM)
- feed_suffix = models.CharField(max_length=255, blank=False, default="feed")
- feeds_enabled = models.BooleanField(default=True)
- feed_length = models.PositiveIntegerField(blank=True, null=True, default=15, help_text="The maximum number of items to return for this feed. All items will be returned if this field is blank.")
-
- item_title_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_title_related")
- item_description_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_description_related")
-
- item_context_var = 'items'
- object_attr = 'object'
-
- description = ""
-
- def feed_patterns(self, base, get_items_attr, page_attr, reverse_name):
- """
- Given the name to be used to reverse this view and the names of
- the attributes for the function that fetches the objects, returns
- patterns suitable for inclusion in urlpatterns.
- """
- urlpatterns = patterns('')
- if self.feeds_enabled:
- feed_reverse_name = "%s_feed" % reverse_name
- feed_view = http_not_acceptable(self.feed_view(get_items_attr, feed_reverse_name))
- feed_pattern = r'%s%s%s$' % (base, (base and base[-1] != "^") and "/" or "", self.feed_suffix)
- urlpatterns += patterns('',
- url(feed_pattern, feed_view, name=feed_reverse_name),
- )
- urlpatterns += patterns('',
- url(r"%s$" % base, self.page_view(get_items_attr, page_attr), name=reverse_name)
- )
- return urlpatterns
-
- def get_object(self, request, **kwargs):
- return getattr(self, self.object_attr)
-
- def feed_view(self, get_items_attr, reverse_name):
- """
- Returns a view function that renders a list of items as a feed.
- """
- get_items = callable(get_items_attr) and get_items_attr or getattr(self, get_items_attr)
-
- def inner(request, extra_context=None, *args, **kwargs):
- obj = self.get_object(request, *args, **kwargs)
- feed = self.get_feed(obj, request, reverse_name)
- items, xxx = get_items(request, extra_context=extra_context, *args, **kwargs)
- self.populate_feed(feed, items, request)
-
- response = HttpResponse(mimetype=feed.mime_type)
- feed.write(response, 'utf-8')
- return response
-
- return inner
-
- def page_view(self, get_items_attr, page_attr):
- """
- Returns a view function that renders a list of items as a page.
- """
- get_items = callable(get_items_attr) and get_items_attr or getattr(self, get_items_attr)
- page = isinstance(page_attr, Page) and page_attr or getattr(self, page_attr)
-
- def inner(request, extra_context=None, *args, **kwargs):
- items, extra_context = get_items(request, extra_context=extra_context, *args, **kwargs)
- items, item_context = self.process_page_items(request, items)
-
- context = self.get_context()
- context.update(extra_context or {})
- context.update(item_context or {})
-
- return page.render_to_response(request, extra_context=context)
- return inner
-
- def process_page_items(self, request, items):
- """
- Hook for handling any extra processing of items based on a
- request, such as pagination or searching. This method is
- expected to return a list of items and a dictionary to be
- added to the page context.
- """
- item_context = {
- self.item_context_var: items
- }
- return items, item_context
-
- def get_feed_type(self, request):
- feed_type = self.feed_type
- if feed_type not in FEEDS:
- feed_type = FEEDS.keys()[0]
- accept = request.META.get('HTTP_ACCEPT')
- if accept and feed_type not in accept and "*/*" not in accept and "%s/*" % feed_type.split("/")[0] not in accept:
- # Wups! They aren't accepting the chosen format. Is there another format we can use?
- if mimeparse:
- feed_type = mimeparse.best_match(FEEDS.keys(), accept)
- else:
- for feed_type in FEEDS.keys():
- if feed_type in accept or "%s/*" % feed_type.split("/")[0] in accept:
- break
- else:
- feed_type = None
- if not feed_type:
- raise HttpNotAcceptable
- return FEEDS[feed_type]
-
- def get_feed(self, obj, request, reverse_name):
- """
- Returns an unpopulated feedgenerator.DefaultFeed object for this object.
- """
- try:
- current_site = Site.objects.get_current()
- except Site.DoesNotExist:
- current_site = RequestSite(request)
-
- feed_type = self.get_feed_type(request)
- node = request.node
- link = node.get_absolute_url(with_domain=True, request=request, secure=request.is_secure())
-
- feed = feed_type(
- title = self.__get_dynamic_attr('title', obj),
- subtitle = self.__get_dynamic_attr('subtitle', obj),
- link = link,
- description = self.__get_dynamic_attr('description', obj),
- language = settings.LANGUAGE_CODE.decode(),
- feed_url = add_domain(
- current_site.domain,
- self.__get_dynamic_attr('feed_url', obj) or node.construct_url(node.subpath, with_domain=True, request=request, secure=request.is_secure()),
- request.is_secure()
- ),
- author_name = self.__get_dynamic_attr('author_name', obj),
- author_link = self.__get_dynamic_attr('author_link', obj),
- author_email = self.__get_dynamic_attr('author_email', obj),
- categories = self.__get_dynamic_attr('categories', obj),
- feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
- feed_guid = self.__get_dynamic_attr('feed_guid', obj),
- ttl = self.__get_dynamic_attr('ttl', obj),
- **self.feed_extra_kwargs(obj)
- )
- return feed
-
- def populate_feed(self, feed, items, request):
- if self.item_title_template:
- title_template = DjangoTemplate(self.item_title_template.code)
- else:
- title_template = None
- if self.item_description_template:
- description_template = DjangoTemplate(self.item_description_template.code)
- else:
- description_template = None
-
- node = request.node
- try:
- current_site = Site.objects.get_current()
- except Site.DoesNotExist:
- current_site = RequestSite(request)
-
- if self.feed_length is not None:
- items = items[:self.feed_length]
-
- for item in items:
- if title_template is not None:
- title = title_template.render(RequestContext(request, {'obj': item}))
- else:
- title = self.__get_dynamic_attr('item_title', item)
- if description_template is not None:
- description = description_template.render(RequestContext(request, {'obj': item}))
- else:
- description = self.__get_dynamic_attr('item_description', item)
-
- link = node.construct_url(self.reverse(obj=item), with_domain=True, request=request, secure=request.is_secure())
-
- enc = None
- enc_url = self.__get_dynamic_attr('item_enclosure_url', item)
- if enc_url:
- enc = feedgenerator.Enclosure(
- url = smart_unicode(add_domain(
- current_site.domain,
- enc_url,
- request.is_secure()
- )),
- length = smart_unicode(self.__get_dynamic_attr('item_enclosure_length', item)),
- mime_type = smart_unicode(self.__get_dynamic_attr('item_enclosure_mime_type', item))
- )
- author_name = self.__get_dynamic_attr('item_author_name', item)
- if author_name is not None:
- author_email = self.__get_dynamic_attr('item_author_email', item)
- author_link = self.__get_dynamic_attr('item_author_link', item)
- else:
- author_email = author_link = None
-
- pubdate = self.__get_dynamic_attr('item_pubdate', item)
- if pubdate and not pubdate.tzinfo:
- ltz = tzinfo.LocalTimezone(pubdate)
- pubdate = pubdate.replace(tzinfo=ltz)
-
- feed.add_item(
- title = title,
- link = link,
- description = description,
- unique_id = self.__get_dynamic_attr('item_guid', item, link),
- enclosure = enc,
- pubdate = pubdate,
- author_name = author_name,
- author_email = author_email,
- author_link = author_link,
- categories = self.__get_dynamic_attr('item_categories', item),
- item_copyright = self.__get_dynamic_attr('item_copyright', item),
- **self.item_extra_kwargs(item)
- )
-
- def __get_dynamic_attr(self, attname, obj, default=None):
- try:
- attr = getattr(self, attname)
- except AttributeError:
- return default
- if callable(attr):
- # Check func_code.co_argcount rather than try/excepting the
- # function and catching the TypeError, because something inside
- # the function may raise the TypeError. This technique is more
- # accurate.
- if hasattr(attr, 'func_code'):
- argcount = attr.func_code.co_argcount
- else:
- argcount = attr.__call__.func_code.co_argcount
- if argcount == 2: # one argument is 'self'
- return attr(obj)
- else:
- return attr()
- return attr
-
- def feed_extra_kwargs(self, obj):
- """
- Returns an extra keyword arguments dictionary that is used when
- initializing the feed generator.
- """
- return {}
-
- def item_extra_kwargs(self, item):
- """
- Returns an extra keyword arguments dictionary that is used with
- the `add_item` call of the feed generator.
- """
- return {}
-
- def item_title(self, item):
- return escape(force_unicode(item))
-
- def item_description(self, item):
- return force_unicode(item)
-
- class Meta:
- abstract=True
-
class Blog(Entity):
+ """Represents a blog which can be posted to."""
+ #: The name of the :class:`Blog`, currently called 'title' for historical reasons.
title = models.CharField(max_length=255)
+
+ #: A slug used to identify the :class:`Blog`.
slug = models.SlugField(max_length=255)
def __unicode__(self):
@property
def entry_tags(self):
- """ Returns a QuerySet of Tags that are used on any entries in this blog. """
+ """Returns a :class:`QuerySet` of :class:`.Tag`\ s that are used on any entries in this blog."""
return Tag.objects.filter(blogentries__blog=self).distinct()
@property
def entry_dates(self):
+ """Returns a dictionary of date :class:`QuerySet`\ s for years, months, and days for which there are entries."""
dates = {'year': self.entries.dates('date', 'year', order='DESC'), 'month': self.entries.dates('date', 'month', order='DESC'), 'day': self.entries.dates('date', 'day', order='DESC')}
return dates
class BlogEntry(Entity):
+ """Represents an entry in a :class:`Blog`."""
+ #: The title of the :class:`BlogEntry`.
title = models.CharField(max_length=255)
+
+ #: A slug which identifies the :class:`BlogEntry`.
slug = models.SlugField(max_length=255)
+
+ #: The :class:`Blog` which this entry has been posted to. Can be left blank to represent a "draft" status.
blog = models.ForeignKey(Blog, related_name='entries', blank=True, null=True)
+
+ #: A :class:`ForeignKey` to the author. The model is either :setting:`PHILO_PERSON_MODULE` or :class:`auth.User`.
author = models.ForeignKey(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='blogentries')
+
+ #: The date and time which the :class:`BlogEntry` is considered posted at.
date = models.DateTimeField(default=None)
+
+ #: The content of the :class:`BlogEntry`.
content = models.TextField()
+
+ #: An optional brief excerpt from the :class:`BlogEntry`.
excerpt = models.TextField(blank=True, null=True)
+
+ #: :class:`.Tag`\ s for this :class:`BlogEntry`.
tags = models.ManyToManyField(Tag, related_name='blogentries', blank=True, null=True)
def save(self, *args, **kwargs):
class BlogView(FeedView):
+ """
+ A subclass of :class:`.FeedView` which handles patterns and feeds for a :class:`Blog` and its related :class:`entries <BlogEntry>`.
+
+ """
ENTRY_PERMALINK_STYLE_CHOICES = (
('D', 'Year, month, and day'),
('M', 'Year and month'),
('N', 'No base')
)
+ #: The :class:`Blog` whose entries should be managed by this :class:`BlogView`
blog = models.ForeignKey(Blog, related_name='blogviews')
+ #: The main page of the :class:`Blog` will be rendered with this :class:`.Page`.
index_page = models.ForeignKey(Page, related_name='blog_index_related')
+ #: The detail view of a :class:`BlogEntry` will be rendered with this :class:`Page`.
entry_page = models.ForeignKey(Page, related_name='blog_entry_related')
# TODO: entry_archive is misleading. Rename to ymd_page or timespan_page.
+ #: Views of :class:`BlogEntry` archives will be rendered with this :class:`Page` (optional).
entry_archive_page = models.ForeignKey(Page, related_name='blog_entry_archive_related', null=True, blank=True)
+ #: Views of :class:`BlogEntry` archives according to their :class:`.Tag`\ s will be rendered with this :class:`Page`.
tag_page = models.ForeignKey(Page, related_name='blog_tag_related')
+ #: The archive of all available tags will be rendered with this :class:`Page` (optional).
tag_archive_page = models.ForeignKey(Page, related_name='blog_tag_archive_related', null=True, blank=True)
- entries_per_page = models.IntegerField(blank=True, validators=[validate_pagination_count], null=True)
-
+ #: This number will be passed directly into pagination for :class:`BlogEntry` list pages. Pagination will be disabled if this is left blank.
+ entries_per_page = models.IntegerField(blank=True, null=True)
+
+ #: Depending on the needs of the site, different permalink styles may be appropriate. Example subpaths are provided for a :class:`BlogEntry` posted on May 2nd, 2011 with a slug of "hello". The choices are:
+ #:
+ #: * Year, month, and day - ``2011/05/02/hello``
+ #: * Year and month - ``2011/05/hello``
+ #: * Year - ``2011/hello``
+ #: * Custom base - :attr:`entry_permalink_base`\ ``/hello``
+ #: * No base - ``hello``
entry_permalink_style = models.CharField(max_length=1, choices=ENTRY_PERMALINK_STYLE_CHOICES)
+ #: If the :attr:`entry_permalink_style` is set to "Custom base" then the value of this field will be used as the base subpath for year/month/day entry archive pages and entry detail pages. Default: "entries"
entry_permalink_base = models.CharField(max_length=255, blank=False, default='entries')
+ #: This will be used as the base for the views of :attr:`tag_page` and :attr:`tag_archive_page`. Default: "tags"
tag_permalink_base = models.CharField(max_length=255, blank=False, default='tags')
item_context_var = 'entries'
@property
def urlpatterns(self):
urlpatterns = self.feed_patterns(r'^', 'get_all_entries', 'index_page', 'index') +\
- self.feed_patterns(r'^%s/(?P<tag_slugs>[-\w]+[-+/\w]*)$' % self.tag_permalink_base, 'get_entries_by_tag', 'tag_page', 'entries_by_tag')
+ self.feed_patterns(r'^%s/(?P<tag_slugs>[-\w]+[-+/\w]*)' % self.tag_permalink_base, 'get_entries_by_tag', 'tag_page', 'entries_by_tag')
if self.tag_archive_page:
urlpatterns += patterns('',
url((r'^%s/(?P<slug>[-\w]+)$' % self.entry_permalink_base), self.entry_view)
)
else:
- urlpatterns = patterns('',
+ urlpatterns += patterns('',
url(r'^(?P<slug>[-\w]+)$', self.entry_view)
)
return urlpatterns
return {'blog': self.blog}
def get_entry_queryset(self):
- return self.blog.entries.all()
+ """Returns the default :class:`QuerySet` of :class:`BlogEntry` instances for the :class:`BlogView` - all entries that are considered posted in the past. This allows for scheduled posting of entries."""
+ return self.blog.entries.filter(date__lte=datetime.now())
def get_tag_queryset(self):
+ """Returns the default :class:`QuerySet` of :class:`.Tag`\ s for the :class:`BlogView`'s :meth:`get_entries_by_tag` and :meth:`tag_archive_view`."""
return self.blog.entry_tags
def get_all_entries(self, request, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for all entries."""
return self.get_entry_queryset(), extra_context
def get_entries_by_ymd(self, request, year=None, month=None, day=None, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for entries with a specific year, month, and day."""
if not self.entry_archive_page:
raise Http404
entries = self.get_entry_queryset()
return entries, context
def get_entries_by_tag(self, request, tag_slugs, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for entries with all of the given tags."""
tag_slugs = tag_slugs.replace('+', '/').split('/')
tags = self.get_tag_queryset().filter(slug__in=tag_slugs)
return entries, context
def entry_view(self, request, slug, year=None, month=None, day=None, extra_context=None):
+ """Renders :attr:`entry_page` with the entry specified by the given parameters."""
entries = self.get_entry_queryset()
if year:
entries = entries.filter(date__year=year)
return self.entry_page.render_to_response(request, extra_context=context)
def tag_archive_view(self, request, extra_context=None):
+ """Renders :attr:`tag_archive_page` with the result of :meth:`get_tag_queryset` added to the context."""
if not self.tag_archive_page:
raise Http404
context = self.get_context()
})
return self.tag_archive_page.render_to_response(request, extra_context=context)
- def feed_view(self, get_items_attr, reverse_name):
+ def feed_view(self, get_items_attr, reverse_name, feed_type=None):
+ """Overrides :meth:`.FeedView.feed_view` to add :class:`.Tag`\ s to the feed as categories."""
get_items = callable(get_items_attr) and get_items_attr or getattr(self, get_items_attr)
def inner(request, extra_context=None, *args, **kwargs):
obj = self.get_object(request, *args, **kwargs)
- feed = self.get_feed(obj, request, reverse_name)
+ feed = self.get_feed(obj, request, reverse_name, feed_type, *args, **kwargs)
items, extra_context = get_items(request, extra_context=extra_context, *args, **kwargs)
self.populate_feed(feed, items, request)
return inner
def process_page_items(self, request, items):
+ """Overrides :meth:`.FeedView.process_page_items` to add pagination."""
if self.entries_per_page:
page_num = request.GET.get('page', 1)
paginator, paginated_page, items = paginate(items, self.entries_per_page, page_num)
class Newsletter(Entity):
+ """Represents a newsletter which will contain :class:`articles <NewsletterArticle>` organized into :class:`issues <NewsletterIssue>`."""
+ #: The name of the :class:`Newsletter`, currently callse 'title' for historical reasons.
title = models.CharField(max_length=255)
+ #: A slug used to identify the :class:`Newsletter`.
slug = models.SlugField(max_length=255)
def __unicode__(self):
class NewsletterArticle(Entity):
+ """Represents an article in a :class:`Newsletter`"""
+ #: The title of the :class:`NewsletterArticle`.
title = models.CharField(max_length=255)
+ #: A slug which identifies the :class:`NewsletterArticle`.
slug = models.SlugField(max_length=255)
+ #: A :class:`ForeignKey` to :class:`Newsletter` representing the newsletter which this article was written for.
newsletter = models.ForeignKey(Newsletter, related_name='articles')
+ #: A :class:`ManyToManyField` to the author(s) of the :class:`NewsletterArticle`. The model is either :setting:`PHILO_PERSON_MODULE` or :class:`auth.User`.
authors = models.ManyToManyField(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='newsletterarticles')
+ #: The date and time which the :class:`NewsletterArticle` is considered published at.
date = models.DateTimeField(default=None)
+ #: A :class:`.TemplateField` containing an optional short summary of the article, meant to grab a reader's attention and draw them in.
lede = TemplateField(null=True, blank=True, verbose_name='Summary')
+ #: A :class:`.TemplateField` containing the full text of the article.
full_text = TemplateField(db_index=True)
+ #: A :class:`ManyToManyField` to :class:`.Tag`\ s for the :class:`NewsletterArticle`.
tags = models.ManyToManyField(Tag, related_name='newsletterarticles', blank=True, null=True)
def save(self, *args, **kwargs):
class NewsletterIssue(Entity):
+ """Represents an issue of the newsletter."""
+ #: The title of the :class:`NewsletterIssue`.
title = models.CharField(max_length=255)
+ #: A slug which identifies the :class:`NewsletterIssue`.
slug = models.SlugField(max_length=255)
+ #: A :class:`ForeignKey` to the :class:`Newsletter` which this issue belongs to.
newsletter = models.ForeignKey(Newsletter, related_name='issues')
+ #: The numbering of the issue - for example, 04.02 for volume 4, issue 2. This is an instance of :class:`CharField` to allow any arbitrary numbering system.
numbering = models.CharField(max_length=50, help_text='For example, 04.02 for volume 4, issue 2.')
+ #: A :class:`ManyToManyField` to articles belonging to this issue.
articles = models.ManyToManyField(NewsletterArticle, related_name='issues')
def __unicode__(self):
class NewsletterView(FeedView):
+ """A subclass of :class:`.FeedView` which handles patterns and feeds for a :class:`Newsletter` and its related :class:`articles <NewsletterArticle>`."""
ARTICLE_PERMALINK_STYLE_CHOICES = (
('D', 'Year, month, and day'),
('M', 'Year and month'),
('S', 'Slug only')
)
+ #: A :class:`ForeignKey` to the :class:`Newsletter` managed by this :class:`NewsletterView`.
newsletter = models.ForeignKey(Newsletter, related_name='newsletterviews')
+ #: A :class:`ForeignKey` to the :class:`Page` used to render the main page of this :class:`NewsletterView`.
index_page = models.ForeignKey(Page, related_name='newsletter_index_related')
+ #: A :class:`ForeignKey` to the :class:`Page` used to render the detail view of a :class:`NewsletterArticle` for this :class:`NewsletterView`.
article_page = models.ForeignKey(Page, related_name='newsletter_article_related')
+ #: A :class:`ForeignKey` to the :class:`Page` used to render the :class:`NewsletterArticle` archive pages for this :class:`NewsletterView`.
article_archive_page = models.ForeignKey(Page, related_name='newsletter_article_archive_related', null=True, blank=True)
+ #: A :class:`ForeignKey` to the :class:`Page` used to render the detail view of a :class:`NewsletterIssue` for this :class:`NewsletterView`.
issue_page = models.ForeignKey(Page, related_name='newsletter_issue_related')
+ #: A :class:`ForeignKey` to the :class:`Page` used to render the :class:`NewsletterIssue` archive pages for this :class:`NewsletterView`.
issue_archive_page = models.ForeignKey(Page, related_name='newsletter_issue_archive_related', null=True, blank=True)
+ #: Depending on the needs of the site, different permalink styles may be appropriate. Example subpaths are provided for a :class:`NewsletterArticle` posted on May 2nd, 2011 with a slug of "hello". The choices are:
+ #:
+ #: * Year, month, and day - :attr:`article_permalink_base`\ ``/2011/05/02/hello``
+ #: * Year and month - :attr:`article_permalink_base`\ ``/2011/05/hello``
+ #: * Year - :attr:`article_permalink_base`\ ``/2011/hello``
+ #: * Slug only - :attr:`article_permalink_base`\ ``/hello``
article_permalink_style = models.CharField(max_length=1, choices=ARTICLE_PERMALINK_STYLE_CHOICES)
+ #: This will be used as the base subpath for year/month/day article archive pages and article detail pages. Default: "articles"
article_permalink_base = models.CharField(max_length=255, blank=False, default='articles')
+ #: This will be used as the base subpath for issue detail pages and the issue archive page.
issue_permalink_base = models.CharField(max_length=255, blank=False, default='issues')
item_context_var = 'articles'
return {'newsletter': self.newsletter}
def get_article_queryset(self):
- return self.newsletter.articles.all()
+ """Returns the default :class:`QuerySet` of :class:`NewsletterArticle` instances for the :class:`NewsletterView` - all articles that are considered posted in the past. This allows for scheduled posting of articles."""
+ return self.newsletter.articles.filter(date__lte=datetime.now())
def get_issue_queryset(self):
+ """Returns the default :class:`QuerySet` of :class:`NewsletterIssue` instances for the :class:`NewsletterView`."""
return self.newsletter.issues.all()
def get_all_articles(self, request, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for all entries."""
return self.get_article_queryset(), extra_context
def get_articles_by_ymd(self, request, year, month=None, day=None, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for a specific year, month, and day."""
articles = self.get_article_queryset().filter(date__year=year)
if month:
articles = articles.filter(date__month=month)
return articles, extra_context
def get_articles_by_issue(self, request, numbering, extra_context=None):
+ """Used to generate :meth:`~.FeedView.feed_patterns` for articles from a certain issue."""
try:
issue = self.get_issue_queryset().get(numbering=numbering)
except NewsletterIssue.DoesNotExist:
return self.get_article_queryset().filter(issues=issue), context
def article_view(self, request, slug, year=None, month=None, day=None, extra_context=None):
+ """Renders :attr:`article_page` with the article specified by the given parameters."""
articles = self.get_article_queryset()
if year:
articles = articles.filter(date__year=year)
return self.article_page.render_to_response(request, extra_context=context)
def issue_archive_view(self, request, extra_context):
+ """Renders :attr:`issue_archive_page` with the result of :meth:`get_issue_queryset` added to the context."""
if not self.issue_archive_page:
raise Http404
context = self.get_context()