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.
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
13 class AttachmentInline(admin.TabularInline):
15 readonly_fields = ['url']
18 class EntryAdmin(admin.ModelAdmin):
19 date_hierarchy = 'date'
20 readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',))
22 (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image', 'date', 'changed_at')}),
25 ('published_%s' % lc),
26 'published_at_%s' % lc,
32 for lc, ln in app_settings.OBLIGATORY_LANGUAGES
35 ('needed_%s' % lc, 'published_%s' % lc),
36 'published_at_%s' % lc,
42 for lc, ln in app_settings.OPTIONAL_LANGUAGES
44 (_('Categories'), {'fields': ('categories',)}),
46 prepopulated_fields = dict([
47 ("slug_%s" % lang_code, ("title_%s" % lang_code,))
48 for lang_code, lang_name in settings.LANGUAGES
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,)
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
68 admin.site.register(Entry, EntryAdmin)
69 admin.site.register(Category, CategoryAdmin)