This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* filters by published * takes an array of entry ids rather than a timestamp
- Loading branch information
Showing
6 changed files
with
52 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
from django.conf import settings | ||
from django.db.models.loading import get_model | ||
from django.shortcuts import get_object_or_404 | ||
from django.utils import dateparse | ||
from django.utils import timezone | ||
from django.views.decorators.cache import cache_control | ||
from django.views.generic import TemplateView | ||
|
||
from bulbs.content.views import BaseContentDetailView | ||
|
||
LiveBlogModel = get_model(settings.BULBS_LIVEBLOG_MODEL) | ||
|
||
|
||
class LiveblogNewEntriesView(TemplateView): | ||
class LiveblogNewEntriesView(BaseContentDetailView): | ||
model = LiveBlogModel | ||
template_name = 'liveblog/new_entries.html' | ||
redirect_correct_path = False | ||
|
||
def get_context_data(self, slug, pk): | ||
def get_context_data(self, object): | ||
context = {} | ||
liveblog = get_object_or_404(LiveBlogModel, pk=pk) | ||
when = dateparse.parse_datetime(self.request.GET['new_as_of']) | ||
if not when: | ||
raise ValueError('param new_as_of must be an ISO formatted timestamp') | ||
context['entries'] = liveblog.entries.filter(published__gte=when) | ||
if 'entry_ids' not in self.request.GET: | ||
raise ValueError('param "entry_ids" MUST be specified') | ||
parsed_entry_ids = [x.strip() for x in self.request.GET['entry_ids'].split(',')] | ||
context['entries'] = self.object.entries.filter( | ||
pk__in=parsed_entry_ids, | ||
published__lte=timezone.now()) | ||
return context | ||
|
||
liveblog_new_entries = cache_control(max_age=600)(LiveblogNewEntriesView.as_view()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters