News app.

This commit is contained in:
Greg Taylor 2007-06-05 20:07:19 +00:00
parent 1e13d94b20
commit e80fa61d03
4 changed files with 84 additions and 0 deletions

0
apps/news/__init__.py Executable file
View file

43
apps/news/models.py Executable file
View file

@ -0,0 +1,43 @@
from django.db import models
from django.contrib.auth.models import User
class NewsTopic(models.Model):
"""
Represents a news topic.
"""
name = models.CharField(maxlength=75, unique=True)
description = models.TextField(blank=True)
icon = models.ImageField(upload_to='newstopic_icons', default='newstopic_icons/default.png', blank=True, help_text="Image for the news topic.")
def __str__(self):
try:
return self.name
except:
return "Invalid"
class Meta:
ordering = ['name']
class Admin:
list_display = ('name', 'icon')
class NewsEntry(models.Model):
"""
An individual news entry.
"""
author = models.ForeignKey(User, related_name='author')
title = models.CharField(maxlength=255)
body = models.TextField()
topic = models.ForeignKey(NewsTopic, related_name='newstopic')
date_posted = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class Meta:
ordering = ('-date_posted',)
class Admin:
list_display = ('title', 'author', 'topic', 'date_posted')
list_filter = ('topic',)
search_fields = ['title']

6
apps/news/urls.py Executable file
View file

@ -0,0 +1,6 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('apps.news.views',
# (r'^news/show/(?P<entry_id>\d+)/$', 'show_news'),
# (r'^news/categories/list/$', 'recent_kills'),
)

35
apps/news/views.py Executable file
View file

@ -0,0 +1,35 @@
#
# News display.
#
from django.shortcuts import render_to_response, get_object_or_404
from django.db import connection
from django.template import RequestContext
from django import newforms as forms
from django.newforms.util import ValidationError
import django.views.generic.list_detail as list_detail
from django.contrib.auth.models import User
from django.utils import simplejson
import frontier.settings as settings
from frontier.apps.player.models import UserProfile
from frontier.apps.news.models import NewsTopic, NewsEntry
nav_block = """
<div>
</div>
"""
def index(request):
"""
News index.
"""
news_entries = NewsEntry.objects.all().order_by('-date_posted')[:10]
pagevars = {
"page_title": "Front Page",
"nav_block": nav_block,
"news_entries": news_entries,
}
context_instance = RequestContext(request)
return render_to_response('news/index.html', pagevars, context_instance)