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 ugettext_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 raw_id_fields = ['book']
27 (None, {'fields': ('group', 'sticky', 'created_at', 'book')}),
28 (_('Content'), {'fields': ('link', 'vip', 'text', 'small')}),
29 (_('Media box'), {'fields': (
31 'picture', 'picture_alt',
32 'picture_title', 'picture_author', 'picture_link',
33 'picture_license', 'picture_license_link'
40 ('background_plain', 'background_color'),
41 'image', 'image_shift',
43 'image_title', 'image_author', 'image_link',
44 'image_license', 'image_license_link'
49 def nonempty_text(self, cite):
52 return "(%s)" % (cite.image_title or cite.link or '-').strip()
53 nonempty_text.short_description = _('text')
55 def has_image(self, cite):
56 return bool(cite.image)
57 has_image.short_description = _('image')
58 has_image.boolean = True
61 admin.site.register(Cite, CiteAdmin)
64 class BannerGroupAdmin(admin.ModelAdmin):
65 list_display = ['name', 'created_at']
66 fields = ['name', 'created_at']
67 readonly_fields = ['created_at']
69 admin.site.register(BannerGroup, BannerGroupAdmin)
72 class CarouselItemInline(OrderableAdmin, admin.TabularInline):
74 ordering_field = 'order'
77 class CarouselAdmin(admin.ModelAdmin):
78 inlines = [CarouselItemInline]
81 admin.site.register(Carousel, CarouselAdmin)