cas
[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     readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',))
21     fieldsets = (
22         (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image', 'date', 'changed_at')}),
23     ) + tuple(
24         (ln, {'fields': (
25             ('published_%s' % lc),
26             'published_at_%s' % lc,
27             'title_%s' % lc,
28             'slug_%s' % lc,
29             'lead_%s' % lc,
30             'body_%s' % lc,
31             )})
32         for lc, ln in app_settings.OBLIGATORY_LANGUAGES
33     ) + tuple(
34         (ln, {'fields': (
35             ('needed_%s' % lc, 'published_%s' % lc),
36             'published_at_%s' % lc,
37             'title_%s' % lc,
38             'slug_%s' % lc,
39             'lead_%s' % lc,
40             'body_%s' % lc,
41             )})
42         for lc, ln in app_settings.OPTIONAL_LANGUAGES
43     ) + (
44         (_('Categories'), {'fields': ('categories',)}),
45     )
46     prepopulated_fields = dict([
47             ("slug_%s" % lang_code, ("title_%s" % lang_code,))
48             for lang_code, lang_name in settings.LANGUAGES
49         ]) 
50
51     list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES
52             ) + ('type', 'date', 'author', 'promo'
53             ) + translated_fields(('published',)
54             ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
55     list_filter = ('type', 'promo') + translated_fields(('published',)
56             ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
57     inlines = (AttachmentInline,)
58
59
60 class CategoryAdmin(admin.ModelAdmin):
61     list_display = translated_fields(('title', 'slug')) + ('taxonomy',)
62     prepopulated_fields = dict([
63             ("slug_%s" % lang_code, ("title_%s" % lang_code,))
64             for lang_code, lang_name in settings.LANGUAGES
65         ]) 
66
67
68 admin.site.register(Entry, EntryAdmin)
69 admin.site.register(Category, CategoryAdmin)