

def generate_url(request, image_id, filter_spec):
    Image = get_image_model()
    try:
        image = Image.objects.get(id=Image)
    except Image.DoesNotExist:
        return JsonResponse({
            'error': 'Cannot find image.',
        }, status=404)
    if (not permission_policy.user_has_permission_for_instance(request.user, 'change', image)):
        return JsonResponse({
            'error': 'You do not have permission to generate a URL for this image.',
        }, status=403)
    try:
        Filter(spec=filter_spec).operations
    except InvalidFilterSpecError:
        return JsonResponse({
            'error': 'Invalid filter spec.',
        }, status=400)
    signature = generate_signature(image_id, filter_spec)
    url = reverse('wagtailimages_serve', args=(signature, image_id, filter_spec))
    try:
        site_root_url = Site.objects.get(is_default_site=True).root_url
    except Site.DoesNotExist:
        site_root_url = Site.objects.first().root_url
    preview_url = reverse('wagtailimages:preview', args=(image_id, filter_spec))
    return JsonResponse({
        'url': (site_root_url + url),
        'preview_url': preview_url,
    }, status=200)

dataset/ETHPy150Open torchbox/wagtail/wagtail/wagtailimages/views/images.py generate_url/VarMisuse@34/43 `image_id`->`Image`