From c0b1d62e024f53aa4afd0d6d96f3b141718c804f Mon Sep 17 00:00:00 2001 From: "Collin Miller (Zardulist)" Date: Thu, 1 Sep 2016 13:33:03 -0500 Subject: [PATCH] liveblog templatetags --- .../templates/liveblog/bulbs_liveblog.html | 123 ++++++++++++++++++ .../templates/liveblog/entry_sharetools.html | 4 + bulbs/liveblog/templates/liveblog/recirc.html | 3 + bulbs/liveblog/templatetags/__init__.py | 0 bulbs/liveblog/templatetags/liveblog_tags.py | 33 +++++ bulbs/utils/methods.py | 4 +- 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 bulbs/liveblog/templates/liveblog/bulbs_liveblog.html create mode 100644 bulbs/liveblog/templates/liveblog/entry_sharetools.html create mode 100644 bulbs/liveblog/templates/liveblog/recirc.html create mode 100644 bulbs/liveblog/templatetags/__init__.py create mode 100644 bulbs/liveblog/templatetags/liveblog_tags.py diff --git a/bulbs/liveblog/templates/liveblog/bulbs_liveblog.html b/bulbs/liveblog/templates/liveblog/bulbs_liveblog.html new file mode 100644 index 00000000..609a314a --- /dev/null +++ b/bulbs/liveblog/templates/liveblog/bulbs_liveblog.html @@ -0,0 +1,123 @@ +{% load ads core betty liveblog_tags %} +
+
LIVE COVERAGE
+

{{ content.title | safe }}

+ + + {% if content.pinned_content %} + {% with pinned_content=content.pinned_content %} +
+ +
+ {% cropped pinned_content.thumbnail "1x1" 100 %} +
+ +
+
+ + {{ pinned_content.title | safe }} +
+ + {% if content.subhead %} +
+ {{ content.subhead | removetags:"p br" | safe }} +
+ {% endif %} + +
+
+
+
+ {% endwith %} + {% endif %} +
+ +{% for entry in content.entries.all %} +
+ +
+
+ {% cropped entry.authors.all.0.avatar '1x1' 100 %} +
+ + +
+ +

{{ entry.headline | safe }}

+ +
+ {{ entry.body | safe }} +
+ + {% for response in entry.responses.all %} +
+
+ {% cropped response.author.avatar '1x1' 100 %} +
+ + +
+ {% endfor %} + + + {% if entry.recirc_content.all %} + + + {% for recirc_item in entry.recirc_content.all %} +
+ + + + + +
+ {% endfor %} + {% endif %} + + {% liveblog_entry_sharetools_partial %} + +
+{% endfor %} + +
+ +
+ + +{% liveblog_recirc_partial %} diff --git a/bulbs/liveblog/templates/liveblog/entry_sharetools.html b/bulbs/liveblog/templates/liveblog/entry_sharetools.html new file mode 100644 index 00000000..c1e3c3b4 --- /dev/null +++ b/bulbs/liveblog/templates/liveblog/entry_sharetools.html @@ -0,0 +1,4 @@ + + Place an entry sharetools partial at: templates/liveblog/entry_sharetools_override.html + + diff --git a/bulbs/liveblog/templates/liveblog/recirc.html b/bulbs/liveblog/templates/liveblog/recirc.html new file mode 100644 index 00000000..dabd9517 --- /dev/null +++ b/bulbs/liveblog/templates/liveblog/recirc.html @@ -0,0 +1,3 @@ + + Place a recirc partial at: templates/liveblog/recirc_override.html + diff --git a/bulbs/liveblog/templatetags/__init__.py b/bulbs/liveblog/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bulbs/liveblog/templatetags/liveblog_tags.py b/bulbs/liveblog/templatetags/liveblog_tags.py new file mode 100644 index 00000000..b282f3da --- /dev/null +++ b/bulbs/liveblog/templatetags/liveblog_tags.py @@ -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 diff --git a/bulbs/utils/methods.py b/bulbs/utils/methods.py index 304cb3fa..73227b4b 100644 --- a/bulbs/utils/methods.py +++ b/bulbs/utils/methods.py @@ -78,7 +78,7 @@ 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: @@ -86,7 +86,7 @@ def get_overridable_template_name(parent_name, 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(