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):
32 # 'osm_data': self.get_osm_info(),
34 print request.GET.keys()
35 if not request.GET.has_key('advanced'):
36 self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file', 'medias',)
37 self.readonly_fields = ('title', 'slug',)
40 self.readonly_fields = ()
41 return super(BookAdmin, self).change_view(request, object_id,
42 extra_context=extra_context)
46 class FragmentAdmin(TaggableModelAdmin):
49 list_display = ('book', 'anchor',)
50 ordering = ('book', 'anchor',)
53 class MediaAdmin(admin.ModelAdmin):
54 #tag_model = BookMedia
56 list_display = ('name', 'type', 'uploaded_at')
57 ordering = ('name', 'type')
58 search_fields = ('name',)
62 admin.site.register(Tag, TagAdmin)
63 admin.site.register(Book, BookAdmin)
64 admin.site.register(Fragment, FragmentAdmin)
65 admin.site.register(BookMedia, MediaAdmin)