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
44 related_lookup_fields = {'fk': raw_id_fields}
47 class BlogViewAdmin(EntityAdmin):
53 'fields': ('index_page', 'entry_page', 'tag_page')
56 'fields': ('entry_archive_page', 'tag_archive_page')
58 ('General Settings', {
59 'fields': ('entry_permalink_style', 'entry_permalink_base', 'tag_permalink_base', 'entries_per_page'),
60 'classes': COLLAPSE_CLASSES
63 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'item_title_template', 'item_description_template',),
64 'classes': COLLAPSE_CLASSES
67 raw_id_fields = ('index_page', 'entry_page', 'tag_page', 'entry_archive_page', 'tag_archive_page', 'item_title_template', 'item_description_template',)
68 related_lookup_fields = {'fk': raw_id_fields}
71 class NewsletterAdmin(TitledAdmin):
75 class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin):
76 form = DelayedDateForm
77 filter_horizontal = ('tags', 'authors')
78 list_filter = ('newsletter',)
79 date_hierarchy = 'date'
80 search_fields = ('title', 'authors__name',)
81 list_display = ['title', 'date', 'author_names']
84 'fields': ('title', 'authors', 'newsletter')
87 'fields': ('full_text', 'lede', 'tags')
90 'fields': ('slug', 'date'),
91 'classes': COLLAPSE_CLASSES
95 def author_names(self, obj):
96 return ', '.join([author.get_full_name() for author in obj.authors.all()])
97 author_names.short_description = "Authors"
100 class NewsletterIssueAdmin(TitledAdmin):
101 filter_horizontal = TitledAdmin.filter_horizontal + ('articles',)
104 class NewsletterViewAdmin(EntityAdmin):
107 'fields': ('newsletter',)
110 'fields': ('index_page', 'article_page', 'issue_page')
113 'fields': ('article_archive_page', 'issue_archive_page')
116 'fields': ('article_permalink_style', 'article_permalink_base', 'issue_permalink_base'),
117 'classes': COLLAPSE_CLASSES
120 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'item_title_template', 'item_description_template',),
121 'classes': COLLAPSE_CLASSES
124 raw_id_fields = ('index_page', 'article_page', 'issue_page', 'article_archive_page', 'issue_archive_page', 'item_title_template', 'item_description_template',)
125 related_lookup_fields = {'fk': raw_id_fields}
128 admin.site.register(Blog, BlogAdmin)
129 admin.site.register(BlogEntry, BlogEntryAdmin)
130 admin.site.register(BlogView, BlogViewAdmin)
131 admin.site.register(Newsletter, NewsletterAdmin)
132 admin.site.register(NewsletterArticle, NewsletterArticleAdmin)
133 admin.site.register(NewsletterIssue, NewsletterIssueAdmin)
134 admin.site.register(NewsletterView, NewsletterViewAdmin)