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 'advanced' not in request.GET:
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, extra_context=extra_context)
49 class FragmentAdmin(TaggableModelAdmin):
52 list_display = ('book', 'anchor',)
53 ordering = ('book', 'anchor',)
56 class CollectionAdmin(admin.ModelAdmin):
57 prepopulated_fields = {'slug': ('title',)}
60 class SourceAdmin(admin.ModelAdmin):
61 list_display = ('netloc', 'name')
64 admin.site.register(Tag, TagAdmin)
65 admin.site.register(Book, BookAdmin)
66 admin.site.register(Fragment, FragmentAdmin)
67 admin.site.register(Collection, CollectionAdmin)
68 admin.site.register(Source, SourceAdmin)