news: Refactor press release rendering into a partial.

Same rationale as a few commits ago for blog entries.
This commit is contained in:
Brett Smith 2016-12-30 23:09:01 -05:00
parent 7f5f98e5db
commit d5f461d879
7 changed files with 69 additions and 55 deletions

View file

@ -26,24 +26,13 @@
<div class="column"> <div class="column">
<h2><a href="/feeds/news/" class="feedlink"><img src="/img/feed-icon-14x14.png" alt="[RSS]"/></a> <a href="/news/">Recent News</a></h2> <h2><a href="/feeds/news/" class="feedlink"><img src="/img/feed-icon-14x14.png" alt="[RSS]"/></a> <a href="/news/">Recent News</a></h2>
<p class="date">{{ press_releases.0.pub_date|date:"F j, Y" }}</p> {% for pressr in press_releases|slice:":5" %}
<h3><a href="{{ press_releases.0.get_absolute_url }}">{{ press_releases.0.headline|safe }}</a></h3> {% if forloop.first or pressr.pub_date|date_within_past_days:30 %}
{{ press_releases.0.summary|safe }} {% if not forloop.first %}<hr class="clear">{% endif %}
{% if press_releases.0.body %}<p><span class="continued"><a href="{{ press_releases.0.get_absolute_url }}">Read More...</a></span></p>{% endif %} {% include "news/pressrelease_partial.html" with pressr=pressr show="summary" only %}
{% if press_releases.1 and press_releases.1.pub_date|date_within_past_days:30 %} {% endif %}
<hr/> {% endfor %}
<p class="date">{{ press_releases.1.pub_date|date:"F j, Y" }}</p>
<h3><a href="{{ press_releases.1.get_absolute_url }}">{{ press_releases.1.headline|safe }}</a></h3>
{{ press_releases.1.summary|safe }}
{% if press_releases.1.body %}<p><span class="continued"><a href="{{ press_releases.1.get_absolute_url }}">Read More...</a></span></p>{% endif %}
{% endif %}
{% if press_releases.2 and press_releases.2.pub_date|date_within_past_days:30 %}
<hr/>
<p class="date">{{ press_releases.2.pub_date|date:"F j, Y" }}</p>
<h3><a href="{{ press_releases.2.get_absolute_url }}">{{ press_releases.2.headline|safe }}</a></h3>
{{ press_releases.2.summary|safe }}
{% if press_releases.2.body %}<p><span class="continued"><a href="{{ press_releases.2.get_absolute_url }}">Read More...</a></span></p>{% endif %}
{% endif %}
<p><span class="continued"><a href="/news/">Conservancy News Archive&hellip;</a></span></p> <p><span class="continued"><a href="/news/">Conservancy News Archive&hellip;</a></span></p>
</div> </div>

View file

@ -6,13 +6,8 @@
<h2>Conservancy News Index - {{ day|date:"F j, Y" }}</h2> <h2>Conservancy News Index - {{ day|date:"F j, Y" }}</h2>
<ul> {% for pressr in object_list %}
{% include "news/pressrelease_partial.html" with pressr=pressr show="dateline" only %}
{% for object in object_list %}
<li><a href="{{ object.get_absolute_url }}"><b>{{ object.headline|safe }}</b></a><br/>
<i>{{ object.pub_date|date:"F j, Y" }}</i></li>
{% endfor %} {% endfor %}
</ul>
{% endblock %} {% endblock %}

View file

@ -6,13 +6,8 @@
<h2>Conservancy News Index - {{ month|date:"F Y" }}</h2> <h2>Conservancy News Index - {{ month|date:"F Y" }}</h2>
<ul> {% for pressr in object_list %}
{% include "news/pressrelease_partial.html" with pressr=pressr show="dateline" only %}
{% for object in object_list %}
<li><a href="{{ object.get_absolute_url }}"><b>{{ object.headline|safe }}</b></a><br/>
<i>{{ object.pub_date|date:"F j, Y" }}</i></li>
{% endfor %} {% endfor %}
</ul>
{% endblock %} {% endblock %}

View file

@ -7,13 +7,9 @@
<div id="mainContent"> <div id="mainContent">
<h2>Conservancy News Index - {{ year|date:"Y" }}</h2> <h2>Conservancy News Index - {{ year|date:"Y" }}</h2>
<ul> {% for pressr in object_list %}
{% include "news/pressrelease_partial.html" with pressr=pressr show="dateline" only %}
{% for object in object_list %}
<li><a href="{{ object.get_absolute_url }}"><b>{{ object.headline|safe }}</b></a><br/>
<i>{{ object.pub_date|date:"F j, Y" }}</i></li>
{% endfor %} {% endfor %}
</ul>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -5,14 +5,6 @@
{% block content %} {% block content %}
<div id="mainContent"> <div id="mainContent">
<p class="date">{{ object.pub_date|date:"F j, Y" }}</p> {% include "news/pressrelease_partial.html" with pressr=object htag="h2" only %}
<h2>{{ object.headline|safe }}</h2>
{% if object.subhead %}
<h3>{{ object.subhead|safe }}</h3>
{% endif %}
{{ object.summary|safe }}
{{ object.body|safe }}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -15,13 +15,11 @@
{% ifnotequal news.number 1 %}<p>(Page {{ news.number }} of {{ news.paginator.num_pages }})</p>{% endifnotequal %} {% ifnotequal news.number 1 %}<p>(Page {{ news.number }} of {{ news.paginator.num_pages }})</p>{% endifnotequal %}
{% for news_item in news %} {% for pressr in news %}
<p class="date">{{ news_item.pub_date|date:"F j, Y" }}</p> {% if pressr.is_recent %}
<h3><a href="{{ news_item.get_absolute_url }}">{{ news_item.headline|safe }}</a></h3> {% include "news/pressrelease_partial.html" with pressr=pressr show="summary" only %}
{% if news_item.is_recent %} {% else %}
{% if news_item.subhead %}<h4>{{ news_item.subhead|safe }}</h4>{% endif %} {% include "news/pressrelease_partial.html" with pressr=pressr show="dateline" only %}
{{ news_item.summary|safe }}
{% if news_item.body %}<p><span class="continued"><a href="{{ news_item.get_absolute_url }}">Read More...</a></span></p>{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View file

@ -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 %}
<div class="press-release">
<{{ htag|default:"h3" }} class="clear"
>{% if show|default:"body" != "body" %}<a href="{{ pressr.get_absolute_url }}"
>{% endif %}{{ pressr.headline|safe }}{% if show|default:"body" != "body" %}</a>{% endif %}</{{ htag|default:"h3" }}>
{% if show != "headline" %}
{% if show != "dateline" and pressr.subhead %}
{# This filter sequence generates the "next" hN tag from htag #}
<h{{ htag|default:"3"|last|get_digit:1|add:1 }}
>{{ pressr.subhead|safe }}</h{{ htag|default:"3"|last|get_digit:1|add:1 }}>
{% endif %}
<p class="date">{{ pressr.pub_date|date:"F j, Y" }}</p>
{% if show != "dateline" and show != "subhead" %}
{% if pressr.summary %}
{{ pressr.summary|safe }}
{% endif %}
{% if pressr.body %}
{% if show == "summary" %}
<p><a class="continued" href="{{ pressr.get_absolute_url }}">Read More&hellip;</a></p>
{% else %}
{{ pressr.body|safe }}
{% endif %}
{% endif %}
{% endif %}
{% endif %}{# show != "headline" #}
</div>