1 from django.contrib import admin
2 from django import forms
3 from philo.admin import EntityAdmin, AddTagAdmin, COLLAPSE_CLASSES
4 from philo.contrib.penfield.models import BlogEntry, Blog, BlogView, Newsletter, NewsletterArticle, NewsletterIssue, NewsletterView
7 class DelayedDateForm(forms.ModelForm):
10 def __init__(self, *args, **kwargs):
11 super(DelayedDateForm, self).__init__(*args, **kwargs)
12 self.fields[self.date_field].required = False
15 class TitledAdmin(EntityAdmin):
16 prepopulated_fields = {'slug': ('title',)}
17 list_display = ('title', 'slug')
20 class BlogAdmin(TitledAdmin):
24 class BlogEntryAdmin(TitledAdmin, AddTagAdmin):
25 form = DelayedDateForm
26 filter_horizontal = ['tags']
27 list_filter = ['author', 'blog']
28 date_hierarchy = 'date'
29 search_fields = ('content',)
30 list_display = ['title', 'date', 'author']
31 raw_id_fields = ('author',)
34 'fields': ('title', 'author', 'blog')
37 'fields': ('content', 'excerpt', 'tags'),
40 'fields': ('slug', 'date'),
41 'classes': COLLAPSE_CLASSES
46 class BlogViewAdmin(EntityAdmin):
52 'fields': ('index_page', 'entry_page', 'tag_page')
55 'fields': ('entry_archive_page', 'tag_archive_page')
58 'fields': ('entry_permalink_style', 'entry_permalink_base', 'tag_permalink_base'),
59 'classes': COLLAPSE_CLASSES
62 'fields': ('feed_suffix', 'feeds_enabled'),
63 'classes': COLLAPSE_CLASSES
66 raw_id_fields = ('index_page', 'entry_page', 'tag_page', 'entry_archive_page', 'tag_archive_page',)
69 class NewsletterAdmin(TitledAdmin):
73 class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin):
74 form = DelayedDateForm
75 filter_horizontal = ('tags', 'authors')
76 list_filter = ('newsletter',)
77 date_hierarchy = 'date'
78 search_fields = ('title', 'authors__name',)
79 list_display = ['title', 'date', 'author_names']
82 'fields': ('title', 'authors', 'newsletter')
85 'fields': ('full_text', 'lede', 'tags')
88 'fields': ('slug', 'date'),
89 'classes': COLLAPSE_CLASSES
93 def author_names(self, obj):
94 return ', '.join([author.get_full_name() for author in obj.authors.all()])
95 author_names.short_description = "Authors"
98 class NewsletterIssueAdmin(TitledAdmin):
99 filter_horizontal = TitledAdmin.filter_horizontal + ('articles',)
102 class NewsletterViewAdmin(EntityAdmin):
105 'fields': ('newsletter',)
108 'fields': ('index_page', 'article_page', 'issue_page')
111 'fields': ('article_archive_page', 'issue_archive_page')
114 'fields': ('article_permalink_style', 'article_permalink_base', 'issue_permalink_base'),
115 'classes': COLLAPSE_CLASSES
118 'fields': ('feed_suffix', 'feeds_enabled'),
119 'classes': COLLAPSE_CLASSES
122 raw_id_fields = ('index_page', 'article_page', 'issue_page', 'article_archive_page', 'issue_archive_page',)
125 admin.site.register(Blog, BlogAdmin)
126 admin.site.register(BlogEntry, BlogEntryAdmin)
127 admin.site.register(BlogView, BlogViewAdmin)
128 admin.site.register(Newsletter, NewsletterAdmin)
129 admin.site.register(NewsletterArticle, NewsletterArticleAdmin)
130 admin.site.register(NewsletterIssue, NewsletterIssueAdmin)
131 admin.site.register(NewsletterView, NewsletterViewAdmin)