gremmie@1: """ gremmie@1: This file contains the automatic admin site definitions for the News models. gremmie@1: """ gremmie@1: from django.contrib import admin bgneal@7: from django.conf import settings bgneal@7: gremmie@1: from news.models import PendingStory gremmie@1: from news.models import Story gremmie@1: from news.models import Category gremmie@1: bgneal@669: import ftfy bgneal@669: bgneal@240: bgneal@240: class CategoryAdmin(admin.ModelAdmin): bgneal@240: prepopulated_fields = {'slug': ("title", )} bgneal@669: list_display = ['title', 'slug'] bgneal@240: bgneal@240: gremmie@1: class PendingStoryAdmin(admin.ModelAdmin): bgneal@669: list_display = ['title', 'date_submitted', 'submitter'] bgneal@669: list_filter = ['date_submitted'] bgneal@669: search_fields = ['title', 'short_text', 'long_text'] bgneal@204: date_hierarchy = 'date_submitted' bgneal@669: actions = ['approve_story'] bgneal@669: readonly_fields = ['update_date'] bgneal@669: raw_id_fields = ['submitter'] gremmie@1: bgneal@204: def approve_story(self, request, qs): bgneal@204: for pending_story in qs: bgneal@204: story = Story( bgneal@204: title=pending_story.title, bgneal@204: submitter=pending_story.submitter, bgneal@204: category=pending_story.category, bgneal@204: short_text=pending_story.short_text, bgneal@204: long_text=pending_story.long_text, bgneal@277: date_submitted=pending_story.date_submitted, bgneal@204: allow_comments=pending_story.allow_comments, bgneal@218: tags=pending_story.tags, bgneal@462: front_page_expiration=pending_story.front_page_expiration, bgneal@486: priority=pending_story.priority, bgneal@486: meta_description=pending_story.meta_description) bgneal@204: story.save() bgneal@204: pending_story.delete() bgneal@204: bgneal@398: count = len(qs) bgneal@398: msg = "1 story" if count == 1 else "%d stories" % count bgneal@398: self.message_user(request, "%s approved." % msg) bgneal@398: bgneal@204: approve_story.short_description = "Approve selected pending stories" bgneal@204: bgneal@204: class Media: bgneal@486: js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] gremmie@1: gremmie@1: gremmie@1: class StoryAdmin(admin.ModelAdmin): bgneal@669: list_display = ['title', 'date_submitted', 'submitter', 'category'] bgneal@669: list_filter = ['date_submitted', 'category'] bgneal@669: search_fields = ['title', 'short_text', 'long_text'] bgneal@204: date_hierarchy = 'date_submitted' bgneal@669: readonly_fields = ['update_date'] bgneal@669: raw_id_fields = ['submitter'] bgneal@669: actions = ['fix_text'] bgneal@669: bgneal@669: def fix_text(self, request, qs): bgneal@669: for story in qs: bgneal@669: story.title = ftfy.fix_text(story.title) bgneal@669: story.short_text = ftfy.fix_text(story.short_text) bgneal@669: story.long_text = ftfy.fix_text(story.long_text) bgneal@669: story.save() bgneal@669: bgneal@669: count = len(qs) bgneal@669: msg = "1 story" if count == 1 else "%d stories" % count bgneal@669: self.message_user(request, "Text fixed on {}".format(msg)) bgneal@669: bgneal@669: fix_text.short_description = "Fix text on selected stories" gremmie@1: bgneal@204: class Media: bgneal@486: js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] gremmie@1: gremmie@1: bgneal@240: admin.site.register(Category, CategoryAdmin) gremmie@1: admin.site.register(Story, StoryAdmin) gremmie@1: admin.site.register(PendingStory, PendingStoryAdmin)