Skip to content
This repository
Browse code

extensible embedded video plugin

  • Loading branch information...
commit 70ce3fd583023c29e2a23b6f5e88226eb90ffe16 1 parent e5a7fcc
Daniele Procida authored
20 arkestra_image_plugin/cms_plugins.py
@@ -15,7 +15,8 @@
15 15 from widgetry.tabs.admin import ModelAdminWithTabs
16 16 from widgetry import fk_lookup
17 17
18   -from arkestra_utilities.settings import IMAGESET_ITEM_PADDING
  18 +from arkestra_utilities.settings import IMAGESET_ITEM_PADDING, VIDEO_HOSTING_SERVICES
  19 +
19 20 from arkestra_utilities.output_libraries.plugin_widths import get_placeholder_width, calculate_container_width
20 21 from arkestra_utilities.admin_mixins import AutocompleteMixin, SupplyRequestMixin
21 22
@@ -531,10 +532,8 @@ def icon_src(self, instance):
531 532
532 533 plugin_pool.register_plugin(FilerImagePlugin)
533 534
  535 +
534 536 class EmbeddedVideoSetItemEditor(SupplyRequestMixin, admin.StackedInline, AutocompleteMixin):
535   - # form = ImageSetItemPluginForm
536   - # formset = ImageSetItemFormFormSet
537   - # related_search_fields = ['destination_content_type']
538 537 model=EmbeddedVideoSetItem
539 538 extra=1
540 539 fieldsets = (
@@ -542,21 +541,14 @@ class EmbeddedVideoSetItemEditor(SupplyRequestMixin, admin.StackedInline, Autoco
542 541 'fields': (
543 542 ('service', 'video_code', 'aspect_ratio'),
544 543 ('video_title', 'video_autoplay'),
545   - ('active', ),
  544 + ('active', 'inline_item_ordering'),
546 545 ),
547 546 }),
548   - # ('Other options', {
549   - # 'fields': (
550   - # 'video_caption',
551   - # ),
552   - # 'classes': ('collapse',),
553   - # })
554 547 )
555 548
556 549
557 550 class EmbeddedVideoPlugin(CMSPluginBase):
558 551 model = EmbeddedVideoSetPlugin
559   - render_template = "arkestra_image_plugin/embedded_video_plugin.html"
560 552 admin_preview = False
561 553
562 554 name = "Embedded video set"
@@ -583,6 +575,7 @@ def render(self, context, embeddedvideoset, placeholder):
583 575 width = int(width_of_image_container(context, embeddedvideoset))
584 576 height = int(width/video.aspect_ratio)
585 577
  578 + self.render_template = VIDEO_HOSTING_SERVICES[video.service]["template"]
586 579 context.update({
587 580 'embeddedvideoset': embeddedvideoset,
588 581 'video': video,
@@ -593,9 +586,6 @@ def render(self, context, embeddedvideoset, placeholder):
593 586 # no items, use a null template
594 587 else:
595 588 self.render_template = "null.html"
596   - # context.update({
597   - # 'placeholder':placeholder,
598   - # })
599 589 return context
600 590
601 591
7 arkestra_image_plugin/models.py
@@ -12,6 +12,8 @@
12 12 from filer.fields.file import FilerFileField
13 13
14 14 from arkestra_utilities.import_free_model_mixins import ArkestraGenericPluginItemOrdering
  15 +from arkestra_utilities.settings import VIDEO_HOSTING_SERVICES
  16 +
15 17 from links.models import LinkMethodsMixin
16 18
17 19 class FilerImage(CMSPlugin):
@@ -281,10 +283,7 @@ class Meta:
281 283 EmbeddedVideoSetPlugin,
282 284 related_name="embeddedvideoset_item"
283 285 )
284   - SERVICES = (
285   - ("vimeo", "Vimeo"),
286   - ("youtube", "YouTube"),
287   - )
  286 + SERVICES = [(service, values["name"]) for service,values in VIDEO_HOSTING_SERVICES.items()]
288 287 service = models.CharField(choices = SERVICES, max_length = 50)
289 288 video_code = models.CharField(max_length=255,
290 289 help_text = "Not the full URL."
22 arkestra_image_plugin/templates/arkestra_image_plugin/embedded_video_plugin.html
... ... @@ -1,22 +0,0 @@
1   -{% if video.service == "youtube" %}
2   - <iframe id="youtubeplayer-{{ embeddedvideoset.id }}"
3   - type="text/html"
4   - width="{{ width }}"
5   - height="{{ height }}"
6   - frameborder="0"
7   - src="http://www.youtube.com/embed/{{ video.video_code }}?autoplay={{ video.video_autoplay|yesno:"1,0,0" }}&modestbranding=0&theme=light"
8   - />
9   - </iframe>
10   -
11   -{% elif video.service == "vimeo" %}
12   - <iframe
13   - id="vimeoplayer-{{ embeddedvideoset.id }}"
14   - width="{{ width }}"
15   - height="{{ height }}"
16   - frameborder="0"
17   - webkitAllowFullScreen mozallowfullscreen allowFullScreen
18   - src="http://player.vimeo.com/video/{{ video.video_code }}?autoplay={{ video.video_autoplay|yesno:"1,0,0" }}"
19   - />
20   - </iframe>
21   -
22   -{% endif %}
9 arkestra_image_plugin/templates/embedded_video/vimeo.html
... ... @@ -0,0 +1,9 @@
  1 +<iframe
  2 + id="vimeoplayer-{{ embeddedvideoset.id }}"
  3 + width="{{ width }}"
  4 + height="{{ height }}"
  5 + frameborder="0"
  6 + webkitAllowFullScreen mozallowfullscreen allowFullScreen
  7 + src="http://player.vimeo.com/video/{{ video.video_code }}?autoplay={{ video.video_autoplay|yesno:"1,0,0" }}"
  8 + />
  9 +</iframe>
8 arkestra_image_plugin/templates/embedded_video/youtube.html
... ... @@ -0,0 +1,8 @@
  1 +<iframe id="youtubeplayer-{{ embeddedvideoset.id }}"
  2 + type="text/html"
  3 + width="{{ width }}"
  4 + height="{{ height }}"
  5 + frameborder="0"
  6 + src="http://www.youtube.com/embed/{{ video.video_code }}?autoplay={{ video.video_autoplay|yesno:"1,0,0" }}&modestbranding=0&theme=light"
  7 + />
  8 +</iframe>
6 arkestra_utilities/settings.py
@@ -99,6 +99,12 @@
99 99
100 100 USE_CELERY_FOR_VIDEO_ENCODING = getattr(settings, "USE_CELERY_FOR_VIDEO_ENCODING", False)
101 101
  102 +VIDEO_HOSTING_SERVICES = getattr(settings, "VIDEO_HOSTING_SERVICES", {
  103 + "vimeo": {"name": "Vimeo", "template": "embedded_video/vimeo.html"},
  104 + "youtube": {"name": "YouTube", "template": "embedded_video/youtube.html"},
  105 + }
  106 + )
  107 +
102 108 # -------- Django CMS ----------------------
103 109
104 110 CMS_SEO_FIELDS = getattr(settings, "CMS_SEO_FIELDS", True)

0 comments on commit 70ce3fd

Please sign in to comment.
Something went wrong with that request. Please try again.