Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
media = media.filter(collection=current_collection)
except (ValueError, Collection.DoesNotExist):
pass
# Search
query_string = None
if 'q' in request.GET:
form = SearchForm(request.GET, placeholder=_("Search media files"))
if form.is_valid():
query_string = form.cleaned_data['q']
media = media.search(query_string)
else:
form = SearchForm(placeholder=_("Search media"))
# Pagination
paginator, media = paginate(request, media)
collections = permission_policy.collections_user_has_any_permission_for(
request.user, ['add', 'change']
)
if len(collections) < 2:
collections = None
# Create response
if request.is_ajax():
return render(request, 'wagtailmedia/media/results.html', {
'ordering': ordering,
'media_files': media,
'query_string': query_string,
'is_searching': bool(query_string),
})
else:
def usage(request, media_id):
Media = get_media_model()
media = get_object_or_404(Media, id=media_id)
paginator, used_by = paginate(request, media.get_usage())
return render(request, "wagtailmedia/media/usage.html", {
'media': media,
'used_by': used_by
})
return render(request, "wagtailmedia/chooser/results.html", {
'media_files': media_files,
'query_string': q,
'is_searching': is_searching,
'pagination_template': pagination_template,
})
else:
searchform = SearchForm()
collections = Collection.objects.all()
if len(collections) < 2:
collections = None
media_files = Media.objects.order_by('-created_at')
paginator, media_files = paginate(request, media_files, per_page=10)
return render_modal_workflow(request, 'wagtailmedia/chooser/chooser.html', None, {
'media_files': media_files,
'searchform': searchform,
'collections': collections,
'is_searching': False,
'pagination_template': pagination_template,
}, json_data={
'step': 'chooser',
'error_label': "Server Error",
'error_message': "Report this error to your webmaster with the following information:",
'tag_autocomplete_url': reverse('wagtailadmin_tag_autocomplete'),
})
collection_id = request.GET.get('collection_id')
if collection_id:
media_files = media_files.filter(collection=collection_id)
searchform = SearchForm(request.GET)
if searchform.is_valid():
q = searchform.cleaned_data['q']
media_files = media_files.search(q)
is_searching = True
else:
media_files = media_files.order_by('-created_at')
is_searching = False
# Pagination
paginator, media_files = paginate(request, media_files, per_page=10)
return render(request, "wagtailmedia/chooser/results.html", {
'media_files': media_files,
'query_string': q,
'is_searching': is_searching,
'pagination_template': pagination_template,
})
else:
searchform = SearchForm()
collections = Collection.objects.all()
if len(collections) < 2:
collections = None
media_files = Media.objects.order_by('-created_at')
paginator, media_files = paginate(request, media_files, per_page=10)