1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.contrib import admin
6 from django import forms
8 from newtagging.admin import TaggableModelAdmin, TaggableModelForm
9 from catalogue.models import Tag, Book, Fragment, BookMedia
12 class TagAdmin(admin.ModelAdmin):
13 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'main_page',)
14 list_filter = ('category',)
15 search_fields = ('name',)
18 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',),}
19 radio_fields = {'category': admin.HORIZONTAL}
22 class MediaInline(admin.TabularInline):
27 class BookAdmin(TaggableModelAdmin):
30 list_display = ('title', 'slug', 'created_at', 'has_pdf_file', 'has_epub_file', 'has_html_file', 'has_description',)
31 search_fields = ('title',)
34 inlines = [MediaInline]
36 def change_view(self, request, object_id, extra_context=None):
37 if not request.GET.has_key('advanced'):
38 self.form = forms.ModelForm
39 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file',)
40 self.readonly_fields = ('title',)
42 self.form = TaggableModelForm
44 self.readonly_fields = ()
45 return super(BookAdmin, self).change_view(request, object_id,
46 extra_context=extra_context)
49 class FragmentAdmin(TaggableModelAdmin):
52 list_display = ('book', 'anchor',)
53 ordering = ('book', 'anchor',)
56 admin.site.register(Tag, TagAdmin)
57 admin.site.register(Book, BookAdmin)
58 admin.site.register(Fragment, FragmentAdmin)