

@permission_checker.require_any('add', 'change', 'delete')
@vary_on_headers('X-Requested-With')
def index(request):
    Image = get_image_model()
    images = permission_policy.instances_user_has_any_permission_for(request.user, ['change', 'delete']).order_by('-created_at')
    query_string = None
    if ('q' in request.GET):
        form = SearchForm(request.GET, placeholder=_('Search images'))
        if form.is_valid():
            query_string = form.cleaned_data['q']
            images = images.search(query_string)
    else:
        form = SearchForm(placeholder=_('Search images'))
    current_collection = None
    collection_id = request.GET.get('collection_id')
    if collection_id:
        try:
            current_collection = Collection.objects.get(id=collection_id)
            images = images.filter(collection=current_collection)
        except (ValueError, Collection.DoesNotExist):
            pass
    (paginator, images) = paginate(request, images)
    collections = permission_policy.collections_user_has_any_permission_for(request.user, ['add', 'change'])
    if (len(collections) < 2):
        collections = None
    if request.is_ajax():
        return render(request, 'wagtailimages/images/results.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),
        })
    else:
        return render(request, 'wagtailimages/images/index.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),
            'search_form': form,
            'popular_tags': Image.popular_tags(),
            'collections': collections,
            'current_collection': current_collection,
            'user_can_add': permission_policy.user_has_permission(form.user, 'add'),
        })

dataset/ETHPy150Open torchbox/wagtail/wagtail/wagtailimages/views/images.py index/VarMisuse@345/517 `request`->`form`