Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def edit(request, video_id, callback=None):
VideoForm = get_video_edit_form(Video)
video = get_object_or_404(Video, id=video_id)
if not request.is_ajax():
return HttpResponseBadRequest("Cannot POST to this view without AJAX")
form = VideoForm(
request.POST, request.FILES, instance=video, prefix='video-' + video_id
)
if form.is_valid():
form.save()
# Reindex the image to make sure all tags are indexed
for backend in get_search_backends():
backend.add(video)
return JsonResponse({
from __future__ import absolute_import, print_function, unicode_literals
from wagtail.wagtailcore.permission_policies.collections import \
CollectionOwnershipPermissionPolicy
from wagtailvideos.models import Video
permission_policy = CollectionOwnershipPermissionPolicy(
Video,
auth_model=Video,
owner_field_name='uploaded_by_user'
)
def video(video, **attrs):
if isinstance(video, Video):
defaults = {'preload': True, 'controls': True}
defaults.update(attrs)
return video.video_tag(attrs)
else:
raise TypeError('Expected type {0}, received {1}.'.format(Video, type(video)))
def chooser_upload(request):
VideoForm = get_video_form(Video)
searchform = SearchForm()
if request.POST:
video = Video(uploaded_by_user=request.user)
form = VideoForm(request.POST, request.FILES, instance=video)
if form.is_valid():
video.uploaded_by_user = request.user
video.save()
# Reindex the video to make sure all tags are indexed
search_index.insert_or_update_object(video)
return render_modal_workflow(
request, None, json_data={
'step': 'video_chosen',
'result': get_video_json(video)
}
)
else:
def create_transcode(request, video_id):
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
video = get_object_or_404(Video, id=video_id)
transcode_form = VideoTranscodeAdminForm(data=request.POST, video=video)
if transcode_form.is_valid():
transcode_form.save()
return redirect('wagtailvideos:edit', video_id)
class VideoTranscodeAdminForm(forms.Form):
media_format = EnumField(MediaFormats)
quality = EnumField(VideoQuality)
def __init__(self, video, data=None, **kwargs):
super(VideoTranscodeAdminForm, self).__init__(data=data, **kwargs)
self.video = video
def save(self):
media_format = self.cleaned_data['media_format']
quality = self.cleaned_data['quality']
self.video.do_transcode(media_format, quality)
GroupVideoPermissionFormSet = collection_member_permission_formset_factory(
Video,
[
('add_video', _("Add"), _("Add/edit images you own")),
('change_video', _("Edit"), _("Edit any video")),
],
'wagtailvideos/permissions/includes/video_permissions_formset.html'
)
from __future__ import absolute_import, print_function, unicode_literals
from wagtail.wagtailcore.permission_policies.collections import \
CollectionOwnershipPermissionPolicy
from wagtailvideos.models import Video
permission_policy = CollectionOwnershipPermissionPolicy(
Video,
auth_model=Video,
owner_field_name='uploaded_by_user'
)
def __init__(self, **kwargs):
super(AdminVideoChooser, self).__init__(**kwargs)
self.video_model = Video