<commit_before>import json

from django.http import HttpResponse, Http404
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import get_object_or_404
from django.core.exceptions import PermissionDenied

from . import settings
from . import models
from . import utils

def choices(request, pk):
    if not request.is_ajax():
        raise PermissionDenied
    response = []
    ctype = get_object_or_404(ContentType, pk=pk)
    model_class = ctype.model_class()
    try:
        if model_class.gallery_visible:
            qs = model_class.objects.all()
            for product in qs:
                response.append({"id": str(product.id), "name": str(product)})
        else:
            raise PermissionDenied
    except AttributeError:
        raise Http404
    return HttpResponse(json.dumps(response), content_type='application/json')


def gallery_data(request, app_label, content_type, object_id):
    image_size = {
        "width": settings.GALLERY_IMAGE_WIDTH,
        "height": settings.GALLERY_IMAGE_HEIGHT
    }
    small_image_size = {
        "width": settings.GALLERY_SMALL_IMAGE_WIDTH,
        "height": settings.GALLERY_SMALL_IMAGE_HEIGHT
    }
    thumbnail_size = {
        "width": settings.GALLERY_THUMBNAIL_WIDTH,
        "height": settings.GALLERY_THUMBNAIL_HEIGHT
    }

    ctype = ContentType.objects.get(app_label=app_label, model=content_type)<commit_msg>Added code that passes the test<commit_after>import json

from django.http import HttpResponse, Http404
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import get_object_or_404
from django.core.exceptions import PermissionDenied

from . import settings
from . import models
from . import utils

def choices(request, pk):
    if not request.is_ajax():
        raise PermissionDenied
    response = []
    ctype = get_object_or_404(ContentType, pk=pk)
    model_class = ctype.model_class()
    try:
        if model_class.gallery_visible:
            qs = model_class.objects.all()
            for product in qs:
                response.append({"id": str(product.id), "name": str(product)})
        else:
            raise PermissionDenied
    except AttributeError:
        raise Http404
    return HttpResponse(json.dumps(response), content_type='application/json')


def gallery_data(request, app_label, content_type, object_id):
    if not request.is_ajax():
        raise PermissionDenied
    image_size = {
        "width": settings.GALLERY_IMAGE_WIDTH,
        "height": settings.GALLERY_IMAGE_HEIGHT
    }
    small_image_size = {
        "width": settings.GALLERY_SMALL_IMAGE_WIDTH,
        "height": settings.GALLERY_SMALL_IMAGE_HEIGHT
    }
    thumbnail_size = {
        "width": settings.GALLERY_THUMBNAIL_WIDTH,
        "height": settings.GALLERY_THUMBNAIL_HEIGHT
    }

    ctype = ContentType.objects.get(app_label=app_label, model=content_type)
{'fraction_non_alphanumeric': 0.08531131750945993, 'fraction_numerical': 0.008255933952528379, 'mean_word_length': 3.301775147928994, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '151932', 'n_tokens_mistral': 909, 'n_tokens_neox': 868, 'n_words': 185}