Josh VanderLinden avatar Josh VanderLinden committed e64d50d

Updating feeds for Django 1.2+; adding Atom feeds to the stock templates; showing number of articles that a tag has been applied to in the admin

Comments (0)

Files changed (10)

articles/admin.py

 from forms import ArticleAdminForm
 from models import Tag, Article, ArticleStatus, Attachment
 
+class TagAdmin(admin.ModelAdmin):
+    list_display = ('name', 'article_count')
+
+    def article_count(self, obj):
+        return obj.article_set.count()
+    article_count.short_description = _('Applied To')
+
 class ArticleStatusAdmin(admin.ModelAdmin):
     list_display = ('name', 'is_live')
     list_filter = ('is_live',)
         else:
             return self.model._default_manager.filter(author=request.user)
 
-admin.site.register(Tag)
+admin.site.register(Tag, TagAdmin)
 admin.site.register(Article, ArticleAdmin)
 admin.site.register(ArticleStatus, ArticleStatusAdmin)
 

articles/feeds.py

 from django.conf import settings
-from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
+from django.contrib.syndication.views import Feed, FeedDoesNotExist
 from django.contrib.sites.models import Site
 from django.core.cache import cache
 from django.core.urlresolvers import reverse

articles/models.py

 
     @property
     def rss_name(self):
-        return u'tags/%s' % self.cleaned
+        return self.cleaned
 
     class Meta:
         ordering = ('name',)

articles/templates/articles/_meta.html

 {% load i18n humanize %}
 
 <div id="article-meta">
-    <h4>Meta</h4>
+  <h4>Meta</h4>
 
-    <p><strong>{% trans 'Published' %}</strong>: {{ article.publish_date|naturalday }}</p>
+  <p><strong>{% trans 'Published' %}</strong>: {{ article.publish_date|naturalday }}</p>
 
-    <p><strong>{% trans 'Author' %}</strong>: <a href="{% url articles_by_author article.author.username %}" title="{% trans 'Read other articles by this author' %}">{{ article.author.get_name }}</a></p>
+  <p><strong>{% trans 'Author' %}</strong>: <a href="{% url articles_by_author article.author.username %}" title="{% trans 'Read other articles by this author' %}">{{ article.author.get_name }}</a></p>
 
-    <p><strong>{% trans 'Comments' %}</strong>: <a href="#disqus_thread">&nbsp;</a></p>
+  <p><strong>{% trans 'Comments' %}</strong>: <a href="#disqus_thread">&nbsp;</a></p>
 
-    <p><strong>{% trans 'Word Count' %}</strong>: {{ article.word_count|intcomma }}</p>
+  <p><strong>{% trans 'Word Count' %}</strong>: {{ article.word_count|intcomma }}</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_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.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 -->
-    <div>
-        <script type="application/javascript">var addthis_pub="{{ article.addthis_username }}";</script>
-        <a href="http://www.addthis.com/bookmark.php?v=20" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a>
-        <script type="application/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script>
-    </div>
-    <!-- AddThis Button END -->
-    {% endif %}
+  {% if article.use_addthis_button and article.addthis_username %}
+  <!-- AddThis Button BEGIN -->
+  <div>
+    <script type="application/javascript">var addthis_pub="{{ article.addthis_username }}";</script>
+    <a href="http://www.addthis.com/bookmark.php?v=20" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a>
+    <script type="application/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script>
+  </div>
+  <!-- AddThis Button END -->
+  {% endif %}
 
-    <script type="application/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
+  <script type="application/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
 
-    <h4>{% trans 'Tags' %}</h4>
-    <p>{% if article.tags.count %}{% for tag in article.tags.all %}<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> {% endfor %}{% else %}None{% endif %}</p>
+  <h4>{% trans 'Tags' %}</h4>
+  <p>{% if article.tags.count %}{% for tag in article.tags.all %}<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> {% endfor %}{% else %}None{% endif %}</p>
 
-    {% for fu in article.followups.live %}
-    {% if forloop.first %}<h4 class="hasfollowup-header">{% trans 'Follow-Up Articles' %}</h4>
+  {% for fu in article.followups.live %}
+  {% 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 %}
+  <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 %}
 
-    {% for fu in article.followup_for.live %}
-    {% if forloop.first %}<h4 class="followup-header">{% trans 'Follows Up On' %}</h4>
+  {% for fu in article.followup_for.live %}
+  {% 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 %}
+  <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 %}
 
-    {% for ra in article.related_articles.live %}
-    {% if forloop.first %}<h4 class="related-header">{% trans 'Related Articles' %}</h4>
+  {% for ra in article.related_articles.live %}
+  {% 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 %}
+  <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 %}
 
-    {% for url,title in article.links %}
-    {% if forloop.first %}<h4>{% trans 'Article Links' %}</h4>
-    <ol>{% endif %}
-        <li><a href="{{ url }}" title="{{ title }}">{{ title|safe|truncatewords:10 }}</a></li>
-    {% if forloop.last %}</ol>{% endif %}
-    {% endfor %}
+  {% for url,title in article.links %}
+  {% if forloop.first %}<h4>{% trans 'Article Links' %}</h4>
+  <ol>{% endif %}
+    <li><a href="{{ url }}" title="{{ title }}">{{ title|safe|truncatewords:10 }}</a></li>
+  {% if forloop.last %}</ol>{% endif %}
+  {% endfor %}
 </div>
 <div class="clear"></div>
 

articles/templates/articles/_tag_cloud.html

 <div id="articles-tag-cloud">
-    {% for tag in tags %}
-    <a href="{{ tag.get_absolute_url }}" class="tag-cloud-{{ tag.weight }}">{{ tag.name }}</a>
-    {% endfor %}
+  {% for tag in tags %}
+  <a href="{{ tag.get_absolute_url }}" class="tag-cloud-{{ tag.weight }}">{{ tag.name }}</a>
+  {% endfor %}
 </div>

articles/templates/articles/article_detail.html

 {% block extra-head %}
 {{ block.super }}
 {% for tag in article.tags.all %}
-<link rel="alternate" type="application/rss+xml" title="Blog Articles Tagged '{{ tag.name }}' RSS Feed" href="{% url articles_feed tag.rss_name %}" />{% endfor %}
+<link rel="alternate" type="application/rss+xml" title="Blog Articles Tagged '{{ tag.name }}' RSS Feed" href="{% url articles_rss_feed_tag tag.rss_name %}" />
+<link rel="alternate" type="application/atom+xml" title="Blog Articles Tagged '{{ tag.name }}' Atom Feed" href="{% url articles_atom_feed_tag tag.rss_name %}" />{% endfor %}
 {% endblock %}
 
 {% block content %}

articles/templates/articles/base.html

 
 {% block extra-head %}
 {{ block.super }}
-<link rel="alternate" type="application/rss+xml" title="Latest Blog Articles RSS Feed" href="{% url articles_feed 'latest' %}" />
+<link rel="alternate" type="application/rss+xml" title="Latest Blog Articles RSS Feed" href="{% url articles_rss_feed_latest %}" />
+<link rel="alternate" type="application/atom+xml" title="Latest Blog Articles Atom Feed" href="{% url articles_atom_feed_latest %}" />
 {% endblock %}
 
 {% block content %}

articles/templates/articles/display_tag.html

 {% block title %}{% trans 'Articles Tagged' %}: {{ tag.name }}{% endblock %}
 {% block extra-head %}
 {{ block.super }}
-<link rel="alternate" type="application/rss+xml" title="Blog Articles Tagged '{{ tag.name }}' RSS Feed" href="{% url articles_feed tag.rss_name %}" />
+<link rel="alternate" type="application/rss+xml" title="Blog Articles Tagged '{{ tag.name }}' RSS Feed" href="{% url articles_rss_feed_tag tag.rss_name %}" />
+<link rel="alternate" type="application/atom+xml" title="Blog Articles Tagged '{{ tag.name }}' Atom Feed" href="{% url articles_atom_feed_tag tag.rss_name %}" />
 {% endblock %}
 
 {% block articles-content %}

articles/templates/articles/uncategorized_article_list.html

 {% for article in page_obj.object_list %}
 {% include 'articles/_articles.html' %}
 {% endfor %}
-{% endblock %}
+{% endblock %}
 from django.conf.urls.defaults import *
-from django.contrib.syndication.views import feed
 
 from articles import views
 from articles.feeds import TagFeed, LatestEntries, TagFeedAtom, LatestEntriesAtom
 
-feeds = {
-  'latest': LatestEntries,
-  'tags': TagFeed
-}
-feed_dict = {'feed_dict': feeds}
-
-atom_feeds = {
-    'latest': LatestEntriesAtom,
-    'tags': TagFeedAtom,
-}
-atom_dict = {'feed_dict': atom_feeds}
+tag_rss = TagFeed()
+latest_rss = LatestEntries()
+tag_atom = TagFeedAtom()
+latest_atom = LatestEntriesAtom()
 
 urlpatterns = patterns('',
     (r'^(?P<year>\d{4})/(?P<month>.{3})/(?P<day>\d{1,2})/(?P<slug>.*)/$', views.redirect_to_article),
     url(r'^ajax/tag/autocomplete/$', views.ajax_tag_autocomplete, name='articles_tag_autocomplete'),
 
     # RSS
-    url(r'^feeds/atom/(?P<url>.*)\.xml$', feed, atom_dict, name='articles_feed_atom'),
-    (r'^feeds/(?P<url>.*)/$', feed, feed_dict),
-    url(r'^feeds/(?P<url>.*)\.rss$', feed, feed_dict, name='articles_feed'),
+    url(r'^feeds/latest\.rss$', latest_rss, name='articles_rss_feed_latest'),
+    url(r'^feeds/latest/$', latest_rss),
+    url(r'^feeds/tag/(?P<slug>[\w_-]+)\.rss$', tag_rss, name='articles_rss_feed_tag'),
+    url(r'^feeds/tag/(?P<slug>[\w_-]+)/$', tag_rss),
+
+    # Atom
+    url(r'^feeds/atom/latest\.xml$', latest_atom, name='articles_atom_feed_latest'),
+    url(r'^feeds/atom/tag/(?P<slug>[\w_-]+)\.xml$', tag_atom, name='articles_atom_feed_tag'),
 
 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.