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 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.form = forms.ModelForm
34 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file', 'medias',)
35 self.readonly_fields = ('title',)
37 self.form = TaggableModelForm
39 self.readonly_fields = ()
40 return super(BookAdmin, self).change_view(request, object_id,
41 extra_context=extra_context)
45 class FragmentAdmin(TaggableModelAdmin):
48 list_display = ('book', 'anchor',)
49 ordering = ('book', 'anchor',)
53 class BookMediaAdminForm(forms.ModelForm):
54 books = forms.CharField(required=False)
60 class MediaAdmin(admin.ModelAdmin):
61 form = BookMediaAdminForm
63 list_display = ('name', 'type', 'book_count', 'uploaded_at')
64 ordering = ('name', 'type')
65 search_fields = ('name',)
66 fields = ('type', 'name', 'file', 'books')
67 readonly_fields = ('books',)
71 admin.site.register(Tag, TagAdmin)
72 admin.site.register(Book, BookAdmin)
73 admin.site.register(Fragment, FragmentAdmin)
74 admin.site.register(BookMedia, MediaAdmin)