Commits

Pierre Bourdon committed d9984aa

Simple news system linking to a forum thread

  • Participants
  • Parent commits 0cfeafa

Comments (0)

Files changed (4)

dolweb/homepage/models.py

+from django.conf import settings
 from django.db import models
 
 class NewsArticle(models.Model):
     def __unicode__(self):
         return self.title
 
+    @property
+    def forum_url(self):
+        return settings.FORUM_URL + u'showthread.php?tid=%d' % self.forum_pid
+
     @models.permalink
     def get_absolute_url(self):
         return ('news-article', [self.slug])

dolweb/homepage/templates/homepage-home.html

 {% extends "_base.html" %}
 
 {% load i18n %}
+{% load humanize %}
 {% load thumbnail %}
 
 {% block "title" %}{% trans "Homepage" %}{% endblock %}
         <h2>{% trans "Recent Dolphin news" %}</h2>
         <p>
         <ul>
-            <li>TODO</li>
-            <li>TODO</li>
-            <li>TODO</li>
-            <li>TODO</li>
+            {% for news in latest_news %}
+            <li><a href="{{ news.forum_url }}">{{ news.title }}</a>
+                ({% trans "by" %} {{ news.author }}, {{ news.posted_on|naturaltime }})</li>
+            {% endfor %}
         </ul>
         </p>
     </div>

dolweb/homepage/views.py

 from annoying.decorators import render_to
 from dolweb.downloads.models import ReleaseVersion
+from dolweb.homepage.models import NewsArticle
 from dolweb.media.models import Screenshot
 
 @render_to('homepage-home.html')
 def home(request):
     featured = Screenshot.objects.filter(promoted=True).order_by('game_name')
+    news = NewsArticle.objects.filter(published=True).order_by('-posted_on')[:5]
     try:
         last_release = ReleaseVersion.objects.order_by('-date')[0]
     except IndexError:
         last_release = u"Dolphin"
-    return { 'featured_images': featured, 'last_release': last_release }
-
-def news_article(request):
-    raise NotImplemented
+    return { 'featured_images': featured, 'last_release': last_release,
+             'latest_news': news }
 urlpatterns = patterns('',
     # Homepage
     url(r'^$', 'dolweb.homepage.views.home', name='home'),
-    url(r'^news/(?P<slug>[\w-]+)/$', 'dolweb.homepage.views.news_article',
-        name='news-article'),
 
     # Media (image gallery, link to videos)
     url(r'^media/', include('dolweb.media.urls')),