Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge 3973ee8 into 8513f91
Browse files Browse the repository at this point in the history
  • Loading branch information
mparent61 committed Sep 9, 2016
2 parents 8513f91 + 3973ee8 commit d52c758
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 143 deletions.
60 changes: 0 additions & 60 deletions bulbs/liveblog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,66 +84,6 @@

`liveblog=123` Conditional filtering to match entries for specific `LiveBlog`

## Get All Entries (PUBLIC)

**GET:**

```
/api/v1/liveblog/public/entry/
```

### Body

```json
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"liveblog": 123,
"headline": "Something Really Funny",
"authors": [50, 57],
"body": "Why are you reading this? Stop it.",
"recirc_content": [501, 1801, 17203],
"published": "2015-01-01T01:01:00.000Z",
"responses": [
{
"author": 85,
"internal_name": "Secret Name",
"body": "Some more really interesting stuff you should read."
}
]
},
{
"liveblog": 123,
"headline": "Something Really Funny",
"authors": [50, 57],
"body": "Why are you reading this? Stop it.",
"recirc_content": [501, 1801, 17203],
"published": "2015-01-01T01:01:00.000Z",
"responses": [
{
"author": 85,
"internal_name": "Secret Name",
"body": "Some more really interesting stuff you should read."
}
]
}
]
}
```

### Filters

`liveblog=123` Conditional filtering to match entries for specific `LiveBlog`
`if_modified_since=2015-01-01T01:01:00.000Z` Conditional filtering to return all entries published after specified ISO 8601 date/time.

### Status Codes

* `200` if successful (modified entries found)
* `304` no modified entries

## Get single entry

### GET
Expand Down
12 changes: 2 additions & 10 deletions bulbs/liveblog/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.conf.urls import url

from rest_framework import routers

from bulbs.liveblog.viewsets import LiveBlogEntryViewSet, PublicLiveBlogEntryViewSet
from bulbs.liveblog.viewsets import LiveBlogEntryViewSet

api_v1_router = routers.DefaultRouter()
api_v1_router.register(
Expand All @@ -11,10 +9,4 @@
base_name="liveblog-entry"
)

urlpatterns = [
url(r"api/v1/liveblog/public/entry/?$",
PublicLiveBlogEntryViewSet.as_view({'get': 'list'}),
name="public-liveblog-entry"),
]

urlpatterns += api_v1_router.urls
urlpatterns = api_v1_router.urls
21 changes: 0 additions & 21 deletions bulbs/liveblog/filters.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
from rest_framework import filters
from rest_framework.exceptions import ParseError

from django.utils import dateparse


logger = __import__('logging').getLogger(__name__)


class IfModifiedSinceFilterBackend(filters.BaseFilterBackend):
"""
Optionally exclude older requests.
Expects ISO 8601-formatted "if_modified_since" query param.
"""
def filter_queryset(self, request, queryset, view):
if_modified_since = request.GET.get('if_modified_since')
if if_modified_since:
when = dateparse.parse_datetime(if_modified_since)
if when:
return queryset.filter(published__gt=when)
else:
raise ParseError('Bad "if_modified_since" date: {}'.format(if_modified_since))
else:
return queryset


class LiveBlogFilterBackend(filters.BaseFilterBackend):
"""
Optionally include only entries belonging to specified LiveBlog.
Expand Down
6 changes: 6 additions & 0 deletions bulbs/liveblog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class AbstractLiveBlog(models.Model):
class Meta:
abstract = True

def get_absolute_url(self):
return '/liveblog/{}-{}'.format(self.slug, self.pk)


class LiveBlogEntry(models.Model):

Expand All @@ -29,6 +32,9 @@ class LiveBlogEntry(models.Model):

recirc_content = models.ManyToManyField(Content, related_name='liveblog_entry_recirc')

def get_absolute_url(self):
return '{}?entry={}'.format(self.liveblog.get_absolute_url(), self.pk)


class LiveBlogResponse(models.Model):

Expand Down
57 changes: 57 additions & 0 deletions bulbs/liveblog/templates/liveblog/bulbs_liveblog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% load ads core betty liveblog_tags %}
<div class="liveblog-cover">
{% cropped content.thumbnail '3x1' 500 %}
</div>
<bulbs-liveblog
firebase-url="{{ FIREBASE_URL }}"
firebase-api-key="{{ FIREBASE_API_KEY }}"
firebase-path="{{ FIREBASE_PUBLIC_ROOT }}/articles/{{ content.id }}/liveblog"
updated-at="{% now 'c' %}"
liveblog-id="{{ content.id }}"
liveblog-url="{% url 'liveblog-new-entries' slug=content.slug pk=content.pk %}"
>
<div>LIVE COVERAGE</div>

<h1 class="liveblog-title">{{ content.title | safe }}</h1>

{% if content.pinned_content %}
{% with pinned_content=content.pinned_content %}
<div class="liveblog-pinned-article">
<a href="{{ content.get_absolute_url }}">
<div class="liveblog-pinned-image">
{% cropped pinned_content.thumbnail "1x1" 100 %}
</div>

<div class="liveblog-pinned-meta">
<div class="liveblog-pinned-title">
<i class="fa fa-thumb-tack" aria-hidden="true"></i>
{{ pinned_content.title | safe }}
</div>

{% if content.subhead %}
<div class="liveblog-pinned-excerpt">
{{ content.subhead | removetags:"p br" | safe }}
</div>
{% endif %}

<div class="liveblog-published-date"></div>
</div>
</a>
</div>
{% endwith %}
{% endif %}

<div class="liveblog-entries">
{% with entries=content.entries.all %}
{% liveblog_entries_partial %}
{% endwith %}
</div>

<div class="liveblog-more">
<button class="liveblog-more-button">
SHOW MORE
</button>
</div>
</bulbs-liveblog>

{% liveblog_recirc_partial %}
101 changes: 101 additions & 0 deletions bulbs/liveblog/templates/liveblog/entries.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{% load ads betty liveblog_tags %}
{% for entry in entries %}
<div
class="
liveblog-entry
{% if request.GET.entry == entry.id %}
liveblog-entry-shared
{% endif %}
"
entry-url="{{ entry.get_absolute_url }}"
>

{% if request.GET.entry == entry.id %}
<button class="liveblog-entry-reset">
PUT BACK IN ORDER &times;
</button>
{% endif %}

<div class="liveblog-entry-header">
<div class="liveblog-avatar">
{% cropped entry.authors.all.0.avatar '1x1' 100 %}
</div>

<div class="liveblog-entry-meta">
<div class="liveblog-author-name">
<a href="{{ entry.authors.all.0.get_absolute_url }}">
{{ entry.authors.all.0.first_name }} {{ entry.authors.all.0.last_name }}
</a>
</div>
<div class="liveblog-published-time">6:27 AM</div>
<div class="liveblog-published-date">JULY 19TH, 2016</div>
</div>

</div>

<h1 class="liveblog-entry-headline">
<a href="{{ entry.get_absolute_url }}">
{{ entry.headline | safe }}
</a>
</h1>

<div class="liveblog-entry-body">
{{ entry.body | safe }}
</div>

{% for response in entry.responses.all %}
<div class="liveblog-response">
<div class="liveblog-avatar">
{% cropped response.author.avatar '1x1' 100 %}
</div>

<div class="liveblog-response-content">
<div class="liveblog-author-name">
<a href="{{ response.author.get_absolute_url }}">
{{ response.author.first_name }} {{ response.author.last_name }}
</a>
</div>

<div class="liveblog-response-body">
{{ response.body | safe }}
</div>
</div>
</div>
{% endfor %}


{% if entry.recirc_content.all %}
<div class="liveblog-related-header">
RELATED
</div>

{% for recirc_item in entry.recirc_content.all %}
<div class="liveblog-related-article">
<a href="{{ recirc_item.get_absolute_url }}">
<div class="liveblog-related-image">
{% cropped recirc_item.thumbnail "1x1" 100 %}
</div>

<div class="liveblog-related-meta">
<div class="liveblog-related-title">
{{ recirc_item.title | safe }}
</div>

{% if content.subhead %}
<div class="liveblog-related-excerpt">
{{ content.subhead | removetags:"p br" | safe }}
</div>
{% endif %}

<div class="liveblog-published-date"></div>
</div>
</a>
</div>
{% endfor %}
{% endif %}

{% liveblog_entry_sharetools_partial %}

</div>
{% endfor %}

4 changes: 4 additions & 0 deletions bulbs/liveblog/templates/liveblog/entry_sharetools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span>
Place an entry sharetools partial at: <code>templates/liveblog/entry_sharetools_override.html</code>
</span>

2 changes: 2 additions & 0 deletions bulbs/liveblog/templates/liveblog/new_entries.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load liveblog_tags %}
{% liveblog_entries_partial %}
3 changes: 3 additions & 0 deletions bulbs/liveblog/templates/liveblog/recirc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span>
Place a recirc partial at: <code>templates/liveblog/recirc_override.html</code>
</span>
Empty file.
47 changes: 47 additions & 0 deletions bulbs/liveblog/templatetags/liveblog_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from django import template
from bulbs.utils.methods import get_overridable_template_name

register = template.Library()

# Liveblog Template
liveblog_template_name = get_overridable_template_name(
'liveblog/bulbs_liveblog.html',
'liveblog/liveblog_override.html')


@register.inclusion_tag(liveblog_template_name, takes_context=True)
def liveblog_partial(context):
return context

# Entries Template
entries_template_name = get_overridable_template_name(
'liveblog/entries.html',
'liveblog/entries_override.html',
must_inherit=False)


@register.inclusion_tag(entries_template_name, takes_context=True)
def liveblog_entries_partial(context):
return context

# Recirc Template
recirc_template_name = get_overridable_template_name(
'liveblog/recirc.html',
'liveblog/recirc_override.html',
must_inherit=False)


@register.inclusion_tag(recirc_template_name, takes_context=True)
def liveblog_recirc_partial(context):
return context

# Sharetools Template
entry_sharetools_template_name = get_overridable_template_name(
'liveblog/entry_sharetools.html',
'liveblog/entry_sharetools_override.html',
must_inherit=False)


@register.inclusion_tag(entry_sharetools_template_name, takes_context=True)
def liveblog_entry_sharetools_partial(context):
return context
23 changes: 23 additions & 0 deletions bulbs/liveblog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.views.decorators.cache import cache_control
from django.views.generic import TemplateView

LiveBlogModel = get_model(settings.BULBS_LIVEBLOG_MODEL)


class LiveblogNewEntriesView(TemplateView):
template_name = 'liveblog/new_entries.html'

def get_context_data(self, slug, pk):
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)
return context

liveblog_new_entries = cache_control(max_age=600)(LiveblogNewEntriesView.as_view())
Loading

0 comments on commit d52c758

Please sign in to comment.