Beispiel #1
0
    def save(self, *args, **kwargs):
        if self.image and not GALLERY_ORIGINAL_IMAGESIZE == 0:
            width, height = GALLERY_ORIGINAL_IMAGESIZE.split('x')
            super(Image, self).save(*args, **kwargs)

            filename = os.path.join( settings.MEDIA_ROOT, self.image.name )
            image = PILImage.open(filename)

            image.thumbnail((int(width), int(height)), PILImage.ANTIALIAS)
            image.save(filename)

        if not self.slug:
            self.slug = slugify(self.name)

        super(Image, self).save(*args, **kwargs)
def get_upload_path(instance, filename):
    parts = filename.split('.')
    ext = parts[-1]
    parts.pop()
    basename = '.'.join(parts)

    today = datetime.now()
    
    if GALLERY_ENCRYPT_FILENAMES:
        time_string = today.strftime("%H-%M-%S")
        hash = hashlib.sha224( "%s-%s" % (filename, time_string) ).hexdigest()
        path = os.path.join(GALLERY_DIR, "%s/%s/%s.%s" % (hash[:2], hash[2:4], hash, ext.lower()) )
    else:
        date_path = today.strftime("%Y/%m")
        
        path = os.path.join(GALLERY_DIR, date_path, "%s.%s" % (slugify(basename), ext.lower()))
        
    return path
Beispiel #3
0
    def save(self, *args, **kwargs):
        slug = self.slug
        if slug == '':
            self.slug = slug = slugify(self.title)

        i = 0
        while True:
            try:
                savepoint = transaction.savepoint()
                res = super(Post, self).save(*args, **kwargs)
                transaction.savepoint_commit(savepoint)
                return res
            except IntegrityError:
                transaction.savepoint_rollback(savepoint)
                i += 1
                self.slug = '%s-%d' % (slug, i)
        # Call the "real" save() method.
        super(Post, self).save(*args, **kwargs)
Beispiel #4
0
    def save(self, *args, **kwargs):
        if self.slug == '':
            self.slug = slugify(self.title)

        super(Page, self).save(*args, **kwargs) # Call the "real" save() method.