Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Wagtail Videos
Commits
95a331b9
Commit
95a331b9
authored
Apr 14, 2016
by
Liam Brenner
Browse files
WIP
parent
6af62859
Changes
8
Hide whitespace changes
Inline
Side-by-side
README.rst
View file @
95a331b9
...
...
@@ -12,7 +12,7 @@ A wagtail module for uploading and displaying videos in various codecs.
Installing
==========
**This package is not on PyPI yet**
**This package is not on PyPI yet**
yayyy
Install using pip::
pip install wagtailvideos
...
...
wagtailvideos/edit_handlers.py
0 → 100644
View file @
95a331b9
from
__future__
import
absolute_import
,
unicode_literals
from
wagtail.wagtailadmin.edit_handlers
import
BaseChooserPanel
from
.widgets
import
AdminVideoChooser
class
BaseVideoChooserPanel
(
BaseChooserPanel
):
object_type_name
=
"video"
@
classmethod
def
widget_overrides
(
cls
):
return
{
cls
.
field_name
:
AdminVideoChooser
}
class
VideoChooserPanel
(
object
):
def
__init__
(
self
,
field_name
):
self
.
field_name
=
field_name
def
bind_to_model
(
self
,
model
):
return
type
(
str
(
'_VideoChooserPanel'
),
(
BaseVideoChooserPanel
,),
{
'model'
:
model
,
'field_name'
:
self
.
field_name
,
})
wagtailvideos/templates/wagtailvideos/chooser/chooser.html
View file @
95a331b9
...
...
@@ -31,7 +31,7 @@
</ul>
</form>
<div
id=
"image-results"
>
{% include "wagtail
image
s/chooser/results.html" %}
{% include "wagtail
video
s/chooser/results.html" %}
</div>
</section>
{% if uploadform %}
...
...
wagtailvideos/templates/wagtailvideos/chooser/results.html
View file @
95a331b9
...
...
@@ -16,8 +16,8 @@
<ul
class=
"listing horiz images chooser"
>
{% for video in videos %}
<li>
<a
class=
"image-choice"
href=
"{% if will_select_format %}{% url 'wagtail
image
s:chooser_select_format'
image
.id %}{% else %}{% url 'wagtail
images:image
_chosen'
image
.id %}{% endif %}"
>
<div
class=
"image"
>
{% image image max-165x
165 class="show-transparency"
%}
</div>
<a
class=
"image-choice"
href=
"{% if will_select_format %}{% url 'wagtail
video
s:chooser_select_format'
video
.id %}{% else %}{% url 'wagtail
videos:video
_chosen'
video
.id %}{% endif %}"
>
<div
class=
"image"
>
<img
src=
'{{video.thumbnail.url}}'
width=
"165"
height=
"
165
"
class=
"show-transparency"
>
</div>
<h3>
{{ video.title|ellipsistrim:60 }}
</h3>
</a>
</li>
...
...
wagtailvideos/templates/wagtailvideos/chooser/
image
_chosen.js
→
wagtailvideos/templates/wagtailvideos/chooser/
video
_chosen.js
View file @
95a331b9
function
(
modal
)
{
modal
.
respond
(
'
image
Chosen
'
,
{{
image
_json
|
safe
}});
modal
.
respond
(
'
video
Chosen
'
,
{{
video
_json
|
safe
}});
modal
.
close
();
}
wagtailvideos/templates/wagtailvideos/widgets/
image
_chooser.html
→
wagtailvideos/templates/wagtailvideos/widgets/
video
_chooser.html
View file @
95a331b9
...
...
@@ -5,12 +5,12 @@
{% block chosen_state_view %}
<div
class=
"preview-image"
>
{% if
image
%}
{% image image max-165x
165 class="show-transparency"
%}
{% if
video
%}
<img
src=
'{{video.thumbnail.url}}'
width=
"165"
height=
"
165
"
class=
"show-transparency"
>
{% else %}
<img>
{% endif %}
</div>
{% endblock %}
{% block edit_chosen_item_url %}{% if
image
%}{% url 'wagtail
image
s:edit'
image
.id %}{% endif %}{% endblock %}
{% block edit_chosen_item_url %}{% if
video
%}{% url 'wagtail
video
s:edit'
video
.id %}{% endif %}{% endblock %}
wagtailvideos/views/chooser.py
View file @
95a331b9
...
...
@@ -12,21 +12,18 @@ from wagtailvideos.forms import VideoInsertionForm, get_video_form
from
wagtailvideos.models
import
get_video_model
def
get_video_json
(
image
):
def
get_video_json
(
video
):
"""
helper function: given an image, return the json to pass back to the
image chooser panel
"""
preview_image
=
image
.
get_rendition
(
'max-165x165'
)
return
json
.
dumps
({
'id'
:
image
.
id
,
'edit_link'
:
reverse
(
'wagtail
image
s:edit'
,
args
=
(
image
.
id
,)),
'title'
:
image
.
title
,
'id'
:
video
.
id
,
'edit_link'
:
reverse
(
'wagtail
video
s:edit'
,
args
=
(
video
.
id
,)),
'title'
:
video
.
title
,
'preview'
:
{
'url'
:
preview_image
.
url
,
'width'
:
preview_image
.
width
,
'height'
:
preview_image
.
height
,
'url'
:
video
.
thumbnail
.
url
,
}
})
...
...
@@ -97,7 +94,7 @@ def video_chosen(request, video_id):
video
=
get_object_or_404
(
get_video_model
(),
id
=
video_id
)
return
render_modal_workflow
(
request
,
None
,
'wagtailvideos/chooser/
image
_chosen.js'
,
request
,
None
,
'wagtailvideos/chooser/
video
_chosen.js'
,
{
'video_json'
:
get_video_json
(
video
)}
)
...
...
wagtailvideos/widgets.py
0 → 100644
View file @
95a331b9
from
__future__
import
absolute_import
,
unicode_literals
import
json
from
django.template.loader
import
render_to_string
from
django.utils.translation
import
ugettext_lazy
as
_
from
wagtail.wagtailadmin.widgets
import
AdminChooser
from
wagtailvideos.models
import
get_video_model
class
AdminVideoChooser
(
AdminChooser
):
choose_one_text
=
_
(
'Choose a video'
)
choose_another_text
=
_
(
'Choose another video'
)
link_to_chosen_text
=
_
(
'Edit this video'
)
def
__init__
(
self
,
**
kwargs
):
super
(
AdminVideoChooser
,
self
).
__init__
(
**
kwargs
)
self
.
video_model
=
get_video_model
()
def
render_html
(
self
,
name
,
value
,
attrs
):
instance
,
value
=
self
.
get_instance_and_id
(
self
.
video_model
,
value
)
original_field_html
=
super
(
AdminVideoChooser
,
self
).
render_html
(
name
,
value
,
attrs
)
return
render_to_string
(
"wagtailvideos/widgets/video_chooser.html"
,
{
'widget'
:
self
,
'original_field_html'
:
original_field_html
,
'attrs'
:
attrs
,
'value'
:
value
,
'video'
:
instance
,
})
def
render_js_init
(
self
,
id_
,
name
,
value
):
return
"createVideoChooser({0});"
.
format
(
json
.
dumps
(
id_
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment