-
Notifications
You must be signed in to change notification settings - Fork 45
/
cms_plugins.py
105 lines (89 loc) · 2.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _
from . import forms, models
class VideoPlayerPlugin(CMSPluginBase):
model = models.VideoPlayer
name = _('Video player')
text_enabled = True
allow_children = True
child_classes = ['VideoSourcePlugin', 'VideoTrackPlugin']
form = forms.VideoPlayerPluginForm
fieldsets = [
(None, {
'fields': (
'template',
'label',
)
}),
(_('Embed video'), {
'classes': ('collapse',),
'fields': (
'embed_link',
'parameters',
)
}),
(_('Advanced settings'), {
'classes': ('collapse',),
'fields': (
'poster',
'attributes',
)
})
]
def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
context['video_template'] = instance.template
return context
def get_render_template(self, context, instance, placeholder):
return 'djangocms_video/{}/video_player.html'.format(instance.template)
class VideoSourcePlugin(CMSPluginBase):
model = models.VideoSource
name = _('Source')
module = _('Video player')
require_parent = True
parent_classes = ['VideoPlayerPlugin']
fieldsets = [
(None, {
'fields': (
'source_file',
'text_title',
)
}),
(_('Advanced settings'), {
'classes': ('collapse',),
'fields': (
'text_description',
'attributes',
)
})
]
def get_render_template(self, context, instance, placeholder):
return 'djangocms_video/{}/source.html'.format(context.get('video_template', 'default'))
class VideoTrackPlugin(CMSPluginBase):
model = models.VideoTrack
name = _('Track')
module = _('Video player')
require_parent = True
parent_classes = ['VideoPlayerPlugin']
fieldsets = [
(None, {
'fields': (
'kind',
'src',
'srclang',
)
}),
(_('Advanced settings'), {
'classes': ('collapse',),
'fields': (
'label',
'attributes',
)
})
]
def get_render_template(self, context, instance, placeholder):
return 'djangocms_video/{}/track.html'.format(context.get('video_template', 'default'))
plugin_pool.register_plugin(VideoPlayerPlugin)
plugin_pool.register_plugin(VideoSourcePlugin)
plugin_pool.register_plugin(VideoTrackPlugin)