-
Notifications
You must be signed in to change notification settings - Fork 6
/
cms_plugins.py
55 lines (42 loc) · 1.49 KB
/
cms_plugins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import copy
from django.utils.translation import gettext_lazy as _
from cms.plugin_pool import plugin_pool
from djangocms_picture.cms_plugins import PicturePlugin
from djangocms_bootstrap5.helpers import concat_classes
from .models import Bootstrap5Picture
class Bootstrap5PicturePlugin(PicturePlugin):
"""
Content > "Image" Plugin
https://getbootstrap.com/docs/5.0/content/images/
"""
model = Bootstrap5Picture
name = _('Picture / Image')
change_form_template = 'djangocms_bootstrap5/admin/picture.html'
module = _('Bootstrap 5')
fieldsets = copy.deepcopy(PicturePlugin.fieldsets)
fieldsets[0] = (
None, {
'fields': (
'picture',
'external_picture',
('picture_fluid', 'picture_rounded', 'picture_thumbnail'),
)
}
)
def render(self, context, instance, placeholder):
link_classes = []
if instance.picture_fluid:
link_classes.append('img-fluid')
if instance.picture_rounded:
link_classes.append('rounded')
if instance.picture_thumbnail:
link_classes.append('img-thumbnail')
classes = concat_classes(link_classes + [
instance.attributes.get('class'),
])
instance.attributes['class'] = classes
return super().render(
context, instance, placeholder
)
plugin_pool.unregister_plugin(PicturePlugin)
plugin_pool.register_plugin(Bootstrap5PicturePlugin)