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.contrib import admin
6 from django.utils.translation import ugettext_lazy as _
7 from migdal.models import Category, Entry, Attachment
8 from migdal import settings
11 def translated_fields(field_names, languages=settings.LANGUAGES):
12 return tuple("%s_%s" % (field_name, lang_code)
13 for field_name in field_names
14 for lang_code, lang_name in languages
18 class AttachmentInline(admin.TabularInline):
20 readonly_fields = ['url']
23 class EntryAdmin(admin.ModelAdmin):
25 (None, {'fields': ('type', 'author', 'author_email', 'image')}),
28 ('published_%s' % lc),
34 for lc, ln in settings.OBLIGATORY_LANGUAGES
37 ('needed_%s' % lc, 'published_%s' % lc),
43 for lc, ln in settings.OPTIONAL_LANGUAGES
45 (_('Categories'), {'fields': ('categories',)}),
47 prepopulated_fields = dict([
48 ("slug_%s" % lang_code, ("title_%s" % lang_code,))
49 for lang_code, lang_name in settings.LANGUAGES
52 list_display = translated_fields(('title',), settings.OBLIGATORY_LANGUAGES
53 ) + ('type', 'date', 'author'
54 ) + translated_fields(('published',)
55 ) + translated_fields(('needed',), settings.OPTIONAL_LANGUAGES)
56 list_filter = ('type',) + translated_fields(('published',)
57 ) + translated_fields(('needed',), settings.OPTIONAL_LANGUAGES)
58 inlines = (AttachmentInline,)
61 class CategoryAdmin(admin.ModelAdmin):
62 list_display = translated_fields(('title', 'slug'))
63 prepopulated_fields = dict([
64 ("slug_%s" % lang_code, ("title_%s" % lang_code,))
65 for lang_code, lang_name in settings.LANGUAGES
69 admin.site.register(Entry, EntryAdmin)
70 admin.site.register(Category, CategoryAdmin)