File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,8 @@ Here is an example:
113
113
from __future__ import unicode_literals
114
114
115
115
from django.db import models
116
- from django.utils.html import format_html
116
+ from django.forms.utils import flatatt
117
+ from django.utils.html import format_html, format_html_join
117
118
118
119
from wagtail.wagtailcore.models import Page
119
120
from wagtail.wagtailcore.fields import StreamField
@@ -132,7 +133,7 @@ class TestMediaBlock(AbstractMediaChooserBlock):
132
133
player_code = '''
133
134
<div>
134
135
<video width="320" height="240" controls>
135
- <source src=" {0} " type="video/mp4">
136
+ {0}
136
137
Your browser does not support the video tag.
137
138
</video>
138
139
</div>
@@ -141,13 +142,16 @@ class TestMediaBlock(AbstractMediaChooserBlock):
141
142
player_code = '''
142
143
<div>
143
144
<audio controls>
144
- <source src=" {0} " type="audio/mpeg">
145
+ {0}
145
146
Your browser does not support the audio element.
146
147
</audio>
147
148
</div>
148
149
'''
149
150
150
- return format_html(player_code, value.file.url)
151
+ return format_html(player_code, format_html_join(
152
+ ' \n ' , " <source{0} >" ,
153
+ [[flatatt(s)] for s in value.sources]
154
+ ))
151
155
152
156
153
157
class BlogPage (Page ):
Original file line number Diff line number Diff line change 1
1
from __future__ import unicode_literals
2
2
3
+ import mimetypes
3
4
import os .path
4
5
5
6
from django .conf import settings
@@ -80,6 +81,13 @@ def file_extension(self):
80
81
def url (self ):
81
82
return self .file .url
82
83
84
+ @property
85
+ def sources (self ):
86
+ return [{
87
+ 'src' : self .url ,
88
+ 'type' : mimetypes .guess_type (self .filename )[0 ],
89
+ }]
90
+
83
91
def get_usage (self ):
84
92
return get_object_usage (self )
85
93
Original file line number Diff line number Diff line change 1
1
from __future__ import unicode_literals
2
2
3
+ from django .core .files import File
4
+ from django .core .files .base import ContentFile
3
5
from django .test import TestCase
4
6
7
+ from six import b
8
+
5
9
from wagtailmedia import models
6
10
from wagtailmedia .forms import get_media_form
7
11
@@ -53,3 +57,25 @@ def test_audio_form_presents_thumbnail(self):
53
57
MediaForm = get_media_form (models .Media )
54
58
media = models .Media .objects .create (title = "Test media file" , type = 'audio' , duration = 100 )
55
59
self .assertIn ('thumbnail' , MediaForm (instance = media ).fields .keys ())
60
+
61
+
62
+ class TestAbstractMediaInterfaceModel (TestCase ):
63
+ def test_sources_mp4_type (self ):
64
+ fake_file = ContentFile (b ("A boring example movie" ))
65
+ fake_file .name = 'movie.mp4'
66
+ media = models .Media ()
67
+ media .file = File (fake_file )
68
+ self .assertEqual (media .sources , [{
69
+ 'src' : '/media/movie.mp4' ,
70
+ 'type' : 'video/mp4' ,
71
+ }])
72
+
73
+ def test_sources_unknown_type (self ):
74
+ fake_file = ContentFile (b ("A boring example movie" ))
75
+ fake_file .name = 'movie'
76
+ media = models .Media ()
77
+ media .file = File (fake_file )
78
+ self .assertEqual (media .sources , [{
79
+ 'src' : '/media/movie' ,
80
+ 'type' : None ,
81
+ }])
You can’t perform that action at this time.
0 commit comments