From d5f461d87963c7952b24fac13b66a465074965de 2016-12-31 04:12:09 From: Brett Smith Date: 2016-12-31 04:12:09 Subject: [PATCH] news: Refactor press release rendering into a partial. Same rationale as a few commits ago for blog entries. --- diff --git a/www/conservancy/templates/frontpage.html b/www/conservancy/templates/frontpage.html index 7f5cbde377beaf7f747762eb8f9b17eba90ba857..a46bd01493ede0b6cb1cab130d4aaa5c93df4a68 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 a6af5bac73b76592be8c4ceb12661db59c4f5418..a37db77aec1a058d84363ff375e5776e69098ed3 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 1f44e7996e0c6be6fdf740bfe7b8419de5580bf1..fabe7637742bb0522c3563135cd726e8747d8832 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 fb6d5e5649ac432aafb2f95f5e8b0ea6f6a173a3..231cd806fbf9d45734ff99d12726b5628d04ff3c 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 a7135c2ed5703a5b544d4db493d70e4b3320c337..ce2d24ecec9279f3ec5ab0b1d3aaf6ba53c53ef1 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 074581d686e731fe43e4dba70bc60d336f9858d3..b3132ff3db1494121e0e8541e9f914cf08f35678 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 0000000000000000000000000000000000000000..dc0fb6877e242df693da2cc984b0ce57803c9775 --- /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" #} + +