X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/a2157081b0dc561e0040c57b4b2b239b69b8d342..ca8f4e8fef80cb603117ed579da8554f503698e5:/src/social/admin.py diff --git a/src/social/admin.py b/src/social/admin.py old mode 100755 new mode 100644 index c53ff893f..ac5fbd250 --- a/src/social/admin.py +++ b/src/social/admin.py @@ -1,35 +1,81 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ +from django.forms import ModelForm +from django.forms.widgets import TextInput +from admin_ordering.admin import OrderableAdmin +from social.models import Cite, BannerGroup, Carousel, CarouselItem -from social.models import Cite +class CiteForm(ModelForm): + class Meta: + model = Cite + fields = '__all__' + widgets = { + 'background_color': TextInput(attrs={'type': 'color'}), + } class CiteAdmin(admin.ModelAdmin): - list_display = ['nonempty_text', 'sticky', 'vip', 'small', 'has_image'] + form = CiteForm + list_display = ['nonempty_text', 'created_at', 'sticky', 'vip', 'small', 'has_image'] + list_filter = ['group'] + readonly_fields = ['created_at'] + autocomplete_fields = ['book'] + search_fields = ['text', 'link', 'picture_alt', 'picture_author', 'picture_link', 'image_title', 'image_author', 'image_link'] fieldsets = ( - (None, {'fields': ('book', 'text', 'small', 'vip', 'link', 'sticky', 'banner')}), + (None, {'fields': ('group', 'sticky', 'created_at', 'book')}), + ('Zawartość', {'fields': ('link', 'vip', 'text', 'small')}), + ('Media', {'fields': ( + 'video', + 'picture', 'picture_alt', + 'picture_title', 'picture_author', 'picture_link', + 'picture_license', 'picture_license_link' + )}), ( - _('Background'), + 'Tło', {'fields': ( - 'image', 'image_shift', 'image_title', 'image_author', - 'image_link', 'image_license', 'image_license_link')}, + ('background_plain', 'background_color'), + 'image', + 'image_title', 'image_author', 'image_link', + 'image_license', 'image_license_link' + )}, ) ) def nonempty_text(self, cite): if cite.text.strip(): return cite.text - return "(%s)" % (cite.image_title.strip() or cite.link) - nonempty_text.short_description = _('text') + return "(%s)" % (cite.image_title or cite.link or '-').strip() + nonempty_text.short_description = 'tekst' def has_image(self, cite): return bool(cite.image) - has_image.short_description = _('image') + has_image.short_description = 'obraz' has_image.boolean = True admin.site.register(Cite, CiteAdmin) + + +class BannerGroupAdmin(admin.ModelAdmin): + list_display = ['name', 'created_at'] + fields = ['name', 'created_at'] + readonly_fields = ['created_at'] + +admin.site.register(BannerGroup, BannerGroupAdmin) + + +class CarouselItemInline(OrderableAdmin, admin.TabularInline): + model = CarouselItem + ordering_field = 'order' + autocomplete_fields = ['banner'] + + +class CarouselAdmin(admin.ModelAdmin): + list_display = ['placement', 'priority', 'language'] + inlines = [CarouselItemInline] + + +admin.site.register(Carousel, CarouselAdmin) +