Commits

Josh VanderLinden  committed a7288a6

Fixed the related articles section in article_detail.html and added the next/previous post stuff back

  • Participants
  • Parent commits d30709f

Comments (0)

Files changed (2)

File articles/models.py

         return text
     teaser = property(_get_teaser)
 
+    def get_next_article(self):
+        try:
+            qs = Article.objects.active().exclude(id__exact=self.id)
+            article = qs.filter(publish_date__gte=self.publish_date).order_by('publish_date')[0]
+        except (Article.DoesNotExist, IndexError):
+            article = None
+        return article
+
+    def get_previous_article(self):
+        try:
+            qs = Article.objects.active().exclude(id__exact=self.id)
+            article = qs.filter(publish_date__lte=self.publish_date).order_by('-publish_date')[0]
+        except (Article.DoesNotExist, IndexError):
+            article = None
+        return article
+
     class Meta:
         ordering = ('-publish_date', 'title')

File articles/templates/articles/article_detail.html

 {% block title %}{% trans article.title %}{% endblock %}
 
 {% block content %}
-<div id="article-content">
+<div id="article-content" class="article">
     <h2 class="title">{% trans article.title %}</h2>
 
     {{ article.rendered_content|safe }}
     <p><strong>{% trans 'Comments' %}</strong>: <a href="#comments">{{ comment_count }}</a></a>
     {% endif %}
 
-    <p><strong>{% trans 'Word Count' %}</strong>: {{ article.word_count|intcomma }}</a>
+    <p><strong>{% trans 'Word Count' %}</strong>: {{ article.word_count|intcomma }}</a></p>
+
+    {% if article.get_next_article %}
+    <p>
+        <strong>{% trans 'Next' %}</strong>:
+        <a href="{{ article.get_next_article.get_absolute_url }}">{{ article.get_next_article.title }}</a>
+    </p>
+    {% endif %}
+
+    {% if article.get_previous_article %}
+    <p>
+        <strong>{% trans 'Previous' %}</strong>:
+        <a href="{{ article.get_previous_article.get_absolute_url }}">{{ article.get_previous_article.title }}</a>
+    </p>
+    {% endif %}
 
     {% if article.use_addthis_button and article.addthis_username %}
     <!-- AddThis Button BEGIN -->
     <h4>{% trans 'Filed Under' %}</h4>
     <p>{% if article.categories.count %}{% for category in article.categories.all %}{% if not forloop.first %}{% ifnotequal article.categories.count 2 %},{% endifnotequal %} {% if forloop.last %}{% trans 'and' %}{% endif %} {% endif %}<a href="{% url articles_display_category category.slug %}" title="{% trans 'View all articles in this category' %}">{{ category }}</a>{% endfor %}{% else %}<a href="{% url articles_display_category 'uncategorized' %}" title="{% trans 'View all uncategorized articles' %}">{% trans 'Uncategorized' %}</a>{% endif %}</p>
 
-    {% if article.followups.active.count %}
-    <h4 class="hasfollowup-header">{% trans 'Follow-Up Articles' %}</h4>
     {% for fu in article.followups.active %}
-    {% if forloop.first %}<ul class="followups">{% endif %}
+    {% if forloop.first %}<h4 class="hasfollowup-header">{% trans 'Follow-Up Articles' %}</h4>
+
+    <ul class="followups">{% endif %}
         <li>
             <a href="{{ fu.get_absolute_url }}" title="{% trans 'Read this follow-up article' %}">{{ fu.title }}</a>, {% trans 'posted' %} {{ fu.publish_date|naturalday }}
         </li>
     {% if forloop.last %}</ul>{% endif %}
     {% endfor %}
-    {% endif %}
 
-    {% if article.followup_for.active.count %}
-    <h4 class="followup-header">Follows Up On</h4>
     {% for fu in article.followup_for.active %}
-    {% if forloop.first %}<ul class="followups">{% endif %}
+    {% if forloop.first %}<h4 class="followup-header">{% trans 'Follows Up On' %}</h4>
+
+    <ul class="followups">{% endif %}
         <li>
             <a href="{{ fu.get_absolute_url }}" title="{% trans 'Read this article' %}">{{ fu.title }}</a>, {% trans 'posted' %} {{ fu.publish_date|naturalday }}
         </li>
     {% if forloop.last %}</ul>{% endif %}
     {% endfor %}
-    {% endif %}
 
-    {% if articles.related_articles.active.count %}
-    <h4 class="related-header">Related Articles</h4>
-    {% for ra in articles.related_articles.active %}
-    {% if forloop.first %}<ul class="related-articles">{% endif %}
+    {% for ra in article.related_articles.active %}
+    {% if forloop.first %}<h4 class="related-header">{% trans 'Related Articles' %}</h4>
+
+    <ul class="related-articles">{% endif %}
         <li>
             <a href="{{ ra.get_absolute_url }}" title="{% trans 'Read this related article' %}">{{ ra.title }}</a>, {% trans 'posted' %}  {{ ra.publish_date|naturalday }}
         </li>
     {% if forloop.last %}</ul>{% endif %}
     {% endfor %}
-    {% endif %}
 
     {% for url,title in article.links %}
     {% if forloop.first %}<h4>{% trans 'Article Links' %}</h4>