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, Collection, Source
12 class TagAdmin(admin.ModelAdmin):
13 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description',)
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):
24 readonly_fields = ['source_sha1']
28 class BookAdmin(TaggableModelAdmin):
31 list_display = ('title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',)
32 search_fields = ('title',)
35 inlines = [MediaInline]
37 def change_view(self, request, object_id, extra_context=None):
38 if not request.GET.has_key('advanced'):
39 self.form = forms.ModelForm
40 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link')
41 self.readonly_fields = ('title',)
43 self.form = TaggableModelForm
45 self.readonly_fields = ()
46 return super(BookAdmin, self).change_view(request, object_id,
47 extra_context=extra_context)
50 class FragmentAdmin(TaggableModelAdmin):
53 list_display = ('book', 'anchor',)
54 ordering = ('book', 'anchor',)
57 class CollectionAdmin(admin.ModelAdmin):
58 prepopulated_fields = {'slug': ('title',)}
61 class SourceAdmin(admin.ModelAdmin):
62 list_display = ('netloc', 'name')
65 admin.site.register(Tag, TagAdmin)
66 admin.site.register(Book, BookAdmin)
67 admin.site.register(Fragment, FragmentAdmin)
68 admin.site.register(Collection, CollectionAdmin)
69 admin.site.register(Source, SourceAdmin)