Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
[613329] Videos can link to CDN if setting provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Craciunoiu committed Nov 20, 2010
1 parent 3e47b02 commit b51d8b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apps/wiki/parser.py
@@ -1,4 +1,5 @@
from itertools import count
from os.path import basename
import re
from xml.sax.saxutils import quoteattr

Expand Down Expand Up @@ -377,15 +378,21 @@ def generate_video(v, params=[]):
"""Takes a video object and returns HTML markup for embedding it."""
sources = []
if v.webm:
sources.append({'src': v.webm.url, 'type': 'webm'})
sources.append({'src': _get_video_url(v.webm), 'type': 'webm'})
if v.ogv:
sources.append({'src': v.ogv.url, 'type': 'ogg'})
sources.append({'src': _get_video_url(v.ogv), 'type': 'ogg'})
data_fallback = ''
# Flash fallback
if v.flv:
data_fallback = v.flv.url
data_fallback = _get_video_url(v.flv)
return jingo.env.get_template('wikiparser/hook_video.html').render(
{'fallback': data_fallback, 'sources': sources, 'params': params,
'video': v,
'height': settings.WIKI_VIDEO_HEIGHT,
'width': settings.WIKI_VIDEO_WIDTH})


def _get_video_url(video_file):
if settings.GALLERY_VIDEO_URL:
return settings.GALLERY_VIDEO_URL + basename(video_file.name)
return video_file.url
17 changes: 17 additions & 0 deletions apps/wiki/tests/test_parser.py
@@ -1,3 +1,5 @@
from copy import deepcopy

from django.conf import settings

from nose.tools import eq_
Expand Down Expand Up @@ -400,6 +402,21 @@ def test_video_modal_caption_text(self):
eq_('WOOT', doc('.video-modal h1').text())
eq_('Place<b>holder</b>', doc('.video-placeholder').html().strip())

def test_video_cdn(self):
"""Video URLs can link to the CDN if a CDN setting is set."""
video()
cdn_url = 'http://videos.mozilla.org/serv/sumo/'

self.old_settings = deepcopy(settings._wrapped.__dict__)
settings.GALLERY_VIDEO_URL = cdn_url
d, _, p = doc_rev_parser('[[V:Some title]]')
settings._wrapped.__dict__ = self.old_settings

doc = pq(d.html)
eq_(cdn_url + 'test.flv', doc('video').attr('data-fallback'))
eq_(cdn_url + 'test.webm', doc('source').eq(0).attr('src'))
eq_(cdn_url + 'test.ogv', doc('source').eq(1).attr('src'))


def parsed_eq(want, to_parse):
p = WikiParser()
Expand Down
3 changes: 3 additions & 0 deletions docs/production.rst
Expand Up @@ -106,6 +106,9 @@ Here are the currently defined upload settings. All paths are relative to
``uploads/images/thumbnails/``.
``IMAGE_UPLOAD_PATH``
Images for questions, defaults to ``uploads/images/``.
``GALLERY_VIDEO_URL``
Prefix for video URLs, which can point to the CDN. E.g.
``http://videos.mozilla.org/serv/sumo/``
``GALLERY_IMAGE_THUMBNAIL_PATH``, ``GALLERY_VIDEO_THUMBNAIL_PATH``
Thumbnails of video/images for the media gallery, defaults to
``uploads/gallery/thumbnails/``.
Expand Down
1 change: 1 addition & 0 deletions settings.py
Expand Up @@ -524,6 +524,7 @@ def read_only_mode(env):
GALLERY_IMAGE_PATH = 'uploads/gallery/images/'
GALLERY_IMAGE_THUMBNAIL_PATH = 'uploads/gallery/images/thumbnails/'
GALLERY_VIDEO_PATH = 'uploads/gallery/videos/'
GALLERY_VIDEO_URL = None
GALLERY_VIDEO_THUMBNAIL_PATH = 'uploads/gallery/videos/thumbnails/'
GALLERY_VIDEO_THUMBNAIL_PROGRESS_URL = MEDIA_URL + 'img/video-thumb.png'
THUMBNAIL_PROGRESS_WIDTH = 32 # width of the above image
Expand Down

0 comments on commit b51d8b5

Please sign in to comment.