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

Commit

Permalink
liveblog templatetags
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Sep 1, 2016
1 parent 1f1abc0 commit c0b1d62
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 2 deletions.
123 changes: 123 additions & 0 deletions bulbs/liveblog/templates/liveblog/bulbs_liveblog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{% load ads core betty liveblog_tags %}
<div class="liveblog">
<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="#">
<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>

{% for entry in content.entries.all %}
<div class="liveblog-entry">

<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">{{ entry.headline | safe }}</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="#">
<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 %}

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


{% liveblog_recirc_partial %}
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>

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.
33 changes: 33 additions & 0 deletions bulbs/liveblog/templatetags/liveblog_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django import template
from bulbs.utils.methods import get_overridable_template_name

register = template.Library()

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

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

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
4 changes: 2 additions & 2 deletions bulbs/utils/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ def get_template_choices():
return ((0, None),) + configured_templates


def get_overridable_template_name(parent_name, child_name):
def get_overridable_template_name(parent_name, child_name, must_inherit=True):
get_template = template.loader.get_template

try:
child_template = get_template(child_name)
except template.loader.TemplateDoesNotExist:
child_template = None

if child_template:
if child_template and must_inherit:
bad_inheritance_message = "{} MUST extend {}".format(child_name, parent_name)

extends_node = child_template.template.nodelist.get_nodes_by_type(
Expand Down

0 comments on commit c0b1d62

Please sign in to comment.