[613329] Videos can link to CDN if setting provided.

This commit is contained in:
Paul Craciunoiu 2010-11-19 16:11:01 -08:00
Родитель 3e47b027a3
Коммит b51d8b5cee
4 изменённых файлов: 31 добавлений и 3 удалений

Просмотреть файл

@ -1,4 +1,5 @@
from itertools import count
from os.path import basename
import re
from xml.sax.saxutils import quoteattr
@ -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

Просмотреть файл

@ -1,3 +1,5 @@
from copy import deepcopy
from django.conf import settings
from nose.tools import eq_
@ -400,6 +402,21 @@ class TestWikiVideo(TestCase):
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()

Просмотреть файл

@ -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/``.

Просмотреть файл

@ -524,6 +524,7 @@ GALLERY_DEFAULT_LANGUAGE = WIKI_DEFAULT_LANGUAGE
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