<commit_before>import PIL

from django.db import models
from django.db.models.fields.files import ImageFieldFile
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

from slugify import UniqueSlugify

from . import utils
from . import settings

# the size of image
IMG_W = settings.GALLERY_IMAGE_WIDTH
IMG_H = settings.GALLERY_IMAGE_HEIGHT

# the size of small image
SMALL_W = settings.GALLERY_SMALL_IMAGE_WIDTH
SMALL_H = settings.GALLERY_SMALL_IMAGE_HEIGHT

# the size of small image (thumbnail)
THUMB_W = settings.GALLERY_THUMBNAIL_WIDTH
THUMB_H = settings.GALLERY_THUMBNAIL_HEIGHT

# the size of preview
PREVIEW_W = settings.GALLERY_PREVIEW_WIDTH
PREVIEW_H = settings.GALLERY_PREVIEW_HEIGHT

# the size of small preview
SMALL_PREVIEW_W = settings.GALLERY_SMALL_PREVIEW_WIDTH
SMALL_PREVIEW_H = settings.GALLERY_SMALL_PREVIEW_HEIGHT

def _unique_slug_check(slug, uids):
    slug = utils.name_in_db(slug)
    return not Image.objects.filter(image__startswith=slug)

slugify_unique = UniqueSlugify(unique_check=_unique_slug_check, to_lower=True)


class ImageQuerySet(models.QuerySet):

    def delete(self):
        for obj in self:
            obj.delete_files()
        return super().delete()


class ImageManager(models.Manager):

    def get_queryset(self):
        return ImageQuerySet(self.model, using=self._db)


class GalleryImageFieldFile(ImageFieldFile):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.thumbnail = utils.ImageFile(self, THUMB_W, THUMB_H,
            'thumbnail')
        self.image_data = utils.InMemoryImageData(self, IMG_W, IMG_H)
        self.small_image = utils.ImageFile(self, SMALL_W, SMALL_H,
            'small')
        self.preview = utils.ImageFile(self, PREVIEW_W, PREVIEW_H,
            'preview')
        self.small_preview = utils.ImageFile(self, SMALL_PREVIEW_W,
            SMALL_PREVIEW_H, 'small_preview')

    def save_files(self, slug, name):
        self.image_data.save(self, slug, name)
        self.thumbnail.save(self, slug, name)
        self.small_image.save(self, slug, name)
        self.preview.save(self, slug, name)
        self.small_preview.save(self, slug, name)
        if not self.data:
            self.name = self.image_data.name_in_db

    def save(self, name, content, save=True):
        content = self.data
        name = self.data.name
        super().save(name, content, save)

    @property
    def data(self):
        return self.image_data.data

    def delete_files(self):
        self.thumbnail.delete()
        self.image_data.delete()
        self.small_image.delete()
        self.preview.delete()
        self.small_preview.delete()

    @property
    def thumbnail_url(self):
        return self.thumbnail.url

    @property
    def image_url(self):
        return self.image_data.url

    @property
    def small_image_url(self):<commit_msg>Deleted data property<commit_after>import PIL

from django.db import models
from django.db.models.fields.files import ImageFieldFile
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

from slugify import UniqueSlugify

from . import utils
from . import settings

# the size of image
IMG_W = settings.GALLERY_IMAGE_WIDTH
IMG_H = settings.GALLERY_IMAGE_HEIGHT

# the size of small image
SMALL_W = settings.GALLERY_SMALL_IMAGE_WIDTH
SMALL_H = settings.GALLERY_SMALL_IMAGE_HEIGHT

# the size of small image (thumbnail)
THUMB_W = settings.GALLERY_THUMBNAIL_WIDTH
THUMB_H = settings.GALLERY_THUMBNAIL_HEIGHT

# the size of preview
PREVIEW_W = settings.GALLERY_PREVIEW_WIDTH
PREVIEW_H = settings.GALLERY_PREVIEW_HEIGHT

# the size of small preview
SMALL_PREVIEW_W = settings.GALLERY_SMALL_PREVIEW_WIDTH
SMALL_PREVIEW_H = settings.GALLERY_SMALL_PREVIEW_HEIGHT

def _unique_slug_check(slug, uids):
    slug = utils.name_in_db(slug)
    return not Image.objects.filter(image__startswith=slug)

slugify_unique = UniqueSlugify(unique_check=_unique_slug_check, to_lower=True)


class ImageQuerySet(models.QuerySet):

    def delete(self):
        for obj in self:
            obj.delete_files()
        return super().delete()


class ImageManager(models.Manager):

    def get_queryset(self):
        return ImageQuerySet(self.model, using=self._db)


class GalleryImageFieldFile(ImageFieldFile):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.thumbnail = utils.ImageFile(self, THUMB_W, THUMB_H,
            'thumbnail')
        self.image_data = utils.InMemoryImageData(self, IMG_W, IMG_H)
        self.small_image = utils.ImageFile(self, SMALL_W, SMALL_H,
            'small')
        self.preview = utils.ImageFile(self, PREVIEW_W, PREVIEW_H,
            'preview')
        self.small_preview = utils.ImageFile(self, SMALL_PREVIEW_W,
            SMALL_PREVIEW_H, 'small_preview')

    def save_files(self, slug, name):
        self.image_data.save(self, slug, name)
        self.thumbnail.save(self, slug, name)
        self.small_image.save(self, slug, name)
        self.preview.save(self, slug, name)
        self.small_preview.save(self, slug, name)
        if not self.image_data.data:
            self.name = self.image_data.name_in_db

    def save(self, name, content, save=True):
        content = self.image_data.data
        name = self.image_data.data.name
        super().save(name, content, save)

    def delete_files(self):
        self.thumbnail.delete()
        self.image_data.delete()
        self.small_image.delete()
        self.preview.delete()
        self.small_preview.delete()

    @property
    def thumbnail_url(self):
        return self.thumbnail.url

    @property
    def image_url(self):
        return self.image_data.url

    @property
    def small_image_url(self):
{'fraction_non_alphanumeric': 0.08915785884759632, 'fraction_numerical': 0.0, 'mean_word_length': 3.458206686930091, 'pattern_counts': {'":': 0, '<': 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': '1611729', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1930, 'n_words': 384}