changeset 40:5c0f9d80442e

I added a news template tag that's a blatant rip off of Chris' review one.
author Bob Mourlam <bob.mourlam@gmail.com>
date Sun, 06 Nov 2011 21:16:22 -0600
parents b9d6f6d930a9
children 9ce9f77d6cde
files bns_website/news/templatetags/__init__.py bns_website/news/templatetags/news_tags.py bns_website/templates/home.html bns_website/templates/news/news_tag.html
diffstat 3 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bns_website/news/templatetags/news_tags.py	Sun Nov 06 21:16:22 2011 -0600
@@ -0,0 +1,11 @@
+from django import template
+from news.models import News
+
+register = template.Library()
+
+"""
+Display a list of the last num_to_display news items.
+"""
+@register.inclusion_tag('news/news_tag.html')
+def list_news(num_to_display):
+    return {'object_list': News.objects.all()[:num_to_display]}
\ No newline at end of file
--- a/bns_website/templates/home.html	Sun Nov 06 20:28:25 2011 -0600
+++ b/bns_website/templates/home.html	Sun Nov 06 21:16:22 2011 -0600
@@ -1,6 +1,6 @@
 {% extends 'base.html' %}
 {% load url from future %}
-{% load core_tags reviews_tags %}
+{% load core_tags reviews_tags news_tags%}
 {% block title %}Home{% endblock %}
 {% block custom_meta %}
 <meta property="og:title" content="Brave New Surf" />
@@ -85,12 +85,7 @@
    <div class="span7">
       <div class="alert-message block-message info">
          <h3>News</h3>
-         <p>This box shows links to the 5 most recent news items.</p>
-         <ul>
-            <li><a href="#">Headline number 3 goes here.</a> - <small>Oct. 29, 2011</small></li>
-            <li><a href="#">Headline number 2 goes here.</a> - <small>Oct. 12, 2011</small></li>
-            <li><a href="#">Headline number 1 goes here.</a> - <small>Oct. 2, 2011</small></li>
-         </ul>
+         {% list_news 5 %}
          <p><br /><a class="btn default" href="{% url 'news' %}">All News &raquo;</a></p>
       </div>
       <div class="alert-message block-message info">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bns_website/templates/news/news_tag.html	Sun Nov 06 21:16:22 2011 -0600
@@ -0,0 +1,6 @@
+{% load url from future %}
+<ul>
+{% for news in object_list %}
+  <li>{{ news.title }}</li>
+{% endfor %}
+</ul>