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
7 from newtagging.admin import TaggableModelAdmin
8 from catalogue.models import Tag, Book, Fragment, BookMedia
11 class TagAdmin(admin.ModelAdmin):
12 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'main_page',)
13 list_filter = ('category',)
14 search_fields = ('name',)
17 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',),}
18 radio_fields = {'category': admin.HORIZONTAL}
21 class BookAdmin(TaggableModelAdmin):
24 list_display = ('title', 'slug', 'created_at', 'has_pdf_file', 'has_epub_file', 'has_html_file', 'has_description',)
25 search_fields = ('title',)
28 filter_horizontal = ('medias',)
30 def change_view(self, request, object_id, extra_context=None):
31 if not request.GET.has_key('advanced'):
32 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file', 'medias',)
33 self.readonly_fields = ('title',)
36 self.readonly_fields = ()
37 return super(BookAdmin, self).change_view(request, object_id,
38 extra_context=extra_context)
42 class FragmentAdmin(TaggableModelAdmin):
45 list_display = ('book', 'anchor',)
46 ordering = ('book', 'anchor',)
49 class MediaAdmin(admin.ModelAdmin):
50 #tag_model = BookMedia
52 list_display = ('name', 'type', 'uploaded_at')
53 ordering = ('name', 'type')
54 search_fields = ('name',)
55 fields = ('type', 'name', 'file',)
59 admin.site.register(Tag, TagAdmin)
60 admin.site.register(Book, BookAdmin)
61 admin.site.register(Fragment, FragmentAdmin)
62 admin.site.register(BookMedia, MediaAdmin)