graphics fixes
[prawokultury.git] / migdal / admin.py
1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django.conf import settings
6 from django.contrib import admin
7 from django.utils.translation import ugettext_lazy as _
8 from migdal.models import Category, Entry, Attachment
9 from migdal import app_settings
10 from migdal.helpers import translated_fields
11
12
13 class AttachmentInline(admin.TabularInline):
14     model = Attachment
15     readonly_fields = ['url']
16
17
18 class EntryAdmin(admin.ModelAdmin):
19     date_hierarchy = 'date'
20     fieldsets = (
21         (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image')}),
22     ) + tuple(
23         (ln, {'fields': (
24             ('published_%s' % lc),
25             'title_%s' % lc,
26             'slug_%s' % lc,
27             'lead_%s' % lc,
28             'body_%s' % lc,
29             )})
30         for lc, ln in app_settings.OBLIGATORY_LANGUAGES
31     ) + tuple(
32         (ln, {'fields': (
33             ('needed_%s' % lc, 'published_%s' % lc),
34             'title_%s' % lc,
35             'slug_%s' % lc,
36             'lead_%s' % lc,
37             'body_%s' % lc,
38             )})
39         for lc, ln in app_settings.OPTIONAL_LANGUAGES
40     ) + (
41         (_('Categories'), {'fields': ('categories',)}),
42     )
43     prepopulated_fields = dict([
44             ("slug_%s" % lang_code, ("title_%s" % lang_code,))
45             for lang_code, lang_name in settings.LANGUAGES
46         ]) 
47
48     list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES
49             ) + ('type', 'date', 'author', 'promo'
50             ) + translated_fields(('published',)
51             ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
52     list_filter = ('type', 'promo') + translated_fields(('published',)
53             ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
54     inlines = (AttachmentInline,)
55
56
57 class CategoryAdmin(admin.ModelAdmin):
58     list_display = translated_fields(('title', 'slug')) + ('taxonomy',)
59     prepopulated_fields = dict([
60             ("slug_%s" % lang_code, ("title_%s" % lang_code,))
61             for lang_code, lang_name in settings.LANGUAGES
62         ]) 
63
64
65 admin.site.register(Entry, EntryAdmin)
66 admin.site.register(Category, CategoryAdmin)