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
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 BookAdmin(TaggableModelAdmin):
25 list_display = ('title', 'slug', 'created_at', 'has_pdf_file', 'has_epub_file', 'has_html_file', 'has_description',)
26 search_fields = ('title',)
29 filter_horizontal = ('medias',)
31 def change_view(self, request, object_id, extra_context=None):
32 if not request.GET.has_key('advanced'):
33 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file', 'medias',)
34 self.readonly_fields = ('title',)
37 self.readonly_fields = ()
38 return super(BookAdmin, self).change_view(request, object_id,
39 extra_context=extra_context)
43 class FragmentAdmin(TaggableModelAdmin):
46 list_display = ('book', 'anchor',)
47 ordering = ('book', 'anchor',)
51 class BookMediaAdminForm(forms.ModelForm):
52 books = forms.CharField(required=False)
58 class MediaAdmin(admin.ModelAdmin):
59 form = BookMediaAdminForm
61 list_display = ('name', 'type', 'book_count', 'uploaded_at')
62 ordering = ('name', 'type')
63 search_fields = ('name',)
64 fields = ('type', 'name', 'file', 'books')
65 readonly_fields = ('books',)
69 admin.site.register(Tag, TagAdmin)
70 admin.site.register(Book, BookAdmin)
71 admin.site.register(Fragment, FragmentAdmin)
72 admin.site.register(BookMedia, MediaAdmin)