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 autocomplete_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'
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 = _('text')
52 def has_image(self, cite):
53 return bool(cite.image)
54 has_image.short_description = _('image')
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'
74 class CarouselAdmin(admin.ModelAdmin):
75 list_display = ['placement', 'priority', 'language']
76 inlines = [CarouselItemInline]
79 admin.site.register(Carousel, CarouselAdmin)