From d5f461d87963c7952b24fac13b66a465074965de Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 30 Dec 2016 23:09:01 -0500 Subject: [PATCH] news: Refactor press release rendering into a partial. Same rationale as a few commits ago for blog entries. --- www/conservancy/templates/frontpage.html | 25 +++------- .../news/pressrelease_archive_day.html | 9 +--- .../news/pressrelease_archive_month.html | 9 +--- .../news/pressrelease_archive_year.html | 8 +-- .../templates/news/pressrelease_detail.html | 10 +--- .../templates/news/pressrelease_list.html | 14 +++--- .../templates/news/pressrelease_partial.html | 49 +++++++++++++++++++ 7 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 www/conservancy/templates/news/pressrelease_partial.html diff --git a/www/conservancy/templates/frontpage.html b/www/conservancy/templates/frontpage.html index 7f5cbde3..a46bd014 100644 --- a/www/conservancy/templates/frontpage.html +++ b/www/conservancy/templates/frontpage.html @@ -26,24 +26,13 @@

[RSS] Recent News

-

{{ press_releases.0.pub_date|date:"F j, Y" }}

-

{{ press_releases.0.headline|safe }}

-{{ press_releases.0.summary|safe }} -{% if press_releases.0.body %}

Read More...

{% endif %} -{% if press_releases.1 and press_releases.1.pub_date|date_within_past_days:30 %} -
-

{{ press_releases.1.pub_date|date:"F j, Y" }}

-

{{ press_releases.1.headline|safe }}

-{{ press_releases.1.summary|safe }} -{% if press_releases.1.body %}

Read More...

{% endif %} -{% endif %} -{% if press_releases.2 and press_releases.2.pub_date|date_within_past_days:30 %} -
-

{{ press_releases.2.pub_date|date:"F j, Y" }}

-

{{ press_releases.2.headline|safe }}

-{{ press_releases.2.summary|safe }} -{% if press_releases.2.body %}

Read More...

{% endif %} -{% endif %} +{% for pressr in press_releases|slice:":5" %} + {% if forloop.first or pressr.pub_date|date_within_past_days:30 %} + {% if not forloop.first %}
{% endif %} + {% include "news/pressrelease_partial.html" with pressr=pressr show="summary" only %} + {% endif %} +{% endfor %} +

Conservancy News Archive…

diff --git a/www/conservancy/templates/news/pressrelease_archive_day.html b/www/conservancy/templates/news/pressrelease_archive_day.html index a6af5bac..a37db77a 100644 --- a/www/conservancy/templates/news/pressrelease_archive_day.html +++ b/www/conservancy/templates/news/pressrelease_archive_day.html @@ -6,13 +6,8 @@

Conservancy News Index - {{ day|date:"F j, Y" }}

- - {% endblock %} diff --git a/www/conservancy/templates/news/pressrelease_archive_month.html b/www/conservancy/templates/news/pressrelease_archive_month.html index 1f44e799..fabe7637 100644 --- a/www/conservancy/templates/news/pressrelease_archive_month.html +++ b/www/conservancy/templates/news/pressrelease_archive_month.html @@ -6,13 +6,8 @@

Conservancy News Index - {{ month|date:"F Y" }}

- - {% endblock %} diff --git a/www/conservancy/templates/news/pressrelease_archive_year.html b/www/conservancy/templates/news/pressrelease_archive_year.html index fb6d5e56..231cd806 100644 --- a/www/conservancy/templates/news/pressrelease_archive_year.html +++ b/www/conservancy/templates/news/pressrelease_archive_year.html @@ -7,13 +7,9 @@

Conservancy News Index - {{ year|date:"Y" }}

-
{% endblock %} diff --git a/www/conservancy/templates/news/pressrelease_detail.html b/www/conservancy/templates/news/pressrelease_detail.html index a7135c2e..ce2d24ec 100644 --- a/www/conservancy/templates/news/pressrelease_detail.html +++ b/www/conservancy/templates/news/pressrelease_detail.html @@ -5,14 +5,6 @@ {% block content %}
-

{{ object.pub_date|date:"F j, Y" }}

-

{{ object.headline|safe }}

-{% if object.subhead %} -

{{ object.subhead|safe }}

-{% endif %} - -{{ object.summary|safe }} - -{{ object.body|safe }} +{% include "news/pressrelease_partial.html" with pressr=object htag="h2" only %}
{% endblock %} diff --git a/www/conservancy/templates/news/pressrelease_list.html b/www/conservancy/templates/news/pressrelease_list.html index 074581d6..b3132ff3 100644 --- a/www/conservancy/templates/news/pressrelease_list.html +++ b/www/conservancy/templates/news/pressrelease_list.html @@ -15,14 +15,12 @@ {% ifnotequal news.number 1 %}

(Page {{ news.number }} of {{ news.paginator.num_pages }})

{% endifnotequal %} -{% for news_item in news %} -

{{ news_item.pub_date|date:"F j, Y" }}

-

{{ news_item.headline|safe }}

- {% if news_item.is_recent %} - {% if news_item.subhead %}

{{ news_item.subhead|safe }}

{% endif %} - {{ news_item.summary|safe }} - {% if news_item.body %}

Read More...

{% endif %} - {% endif %} +{% for pressr in news %} + {% if pressr.is_recent %} + {% include "news/pressrelease_partial.html" with pressr=pressr show="summary" only %} + {% else %} + {% include "news/pressrelease_partial.html" with pressr=pressr show="dateline" only %} + {% endif %} {% endfor %}

diff --git a/www/conservancy/templates/news/pressrelease_partial.html b/www/conservancy/templates/news/pressrelease_partial.html new file mode 100644 index 00000000..dc0fb687 --- /dev/null +++ b/www/conservancy/templates/news/pressrelease_partial.html @@ -0,0 +1,49 @@ +{% comment %} + +This partial requires these parameters: + +* `pressr`: The PressRelease object to render. + +This partial accepts these optional parameters: + +* `show`: How much of the PressRelease to render. Accepted values are + "headline", "dateline", "subhead", "summary", and "body". + Every value will render the parts listed before it. Default "body". +* `htag`: Name of the HTML tag to render the pressr headline. + If you're passing show="subhead" or a greater detail level, this + must be a headline tag h1 through h5, inclusive. Default "h3". + +{% endcomment %} + +

+ +<{{ htag|default:"h3" }} class="clear" + >{% if show|default:"body" != "body" %}{% endif %}{{ pressr.headline|safe }}{% if show|default:"body" != "body" %}{% endif %} + +{% if show != "headline" %} +{% if show != "dateline" and pressr.subhead %} + {# This filter sequence generates the "next" hN tag from htag #} + {{ pressr.subhead|safe }} +{% endif %} + +

{{ pressr.pub_date|date:"F j, Y" }}

+ +{% if show != "dateline" and show != "subhead" %} + {% if pressr.summary %} + {{ pressr.summary|safe }} + {% endif %} + + {% if pressr.body %} + {% if show == "summary" %} +

Read More…

+ {% else %} + {{ pressr.body|safe }} + {% endif %} + {% endif %} +{% endif %} + +{% endif %}{# show != "headline" #} + +