1 from django import forms
2 from django.contrib import admin
3 from django.core.urlresolvers import reverse
4 from django.http import HttpResponseRedirect, QueryDict
6 from philo.admin import EntityAdmin, COLLAPSE_CLASSES
7 from philo.contrib.penfield.models import BlogEntry, Blog, BlogView, Newsletter, NewsletterArticle, NewsletterIssue, NewsletterView
10 class DelayedDateForm(forms.ModelForm):
13 def __init__(self, *args, **kwargs):
14 super(DelayedDateForm, self).__init__(*args, **kwargs)
15 self.fields[self.date_field].required = False
18 class BlogAdmin(EntityAdmin):
19 prepopulated_fields = {'slug': ('title',)}
20 list_display = ('title', 'slug')
23 class BlogEntryAdmin(EntityAdmin):
24 form = DelayedDateForm
25 list_filter = ['author', 'blog']
26 date_hierarchy = 'date'
27 search_fields = ('content',)
28 list_display = ['title', 'date', 'author']
29 raw_id_fields = ('author',)
32 'fields': ('title', 'author', 'blog')
35 'fields': ('content', 'excerpt', 'tags'),
38 'fields': ('slug', 'date'),
39 'classes': COLLAPSE_CLASSES
42 related_lookup_fields = {'fk': raw_id_fields}
43 prepopulated_fields = {'slug': ('title',)}
46 class BlogViewAdmin(EntityAdmin):
52 'fields': ('index_page', 'entry_page', 'tag_page')
55 'fields': ('entry_archive_page', 'tag_archive_page')
57 ('General Settings', {
58 'fields': ('entry_permalink_style', 'entry_permalink_base', 'tag_permalink_base', 'entries_per_page'),
59 'classes': COLLAPSE_CLASSES
62 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'feed_length', 'item_title_template', 'item_description_template',),
63 'classes': COLLAPSE_CLASSES
66 raw_id_fields = ('index_page', 'entry_page', 'tag_page', 'entry_archive_page', 'tag_archive_page', 'item_title_template', 'item_description_template',)
67 related_lookup_fields = {'fk': raw_id_fields}
70 class NewsletterAdmin(EntityAdmin):
71 prepopulated_fields = {'slug': ('title',)}
72 list_display = ('title', 'slug')
75 class NewsletterArticleAdmin(EntityAdmin):
76 form = DelayedDateForm
77 filter_horizontal = ('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
94 actions = ['make_issue']
95 prepopulated_fields = {'slug': ('title',)}
97 def author_names(self, obj):
98 return ', '.join([author.get_full_name() for author in obj.authors.all()])
99 author_names.short_description = "Authors"
101 def make_issue(self, request, queryset):
102 opts = NewsletterIssue._meta
103 info = opts.app_label, opts.module_name
104 url = reverse("admin:%s_%s_add" % info)
105 return HttpResponseRedirect("%s?articles=%s" % (url, ",".join([str(a.pk) for a in queryset])))
106 make_issue.short_description = u"Create issue from selected %(verbose_name_plural)s"
109 class NewsletterIssueAdmin(EntityAdmin):
110 filter_horizontal = ('articles',)
111 prepopulated_fields = {'slug': ('title',)}
112 list_display = ('title', 'slug')
115 class NewsletterViewAdmin(EntityAdmin):
118 'fields': ('newsletter',)
121 'fields': ('index_page', 'article_page', 'issue_page')
124 'fields': ('article_archive_page', 'issue_archive_page')
127 'fields': ('article_permalink_style', 'article_permalink_base', 'issue_permalink_base'),
128 'classes': COLLAPSE_CLASSES
131 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'feed_length', 'item_title_template', 'item_description_template',),
132 'classes': COLLAPSE_CLASSES
135 raw_id_fields = ('index_page', 'article_page', 'issue_page', 'article_archive_page', 'issue_archive_page', 'item_title_template', 'item_description_template',)
136 related_lookup_fields = {'fk': raw_id_fields}
139 admin.site.register(Blog, BlogAdmin)
140 admin.site.register(BlogEntry, BlogEntryAdmin)
141 admin.site.register(BlogView, BlogViewAdmin)
142 admin.site.register(Newsletter, NewsletterAdmin)
143 admin.site.register(NewsletterArticle, NewsletterArticleAdmin)
144 admin.site.register(NewsletterIssue, NewsletterIssueAdmin)
145 admin.site.register(NewsletterView, NewsletterViewAdmin)