X-Git-Url: https://git.mdrn.pl/django-migdal.git/blobdiff_plain/734cd58d3f12c5397b42c1ae122c947500386014..HEAD:/migdal/admin.py?ds=sidebyside diff --git a/migdal/admin.py b/migdal/admin.py index 6bdfb59..2a674b1 100644 --- a/migdal/admin.py +++ b/migdal/admin.py @@ -5,7 +5,7 @@ from django.conf import settings from django.contrib import admin from django.utils.translation import ugettext_lazy as _ -from migdal.models import Entry, Attachment +from migdal.models import Entry, Attachment, Photo from migdal import app_settings from fnpdjango.utils.models import filtered_model from fnpdjango.utils.models.translation import translated_fields @@ -16,10 +16,15 @@ class AttachmentInline(admin.TabularInline): readonly_fields = ['url'] +class PhotoInline(admin.TabularInline): + model = Photo + readonly_fields = ['url'] + + def filtered_entry_admin(typ): class EntryAdmin(admin.ModelAdmin): - def queryset(self, request): - return self.model.objects.filter(type=typ) + def get_queryset(self, request): + return self.model.objects.filter(type=typ.db) def has_add_permission(self, request): return request.user.has_perm('migdal.add_entry') @@ -30,15 +35,23 @@ def filtered_entry_admin(typ): def has_delete_permission(self, request, obj=None): return request.user.has_perm('migdal.delete_entry') + def formfield_for_dbfield(self, db_field, **kwargs): + field = super(EntryAdmin, self).formfield_for_dbfield(db_field, **kwargs) + if db_field.name == 'categories': + field.widget.attrs['style'] = 'height: 10em' + return field + date_hierarchy = 'date' - readonly_fields = ('date', 'changed_at') + \ - translated_fields(('published_at',)) + readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',), app_settings.LANGUAGES) + if app_settings.PUBLISH_DATE_EDITABLE: + readonly_fields += ('first_published_at',) _promo_if_necessary = ('promo',) if typ.promotable else () fieldsets = ( (None, { 'fields': _promo_if_necessary + ( - 'author', 'author_email', 'image', 'date', 'changed_at') + 'in_stream', 'author', 'author_email', 'canonical_url', 'image', + 'date', 'first_published_at', 'changed_at') }), ) + tuple( (ln, {'fields': ( @@ -48,6 +61,8 @@ def filtered_entry_admin(typ): 'slug_%s' % lc, 'lead_%s' % lc, 'body_%s' % lc, + 'place_%s' % lc, + 'time_%s' % lc, )}) for lc, ln in app_settings.OBLIGATORY_LANGUAGES ) + tuple( @@ -58,6 +73,8 @@ def filtered_entry_admin(typ): 'slug_%s' % lc, 'lead_%s' % lc, 'body_%s' % lc, + 'place_%s' % lc, + 'time_%s' % lc, )}) for lc, ln in app_settings.OPTIONAL_LANGUAGES ) @@ -68,19 +85,19 @@ def filtered_entry_admin(typ): ) prepopulated_fields = dict([ ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES + for lang_code, lang_name in app_settings.LANGUAGES ]) - list_display = translated_fields(('title',), - app_settings.OBLIGATORY_LANGUAGES) + \ - ('date', 'author') + \ - _promo_if_necessary + \ - translated_fields(('published_at',)) + \ - translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) + list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES) + \ + ('date', 'author') + \ + _promo_if_necessary + \ + ('in_stream', 'first_published_at',) + \ + translated_fields(('published_at',), app_settings.LANGUAGES) + \ + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) list_filter = _promo_if_necessary + \ - translated_fields(('published',)) + \ - translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) - inlines = (AttachmentInline,) + translated_fields(('published',), app_settings.LANGUAGES) + \ + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) + inlines = (PhotoInline, AttachmentInline) search_fields = ('title_pl', 'title_en') return EntryAdmin @@ -94,9 +111,9 @@ if app_settings.TAXONOMIES: from migdal.models import Category class CategoryAdmin(admin.ModelAdmin): - list_display = translated_fields(('title', 'slug')) + ('taxonomy',) + list_display = translated_fields(('title', 'slug'), app_settings.LANGUAGES) + ('taxonomy',) prepopulated_fields = dict([ ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES + for lang_code, lang_name in app_settings.LANGUAGES ]) admin.site.register(Category, CategoryAdmin)