Commit be37277e authored by Liam Brenner's avatar Liam Brenner
Browse files

Can now edit/preview videos WIP

parent 95a331b9
{% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags staticfiles i18n %}
{% block titletag %}{% blocktrans with title=image.title %}Editing image {{ title }}{% endblocktrans %}{% endblock %}
{% block extra_css %}
{{ block.super }}
<!-- Focal point chooser -->
<link rel="stylesheet" href="{% static 'wagtailimages/css/vendor/jquery.Jcrop.min.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'wagtailimages/css/focal-point-chooser.css' %}" type="text/css">
{% endblock %}
{% block titletag %}{% blocktrans with title=video.title %}Editing video {{ title }}{% endblocktrans %}{% endblock %}
{% block extra_js %}
{{ block.super }}
......@@ -20,21 +13,16 @@
});
});
</script>
<!-- Focal point chooser -->
<script src="{% static 'wagtailadmin/js/vendor/jquery.ba-throttle-debounce.min.js' %}"></script>
<script src="{% static 'wagtailimages/js/vendor/jquery.Jcrop.min.js' %}"></script>
<script src="{% static 'wagtailimages/js/focal-point-chooser.js' %}"></script>
{% endblock %}
{% block content %}
{% trans "Editing" as editing_str %}
{% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=image.title icon="image" usage_object=image %}
{% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=video.title icon="image" usage_object=video %}
<div class="row row-flush nice-padding">
<div class="col5">
<form action="{% url 'wagtailimages:edit' image.id %}" method="POST" enctype="multipart/form-data">
<form action="{% url 'wagtailvideos:edit' video.id %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<ul class="fields">
{% for field in form %}
......@@ -51,17 +39,19 @@
<li>
<input type="submit" value="{% trans 'Save' %}" />
{% if user_can_delete %}
<a href="{% url 'wagtailimages:delete' image.id %}" class="button button-secondary no">{% trans "Delete image" %}</a>
<a href="{% url 'wagtailvideos:delete' video.id %}" class="button button-secondary no">{% trans "Delete video" %}</a>
{% endif %}
</li>
</ul>
</form>
</div>
<div class="col5 divider-after">
<h2 class="label">{% trans "Focal point (optional)" %}</h2>
<p>{% trans "To define this image's most important region, drag a box over the image below." %} {% if image.focal_point %}({% trans "Current focal point shown" %}){% endif %}</p>
<h2 class="label">{% trans "Video preview" %}</h2>
{% image image max-800x600 as rendition %}
<video style='max-width:100%;height:auto;' {# FIXME Inline styles #} preload="auto" controls="true" poster='{{video.thumbnail.url}}'>
<source src="{{video.file.url}}" type='video/mp4'/>
</video>
<!--img src='{{video.thumbnail.url}}' /-->
<div class="focal-point-chooser"
style="max-width: {{ rendition.width }}px; max-height: {{ rendition.height }}px;"
......@@ -78,15 +68,13 @@
</div>
<div class="col2 ">
{% if url_generator_enabled %}
<a href="{% url 'wagtailimages:url_generator' image.id %}" class="button bicolor icon icon-link">{% trans "URL Generator" %}</a>
<a href="{% url 'wagtailvideos:url_generator' video.id %}" class="button bicolor icon icon-link">{% trans "URL Generator" %}</a>
<hr />
{% endif %}
{% image image original as original_image %}
<img src='{{video.thumbnail.url}}' />
<dl>
<dt>{% trans "Max dimensions" %}</dt>
<dd>{{ original_image.width }}x{{ original_image.height }}</dd>
<dt>{% trans "Filesize" %}</dt>
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
</dl>
......
{% load wagtailadmin_tags %}
{% load i18n %}
{% if images %}
{% if videos %}
{% if is_searching %}
<h2>
{% blocktrans count counter=images.paginator.count %}
{% blocktrans count counter=video.paginator.count %}
There is one match
{% plural %}
There are {{ counter }} matches
......@@ -16,17 +16,17 @@
{% endif %}
<ul class="listing horiz images">
{% for image in images %}
{% for video in videos %}
<li>
<a class="image-choice" href="{% url 'wagtailimages:edit' image.id %}">
<a class="image-choice" href="{% url 'wagtailvideos:edit' video.id %}">
{% include "wagtailvideos/videos/results_image.html" %}
<h3>{{ image.title|ellipsistrim:60 }}</h3>
<h3>{{ video.title|ellipsistrim:60 }}</h3>
</a>
</li>
{% endfor %}
</ul>
{% include "wagtailadmin/shared/pagination_nav.html" with items=images is_searching=is_searching query_string=query_string linkurl="wagtailimages:index" %}
{% include "wagtailadmin/shared/pagination_nav.html" with items=videos is_searching=is_searching query_string=query_string linkurl="wagtailvideos:index" %}
{% else %}
{% if is_searching %}
......@@ -34,11 +34,11 @@
{% search_other %}
{% else %}
{% url 'wagtailimages:add_multiple' as wagtailimages_add_image_url %}
{% url 'wagtailvideos:add_multiple' as wagtailvideos_add_video_url %}
{% if current_collection %}
<p>{% blocktrans %}You've not uploaded any videos in this collection. Why not <a href="{{ wagtailimages_add_image_url }}">add one now</a>?{% endblocktrans %}</p>
<p>{% blocktrans %}You've not uploaded any videos in this collection. Why not <a href="{{ wagtailvideos_add_video_url }}">add one now</a>?{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans %}You've not uploaded any videos. Why not <a href="{{ wagtailimages_add_image_url }}">add one now</a>?{% endblocktrans %}</p>
<p>{% blocktrans %}You've not uploaded any videos. Why not <a href="{{ wagtailvideos_add_video_url }}">add one now</a>?{% endblocktrans %}</p>
{% endif %}
{% endif %}
{% endif %}
......@@ -14,4 +14,4 @@
{% endcomment %}
<div class="image"><img src='{{image.thumbnail.url}}' height=165 width=165 class="show-transparency" /></img></div>
<div class="image"><img src='{{video.thumbnail.url}}' height=165 width=165 class="show-transparency" /></img></div>
......@@ -53,7 +53,7 @@ def index(request):
})
else:
return render(request, 'wagtailvideos/videos/index.html', {
'images': videos,
'videos': videos,
'query_string': query_string,
'is_searching': bool(query_string),
......@@ -63,40 +63,39 @@ def index(request):
})
def edit(request, image_id):
Image = get_video_model()
ImageForm = get_video_form(Image)
def edit(request, video_id):
Video = get_video_model()
VideoForm = get_video_form(Video)
image = get_object_or_404(Image, id=image_id)
video = get_object_or_404(Video, id=video_id)
if request.POST:
original_file = image.file
form = ImageForm(request.POST, request.FILES, instance=image, user=request.user)
original_file = video.file
form = VideoForm(request.POST, request.FILES, instance=video)
if form.is_valid():
if 'file' in form.changed_data:
# if providing a new image file, delete the old one and all renditions.
# NB Doing this via original_file.delete() clears the file field,
# which definitely isn't what we want...
original_file.storage.delete(original_file.name)
image.renditions.all().delete()
# Set new image file size
image.file_size = image.file.size
video.file_size = video.file.size
form.save()
# Reindex the image to make sure all tags are indexed
for backend in get_search_backends():
backend.add(image)
backend.add(video)
messages.success(request, _("Image '{0}' updated.").format(image.title), buttons=[
messages.button(reverse('wagtailvideos:edit', args=(image.id,)), _('Edit again'))
messages.success(request, _("Video '{0}' updated.").format(video.title), buttons=[
messages.button(reverse('wagtailvideos:edit', args=(video.id,)), _('Edit again'))
])
return redirect('wagtailvideos:index')
else:
messages.error(request, _("The image could not be saved due to errors."))
messages.error(request, _("The video could not be saved due to errors."))
else:
form = ImageForm(instance=image, user=request.user)
form = VideoForm(instance=video)
# Check if we should enable the frontend url generator
try:
......@@ -105,20 +104,20 @@ def edit(request, image_id):
except NoReverseMatch:
url_generator_enabled = False
if image.is_stored_locally():
if video.is_stored_locally():
# Give error if image file doesn't exist
if not os.path.isfile(image.file.path):
if not os.path.isfile(video.file.path):
messages.error(request, _(
"The source image file could not be found. Please change the source or delete the image."
).format(image.title), buttons=[
messages.button(reverse('wagtailvideos:delete', args=(image.id,)), _('Delete'))
"The source video file could not be found. Please change the source or delete the video."
).format(video.title), buttons=[
messages.button(reverse('wagtailvideos:delete', args=(video.id,)), _('Delete'))
])
return render(request, "wagtailvideos/images/edit.html", {
'image': image,
return render(request, "wagtailvideos/videos/edit.html", {
'video': video,
'form': form,
'url_generator_enabled': url_generator_enabled,
'filesize': image.get_file_size(),
'filesize': video.get_file_size(),
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment