1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.contrib import admin
5 from django.forms import ModelForm
6 from django.forms.widgets import TextInput
7 from admin_ordering.admin import OrderableAdmin
8 from social.models import Cite, BannerGroup, Carousel, CarouselItem
11 class CiteForm(ModelForm):
16 'background_color': TextInput(attrs={'type': 'color'}),
19 class CiteAdmin(admin.ModelAdmin):
21 list_display = ['nonempty_text', 'created_at', 'sticky', 'vip', 'small', 'has_image']
22 list_filter = ['group']
23 readonly_fields = ['created_at']
24 autocomplete_fields = ['book']
25 search_fields = ['text', 'link', 'picture_alt', 'picture_author', 'picture_link', 'image_title', 'image_author', 'image_link']
27 (None, {'fields': ('group', 'sticky', 'created_at', 'book')}),
28 ('Zawartość', {'fields': ('link', 'vip', 'text', 'small')}),
29 ('Media', {'fields': (
31 'picture', 'picture_alt',
32 'picture_title', 'picture_author', 'picture_link',
33 'picture_license', 'picture_license_link'
38 ('background_plain', 'background_color'),
40 'image_title', 'image_author', 'image_link',
41 'image_license', 'image_license_link'
46 def nonempty_text(self, cite):
49 return "(%s)" % (cite.image_title or cite.link or '-').strip()
50 nonempty_text.short_description = 'tekst'
52 def has_image(self, cite):
53 return bool(cite.image)
54 has_image.short_description = 'obraz'
55 has_image.boolean = True
58 admin.site.register(Cite, CiteAdmin)
61 class BannerGroupAdmin(admin.ModelAdmin):
62 list_display = ['name', 'created_at']
63 fields = ['name', 'created_at']
64 readonly_fields = ['created_at']
66 admin.site.register(BannerGroup, BannerGroupAdmin)
69 class CarouselItemInline(OrderableAdmin, admin.TabularInline):
71 ordering_field = 'order'
72 autocomplete_fields = ['banner']
75 class CarouselAdmin(admin.ModelAdmin):
76 list_display = ['placement', 'priority', 'language']
77 inlines = [CarouselItemInline]
80 admin.site.register(Carousel, CarouselAdmin)