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):
VideoForm = get_video_form(Video)
video = get_object_or_404(Video, id=video_id)
if request.POST:
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 video 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)
# Set new video file size
video.file_size = video.file.size
video = form.save()
def get_video_edit_form(VideoModel):
VideoForm = get_video_form(VideoModel)
# Make a new form with the file and focal point fields excluded
class VideoEditForm(VideoForm):
class Meta(VideoForm.Meta):
model = VideoModel
exclude = (
'file',
)
return VideoEditForm
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={
def add(request):
VideoForm = get_video_form(Video)
if request.POST:
video = Video(uploaded_by_user=request.user)
form = VideoForm(request.POST, request.FILES, instance=video, user=request.user)
if form.is_valid():
# Save
video = form.save(commit=False)
video.file_size = video.file.size
video.save()
# Success! Send back an edit form
for backend in get_search_backends():
backend.add(video)
messages.success(request, _("Video '{0}' added.").format(video.title), buttons=[
messages.button(reverse('wagtailvideos:edit', args=(video.id,)), _('Edit'))
def add(request):
VideoForm = get_video_form(Video)
collections = permission_policy.collections_user_has_permission_for(request.user, 'add')
if len(collections) > 1:
collections_to_choose = collections
else:
# no need to show a collections chooser
collections_to_choose = None
if request.method == 'POST':
if not request.is_ajax():
return HttpResponseBadRequest("Cannot POST to this view without AJAX")
if not request.FILES:
return HttpResponseBadRequest("Must upload a file")
# Build a form for validation
def chooser(request):
VideoForm = get_video_form(Video)
uploadform = VideoForm()
videos = Video.objects.order_by('-created_at')
q = None
if (
'q' in request.GET or 'p' in request.GET or 'tag' in request.GET
or 'collection_id' in request.GET
):
# this request is triggered from search, pagination or 'popular tags';
# we will just render the results.html fragment
collection_id = request.GET.get('collection_id')
if collection_id:
videos = videos.filter(collection=collection_id)
searchform = SearchForm(request.GET)