<commit_before># -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator, MaxValueValidator

from opps.core.models.published import Published

from sorl.thumbnail import ImageField, get_thumbnail



CROP_TYPE = (("center", u"center"),)

class ImageCrop(models.Model):

    type = models.CharField(_(u"Type"), max_length=15, choices=CROP_TYPE)
    width = models.IntegerField()
    height = models.IntegerField()
    quality = models.IntegerField(validators=[MinValueValidator(20),
        MaxValueValidator(100)])

    def __unicode__(self):
        return "{0} x {1} ({2})".format(self.width, self.height, self.type)


class Image(Publisher):

    image = ImageField(upload_to="opps_images/")
    description = models.CharField(_(u"Description"), max_length=255,
            null=True, blank=True)
    crop = models.ManyToManyField(ImageCrop, null=True, blank=True)

    def save(self, *args, **kwargs):
        if self.crop:
            import pdb; pdb.set_trace()
            for x in self.crop.all():
                get_thumbnail(self.image,
                        "{0}x{1}".format(x.width, x.height),
                        crop=x.type, quality=x.quality)

        super(Image, self).save(*args, **kwargs)<commit_msg>Add core models date abstract on Image app<commit_after># -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator, MaxValueValidator

from opps.core.models.published import Published
from opps.core.models.date import Date

from sorl.thumbnail import ImageField, get_thumbnail



CROP_TYPE = (("center", u"center"),)

class ImageCrop(models.Model):

    type = models.CharField(_(u"Type"), max_length=15, choices=CROP_TYPE)
    width = models.IntegerField()
    height = models.IntegerField()
    quality = models.IntegerField(validators=[MinValueValidator(20),
        MaxValueValidator(100)])

    def __unicode__(self):
        return "{0} x {1} ({2})".format(self.width, self.height, self.type)


class Image(Published, Date):

    image = ImageField(upload_to="opps_images/")
    description = models.CharField(_(u"Description"), max_length=255,
            null=True, blank=True)
    crop = models.ManyToManyField(ImageCrop, null=True, blank=True)

    def save(self, *args, **kwargs):
        if self.crop:
            import pdb; pdb.set_trace()
            for x in self.crop.all():
                get_thumbnail(self.image,
                        "{0}x{1}".format(x.width, x.height),
                        crop=x.type, quality=x.quality)

        super(Image, self).save(*args, **kwargs)
{'fraction_non_alphanumeric': 0.12884333821376281, 'fraction_numerical': 0.01171303074670571, 'mean_word_length': 3.2570093457943927, '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': '1267018', 'n_tokens_mistral': 865, 'n_tokens_neox': 830, 'n_words': 181}