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, AddTagAdmin, 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(AddTagAdmin):
24 form = DelayedDateForm
25 filter_horizontal = ['tags']
26 list_filter = ['author', 'blog']
27 date_hierarchy = 'date'
28 search_fields = ('content',)
29 list_display = ['title', 'date', 'author']
30 raw_id_fields = ('author',)
33 'fields': ('title', 'author', 'blog')
36 'fields': ('content', 'excerpt', 'tags'),
39 'fields': ('slug', 'date'),
40 'classes': COLLAPSE_CLASSES
43 related_lookup_fields = {'fk': raw_id_fields}
44 prepopulated_fields = {'slug': ('title',)}
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', 'feed_length', '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(EntityAdmin):
72 prepopulated_fields = {'slug': ('title',)}
73 list_display = ('title', 'slug')
76 class NewsletterArticleAdmin(AddTagAdmin):
77 form = DelayedDateForm
78 filter_horizontal = ('tags', 'authors')
79 list_filter = ('newsletter',)
80 date_hierarchy = 'date'
81 search_fields = ('title', 'authors__name',)
82 list_display = ['title', 'date', 'author_names']
85 'fields': ('title', 'authors', 'newsletter')
88 'fields': ('full_text', 'lede', 'tags')
91 'fields': ('slug', 'date'),
92 'classes': COLLAPSE_CLASSES
95 actions = ['make_issue']
96 prepopulated_fields = {'slug': ('title',)}
98 def author_names(self, obj):
99 return ', '.join([author.get_full_name() for author in obj.authors.all()])
100 author_names.short_description = "Authors"
102 def make_issue(self, request, queryset):
103 opts = NewsletterIssue._meta
104 info = opts.app_label, opts.module_name
105 url = reverse("admin:%s_%s_add" % info)
106 return HttpResponseRedirect("%s?articles=%s" % (url, ",".join([str(a.pk) for a in queryset])))
107 make_issue.short_description = u"Create issue from selected %(verbose_name_plural)s"
110 class NewsletterIssueAdmin(EntityAdmin):
111 filter_horizontal = ('articles',)
112 prepopulated_fields = {'slug': ('title',)}
113 list_display = ('title', 'slug')
116 class NewsletterViewAdmin(EntityAdmin):
119 'fields': ('newsletter',)
122 'fields': ('index_page', 'article_page', 'issue_page')
125 'fields': ('article_archive_page', 'issue_archive_page')
128 'fields': ('article_permalink_style', 'article_permalink_base', 'issue_permalink_base'),
129 'classes': COLLAPSE_CLASSES
132 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'feed_length', 'item_title_template', 'item_description_template',),
133 'classes': COLLAPSE_CLASSES
136 raw_id_fields = ('index_page', 'article_page', 'issue_page', 'article_archive_page', 'issue_archive_page', 'item_title_template', 'item_description_template',)
137 related_lookup_fields = {'fk': raw_id_fields}
140 admin.site.register(Blog, BlogAdmin)
141 admin.site.register(BlogEntry, BlogEntryAdmin)
142 admin.site.register(BlogView, BlogViewAdmin)
143 admin.site.register(Newsletter, NewsletterAdmin)
144 admin.site.register(NewsletterArticle, NewsletterArticleAdmin)
145 admin.site.register(NewsletterIssue, NewsletterIssueAdmin)
146 admin.site.register(NewsletterView, NewsletterViewAdmin)