view gpp/news/admin.py @ 220:71fd8454688b

For #51, added weblinks to search. Decided against using the search index to store prerendered results. My fear is this could get too unweildy once we add forums.
author Brian Neal <bgneal@gmail.com>
date Sun, 06 Jun 2010 20:06:15 +0000
parents 6dbb8faef085
children 1246a4f1ab4f
line wrap: on
line source
"""
This file contains the automatic admin site definitions for the News models.
"""
import datetime

from django.contrib import admin
from django.conf import settings

from news.models import PendingStory
from news.models import Story
from news.models import Category

class PendingStoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'date_submitted', 'submitter')
    list_filter = ('date_submitted', )
    search_fields = ('title', 'short_text', 'long_text')
    date_hierarchy = 'date_submitted'
    actions = ('approve_story', )

    def approve_story(self, request, qs):
        for pending_story in qs:
            story = Story(
                    title=pending_story.title,
                    submitter=pending_story.submitter,
                    category=pending_story.category,
                    short_text=pending_story.short_text,
                    long_text=pending_story.long_text,
                    date_submitted=datetime.datetime.now(),
                    allow_comments=pending_story.allow_comments,
                    tags=pending_story.tags,
                    front_page_expiration=pending_story.front_page_expiration)
            story.save()
            pending_story.delete()

    approve_story.short_description = "Approve selected pending stories"

    class Media:
        js = settings.GPP_THIRD_PARTY_JS['tiny_mce']


class StoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'date_submitted', 'submitter', 'category')
    list_filter = ('date_submitted', 'category')
    search_fields = ('title', 'short_text', 'long_text')
    date_hierarchy = 'date_submitted'

    class Media:
        js = settings.GPP_THIRD_PARTY_JS['tiny_mce']


admin.site.register(Category)
admin.site.register(Story, StoryAdmin)
admin.site.register(PendingStory, PendingStoryAdmin)