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

Can now edit/preview videos WIP

parent 95a331b9
{% extends "wagtailadmin/base.html" %} {% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags staticfiles i18n %} {% load wagtailimages_tags staticfiles i18n %}
{% block titletag %}{% blocktrans with title=image.title %}Editing image {{ title }}{% endblocktrans %}{% endblock %} {% block titletag %}{% blocktrans with title=video.title %}Editing video {{ 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 extra_js %} {% block extra_js %}
{{ block.super }} {{ block.super }}
...@@ -20,21 +13,16 @@ ...@@ -20,21 +13,16 @@
}); });
}); });
</script> </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 %} {% endblock %}
{% block content %} {% block content %}
{% trans "Editing" as editing_str %} {% 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="row row-flush nice-padding">
<div class="col5"> <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 %} {% csrf_token %}
<ul class="fields"> <ul class="fields">
{% for field in form %} {% for field in form %}
...@@ -51,17 +39,19 @@ ...@@ -51,17 +39,19 @@
<li> <li>
<input type="submit" value="{% trans 'Save' %}" /> <input type="submit" value="{% trans 'Save' %}" />
{% if user_can_delete %} {% 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 %} {% endif %}
</li> </li>
</ul> </ul>
</form> </form>
</div> </div>
<div class="col5 divider-after"> <div class="col5 divider-after">
<h2 class="label">{% trans "Focal point (optional)" %}</h2> <h2 class="label">{% trans "Video preview" %}</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>
{% 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" <div class="focal-point-chooser"
style="max-width: {{ rendition.width }}px; max-height: {{ rendition.height }}px;" style="max-width: {{ rendition.width }}px; max-height: {{ rendition.height }}px;"
...@@ -78,15 +68,13 @@ ...@@ -78,15 +68,13 @@
</div> </div>
<div class="col2 "> <div class="col2 ">
{% if url_generator_enabled %} {% 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 /> <hr />
{% endif %} {% endif %}
{% image image original as original_image %} <img src='{{video.thumbnail.url}}' />
<dl> <dl>
<dt>{% trans "Max dimensions" %}</dt>
<dd>{{ original_image.width }}x{{ original_image.height }}</dd>
<dt>{% trans "Filesize" %}</dt> <dt>{% trans "Filesize" %}</dt>
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd> <dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
</dl> </dl>
......
{% load wagtailadmin_tags %} {% load wagtailadmin_tags %}
{% load i18n %} {% load i18n %}
{% if images %} {% if videos %}
{% if is_searching %} {% if is_searching %}
<h2> <h2>
{% blocktrans count counter=images.paginator.count %} {% blocktrans count counter=video.paginator.count %}
There is one match There is one match
{% plural %} {% plural %}
There are {{ counter }} matches There are {{ counter }} matches
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
{% endif %} {% endif %}
<ul class="listing horiz images"> <ul class="listing horiz images">
{% for image in images %} {% for video in videos %}
<li> <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" %} {% include "wagtailvideos/videos/results_image.html" %}
<h3>{{ image.title|ellipsistrim:60 }}</h3> <h3>{{ video.title|ellipsistrim:60 }}</h3>
</a> </a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </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 %} {% else %}
{% if is_searching %} {% if is_searching %}
...@@ -34,11 +34,11 @@ ...@@ -34,11 +34,11 @@
{% search_other %} {% search_other %}
{% else %} {% else %}
{% url 'wagtailimages:add_multiple' as wagtailimages_add_image_url %} {% url 'wagtailvideos:add_multiple' as wagtailvideos_add_video_url %}
{% if current_collection %} {% 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 %} {% 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 %} {% endif %}
{% endif %} {% endif %}
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
{% endcomment %} {% 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): ...@@ -53,7 +53,7 @@ def index(request):
}) })
else: else:
return render(request, 'wagtailvideos/videos/index.html', { return render(request, 'wagtailvideos/videos/index.html', {
'images': videos, 'videos': videos,
'query_string': query_string, 'query_string': query_string,
'is_searching': bool(query_string), 'is_searching': bool(query_string),
...@@ -63,40 +63,39 @@ def index(request): ...@@ -63,40 +63,39 @@ def index(request):
}) })
def edit(request, image_id): def edit(request, video_id):
Image = get_video_model() Video = get_video_model()
ImageForm = get_video_form(Image) 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: if request.POST:
original_file = image.file original_file = video.file
form = ImageForm(request.POST, request.FILES, instance=image, user=request.user) form = VideoForm(request.POST, request.FILES, instance=video)
if form.is_valid(): if form.is_valid():
if 'file' in form.changed_data: if 'file' in form.changed_data:
# if providing a new image file, delete the old one and all renditions. # if providing a new image file, delete the old one and all renditions.
# NB Doing this via original_file.delete() clears the file field, # NB Doing this via original_file.delete() clears the file field,
# which definitely isn't what we want... # which definitely isn't what we want...
original_file.storage.delete(original_file.name) original_file.storage.delete(original_file.name)
image.renditions.all().delete()
# Set new image file size # Set new image file size
image.file_size = image.file.size video.file_size = video.file.size
form.save() form.save()
# Reindex the image to make sure all tags are indexed # Reindex the image to make sure all tags are indexed
for backend in get_search_backends(): for backend in get_search_backends():
backend.add(image) backend.add(video)
messages.success(request, _("Image '{0}' updated.").format(image.title), buttons=[ messages.success(request, _("Video '{0}' updated.").format(video.title), buttons=[
messages.button(reverse('wagtailvideos:edit', args=(image.id,)), _('Edit again')) messages.button(reverse('wagtailvideos:edit', args=(video.id,)), _('Edit again'))
]) ])
return redirect('wagtailvideos:index') return redirect('wagtailvideos:index')
else: 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: else:
form = ImageForm(instance=image, user=request.user) form = VideoForm(instance=video)
# Check if we should enable the frontend url generator # Check if we should enable the frontend url generator
try: try:
...@@ -105,20 +104,20 @@ def edit(request, image_id): ...@@ -105,20 +104,20 @@ def edit(request, image_id):
except NoReverseMatch: except NoReverseMatch:
url_generator_enabled = False url_generator_enabled = False
if image.is_stored_locally(): if video.is_stored_locally():
# Give error if image file doesn't exist # 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, _( messages.error(request, _(
"The source image file could not be found. Please change the source or delete the image." "The source video file could not be found. Please change the source or delete the video."
).format(image.title), buttons=[ ).format(video.title), buttons=[
messages.button(reverse('wagtailvideos:delete', args=(image.id,)), _('Delete')) messages.button(reverse('wagtailvideos:delete', args=(video.id,)), _('Delete'))
]) ])
return render(request, "wagtailvideos/images/edit.html", { return render(request, "wagtailvideos/videos/edit.html", {
'image': image, 'video': video,
'form': form, 'form': form,
'url_generator_enabled': url_generator_enabled, '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