Permalink
Browse files

hooray for tags

  • Loading branch information...
1 parent c018942 commit 17edfebf7a9a8eb04badc00d861cbf76dad03d4c Justine Tunney committed Aug 13, 2012
View
@@ -555,6 +555,12 @@ def translate(self, lang):
self.title = trans.title
self.__translated = True
+ @property
+ def taggies(self):
+ if not hasattr(self, "_taggies"):
+ self._taggies = self.tags.all()[:]
+ return self._taggies
+
class ArticleTranslation(models.Model):
article = models.ForeignKey(Article)
@@ -39,4 +39,11 @@
<a class="edit" href="#">{% trans 'edit' %}</a>
<a class="remove" href="#">{% if not article.is_visible %}{% trans 'unremove' %}{% else %}{% trans 'remove' %}{% endif %}</a>
{% endif %}
+ {% if not article.is_forum and article.taggies %}
+ <br/>
+ Tags:
+ {% for tag in article.taggies %}
+ <a href="{% url tag tag.name %}">{{ tag.name }}</a>
+ {% endfor %}
+ {% endif %}
</p>
@@ -0,0 +1,36 @@
+{% extends base %}
+{% load ows i18n l10n %}
+{% block body_class %}tag-page archive-page{% endblock body_class %}
+{% block title %}{{ OWS_SITE_NAME }} articles tagged {{ tag }}{% endblock title %}
+
+{% block content %}
+ <table style="width:100%"><tbody><tr><td id="left">
+ <h1>Articles tagged {{ tag }}</h1>
+ <hr/>
+ <section id="articles">
+ {% with read_more="True" %}
+ {% for article in articles %}
+ {% include "occupywallst/article_content.html" %}
+ {% empty %}
+ <p>No Results Found</p>
+ {% endfor %}
+ {% endwith %}
+ </section>
+ <p style="font-weight:bold">
+ {% if prev %}
+ <a href="{{ prev }}">{% trans 'Newer Posts' %}</a>
+ {% endif %}
+ {% if prev and next %}|{% endif %}
+ {% if next %}
+ <a href="{{ next }}">{% trans 'Older Posts' %}</a>
+ {% endif %}
+ </p>
+ </td><td id="right">
+ <h2>Tags</h2>
+ <ul>
+ {% for tag in tags %}
+ <li><a href="{% url tag tag.name %}">{{ tag.name }}</a> <small style="color:#666">({{ tag.num_times }} articles)</small></li>
+ {% endfor %}
+ </ul>
+ </td></tr></tbody></table>
+{% endblock content %}
View
@@ -23,6 +23,7 @@
url(r'^(?P<prefix>archive/)((?P<month>[A-Za-z]{3,})-((?P<day>[1-3]?\d)-)?(?P<year>\d{4})/)?(page-(?P<page>\d+)/)?$', 'occupywallst.views.archive', {'is_forum': False, 'per_page': 5}),
url(r'^(?P<prefix>forum/archive/)((?P<month>[A-Za-z]{3,})-((?P<day>[1-3]?\d)-)?(?P<year>\d{4})/)?(page-(?P<page>\d+)/)?$', 'occupywallst.views.archive', {'is_forum': True, 'per_page': 50}),
url(r'^article/(?P<slug>[-_\d\w]+)/$', 'occupywallst.views.article', name='article'),
+ url(r'^tag/(?P<tag>.+?)/((?P<page>\d+)/)?$', 'occupywallst.views.showtag', {'per_page': 1}, name='tag'),
url(r'^fightback/$', 'occupywallst.views.fightback', name='fightback'),
url(r'^fightback/(?P<pledgeid>\d+)/$', 'occupywallst.views.fightback_sig', name='fightback_sig'),
url(r'^fightback/all/$', 'occupywallst.views.fightback_sigs', name='fightback_sigs'),
View
@@ -90,6 +90,24 @@ def forum_search(request):
context_instance=RequestContext(request))
+def showtag(request, tag, page, per_page):
+ page = int(page) - 1 if page else 0
+ tags = db.NewsArticle.tags.most_common()
+ qset = (db.NewsArticle.objects
+ .filter(is_visible=True, is_forum=False, is_deleted=False)
+ .filter(tags__name__in=[tag])
+ .order_by('-published'))
+ articles = qset[page * per_page:page * per_page + per_page]
+ fool = (len(articles) == per_page) # 90% correct without count(*)
+ return render_to_response('occupywallst/tag.html', {
+ 'articles': articles,
+ 'tag': tag,
+ 'tags': tags,
+ 'prev': '/tag/%s/%d/' % (tag, page + 0) if page else None,
+ 'next': '/tag/%s/%d/' % (tag, page + 2) if fool else None,
+ }, context_instance=RequestContext(request))
+
+
def archive(request, is_forum, prefix, per_page,
page=None, year=None, month=None, day=None):
page = int(page) - 1 if page else 0
@@ -119,18 +137,17 @@ def archive(request, is_forum, prefix, per_page,
path = prefix
articles = qset[page * per_page:page * per_page + per_page]
fool = (len(articles) == per_page) # 90% correct without count(*)
- return render_to_response(
- 'occupywallst/archive.html', {
- 'articles': articles,
- 'is_forum': is_forum,
- 'prefix': prefix,
- 'mode': mode,
- 'drill': drill,
- 'filterday': filterday,
- 'prev_path': '/%spage-%d/' % (path, page + 0) if page else None,
- 'cano_path': '/%spage-%d/' % (path, page + 1),
- 'next_path': '/%spage-%d/' % (path, page + 2) if fool else None},
- context_instance=RequestContext(request))
+ return render_to_response('occupywallst/archive.html', {
+ 'articles': articles,
+ 'is_forum': is_forum,
+ 'prefix': prefix,
+ 'mode': mode,
+ 'drill': drill,
+ 'filterday': filterday,
+ 'prev_path': '/%spage-%d/' % (path, page + 0) if page else None,
+ 'cano_path': '/%spage-%d/' % (path, page + 1),
+ 'next_path': '/%spage-%d/' % (path, page + 2) if fool else None,
+ }, context_instance=RequestContext(request))
@my_cache(lambda r: 'forum')

0 comments on commit 17edfeb

Please sign in to comment.