1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. 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 django.utils.translation import gettext_lazy as _
8 from admin_ordering.admin import OrderableAdmin
9 from social.models import Cite, BannerGroup, Carousel, CarouselItem
12 class CiteForm(ModelForm):
17 'background_color': TextInput(attrs={'type': 'color'}),
20 class CiteAdmin(admin.ModelAdmin):
22 list_display = ['nonempty_text', 'created_at', 'sticky', 'vip', 'small', 'has_image']
23 list_filter = ['group']
24 readonly_fields = ['created_at']
25 autocomplete_fields = ['book']
26 search_fields = ['text', 'link', 'picture_alt', 'picture_author', 'picture_link', 'image_title', 'image_author', 'image_link']
28 (None, {'fields': ('group', 'sticky', 'created_at', 'book')}),
29 (_('Content'), {'fields': ('link', 'vip', 'text', 'small')}),
30 (_('Media box'), {'fields': (
32 'picture', 'picture_alt',
33 'picture_title', 'picture_author', 'picture_link',
34 'picture_license', 'picture_license_link'
39 ('background_plain', 'background_color'),
41 'image_title', 'image_author', 'image_link',
42 'image_license', 'image_license_link'
47 def nonempty_text(self, cite):
50 return "(%s)" % (cite.image_title or cite.link or '-').strip()
51 nonempty_text.short_description = _('text')
53 def has_image(self, cite):
54 return bool(cite.image)
55 has_image.short_description = _('image')
56 has_image.boolean = True
59 admin.site.register(Cite, CiteAdmin)
62 class BannerGroupAdmin(admin.ModelAdmin):
63 list_display = ['name', 'created_at']
64 fields = ['name', 'created_at']
65 readonly_fields = ['created_at']
67 admin.site.register(BannerGroup, BannerGroupAdmin)
70 class CarouselItemInline(OrderableAdmin, admin.TabularInline):
72 ordering_field = 'order'
73 autocomplete_fields = ['banner']
76 class CarouselAdmin(admin.ModelAdmin):
77 list_display = ['placement', 'priority', 'language']
78 inlines = [CarouselItemInline]
81 admin.site.register(Carousel, CarouselAdmin)