Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

metadata edits #251

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions richard/videos/templates/videos/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
{% block title %}{% page_title v.title %}{% endblock %}

{% block content %}

{% if v_form %}
<form method="POST">
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
{{v_form.errors|safe}}
{% endif %}

{% if not v.is_live %}
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <strong>Note:</strong>
Expand All @@ -35,6 +42,11 @@
<div id="videobox" class="col-md-12">
<div class="section">
<h3 class="centered">{{ v.title }}</h3>

{% if v_form %}
{{ v_form.title|safe }}
<input type="submit" value="Save">
{% endif %}
</div>

{# Fix floats in unisubs widget that are not cleared #}
Expand Down Expand Up @@ -62,6 +74,12 @@ <h3 class="centered">{{ v.title }}</h3>
<p>No video to show.</p>
{% endif %}
{% endif %}
{# carl's hacky veyepar title preview #}
{% if not v.is_live %}
<img src="{{ v.thumbnail_url }}" width=600 ><br/>
(note: ths image will not automatically update, video producer has to bump it.)
{% endif %}

</div>
</div>
</div>
Expand All @@ -79,6 +97,7 @@ <h3 class="centered">{{ v.title }}</h3>
<div class="section">
<h4>Summary</h4>
{{ v.summary|md|safe }}
{{ v_form.summary|safe }}
</div>
{% endif %}

Expand All @@ -93,6 +112,13 @@ <h4>Related URLs</h4>
</div>
{% endif %}

<ul>
{{ u_formset.management_form }}
{% for f in u_formset %}
<li>{{ f|safe }}</li>
{% endfor %}
</ul>

{% if v.description %}
<div class="section">
<h4>Description</h4>
Expand Down Expand Up @@ -120,6 +146,9 @@ <h4>Description</h4>
{% empty %}
Unknown
{% endfor %}
{% if s_formset %}
{{ s_formset|safe }}
{% endif %}
</dd>

{% if v.language %}
Expand Down Expand Up @@ -193,6 +222,10 @@ <h4>Description</h4>
</div>
</div>
</div>
{% if v_form %}
<input type="submit" value="Save">
</form>
{% endif %}
{% endblock %}

{% block site_js %}
Expand Down
58 changes: 56 additions & 2 deletions richard/videos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from django.contrib.sites.models import Site
from django.core.paginator import EmptyPage, Paginator
from django.http import Http404, HttpResponse
from django.forms.models import modelform_factory, modelformset_factory, inlineformset_factory
from django.shortcuts import get_object_or_404, render
from django.template import RequestContext

from haystack.query import SearchQuerySet
from rest_framework import generics
Expand Down Expand Up @@ -174,15 +176,67 @@ def video(request, video_id, slug):

use_amara = settings.AMARA_SUPPORT

# crazy edit
if "editkey" in request.GET:
edit_key = request.GET['editkey']
if edit_key=='1':

Video_Form = modelform_factory(
models.Video, fields=("title","summary"))

Speaker_FormSet = modelformset_factory(
models.Speaker,
extra=0,
fields=('name',) )

Url_FormSet = inlineformset_factory(
models.Video, models.RelatedUrl,
extra=1,
fields=('url','description',) )

if request.method == 'POST':

video_form = Video_Form(request.POST, instance=obj)
speaker_formset = Speaker_FormSet( request.POST,
queryset=obj.speakers.all())
url_formset = Url_FormSet( request.POST, instance=obj,
queryset=obj.related_urls.all())

if video_form.is_valid() and \
speaker_formset.is_valid() and \
url_formset.is_valid():
video_form.save()
speaker_formset.save()
url_formset.save()

else:
video_form = Video_Form(instance=obj)
speaker_formset = Speaker_FormSet(
queryset=obj.speakers.all())
url_formset = Url_FormSet(
instance=obj,
queryset=obj.related_urls.all())
else:
video_form = None
speaker_formset = None
url_formset = None


ret = render(request, 'videos/video.html', {
'meta': meta,
'v': obj,
'v_form': video_form,
's_formset': speaker_formset,
'u_formset': url_formset,
'use_amara': use_amara,
'video_url': video_url,
'embed': embed,
'embed_type': embed_type,
'html5_formats': html5_formats
})
'html5_formats': html5_formats,
},
context_instance=RequestContext(request)
)

return ret


Expand Down