Example #1
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):

        if self.image:
            photo = Photo.objects.filter(image=self.image)

            if len(photo) == 0:
                uploader = ImageUploader(self.image)
                image_handle = uploader.save(800, 600)
                thumb_handle = uploader.create_thumbnail(200, 200)

                image_field = SimpleUploadedFile(
                    self.image.name,
                    image_handle.read(),
                    content_type=self.image.file.content_type)
                thumb_field = SimpleUploadedFile(
                    self.image.name,
                    thumb_handle.read(),
                    content_type=self.image.file.content_type)

                self.image.save('%s.%s' %
                                (os.path.splitext(self.image.name)[0], 'jpg'),
                                image_field,
                                save=False)
                self.thumb.save('%s_thumbnail.%s' %
                                (os.path.splitext(self.image.name)[0], 'png'),
                                thumb_field,
                                save=False)
                self.width = self.image.width
                self.height = self.image.height
        super(Photo, self).save(force_insert, force_update, using,
                                update_fields)
Example #2
0
    def save(self, *args, **kwargs):
        if self.thumb:
            video = Video.objects.filter(thumb=self.thumb)

            if len(video) == 0:
                uploader = ImageUploader(self.thumb)
                image_handle = uploader.save(200, 200)

                image_field = SimpleUploadedFile(self.thumb.name, image_handle.read(),
                                                 content_type=self.thumb.file.content_type)

                self.thumb.save('%s.%s' % (os.path.splitext(self.thumb.name)[0], 'jpg'), image_field, save=False)

        self.file.name = Translit.translit(self.file.name)

        if self.youtube_status > YOUTUBE_STATUS_PENDING_UPLOAD:
            self.youtube_status = YOUTUBE_STATUS_PENDING_UPDATE

        super(Video, self).save(*args, **kwargs)
Example #3
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if hasattr(self.icon.file, 'content_type'):
            uploader = ImageUploader(self.icon, 'png')
            image_handle = uploader.save(300, 300)

            image_field = SimpleUploadedFile(
                self.icon.name,
                image_handle.read(),
                content_type=self.icon.file.content_type)
            self.icon.save('%s.%s' %
                           (os.path.splitext(self.icon.name)[0], 'png'),
                           image_field,
                           save=False)

        super(Home, self).save(force_insert, force_update, using,
                               update_fields)
Example #4
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.thumb:
            recipe = Recipe.objects.filter(thumb=self.thumb)

            if len(recipe) == 0:
                uploader = ImageUploader(self.thumb)
                image_handle = uploader.save(150, 150)

                image_field = SimpleUploadedFile(
                    self.thumb.name,
                    image_handle.read(),
                    content_type=self.thumb.file.content_type)

                self.thumb.save('%s.%s' %
                                (os.path.splitext(self.thumb.name)[0], 'jpg'),
                                image_field,
                                save=False)

        super(Recipe, self).save(force_insert, force_update, using,
                                 update_fields)
Example #5
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.icon:
            article = Article.objects.filter(icon=self.icon)

            if len(article) == 0:
                uploader = ImageUploader(self.icon)
                image_handle = uploader.save(300, 300)

                image_field = SimpleUploadedFile(
                    self.icon.name,
                    image_handle.read(),
                    content_type=self.icon.file.content_type)

                self.icon.save('%s.%s' %
                               (os.path.splitext(self.icon.name)[0], 'jpg'),
                               image_field,
                               save=False)

        super(Article, self).save(force_insert, force_update, using,
                                  update_fields)
Example #6
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.image:
            image = Price.objects.filter(image=self.image)

            if len(image) == 0:
                uploader = ImageUploader(self.image)
                image_handle = uploader.save(200, 200)

                image_field = SimpleUploadedFile(
                    self.image.name,
                    image_handle.read(),
                    content_type=self.image.file.content_type)

                self.image.save('%s.%s' %
                                (os.path.splitext(self.image.name)[0], 'jpg'),
                                image_field,
                                save=False)

        super(Price, self).save(force_insert, force_update, using,
                                update_fields)
Example #7
0
 def delete(self, *args, **kwargs):
     for photo in self:
         ImageUploader.clean_image(image_path=photo.thumb.__str__())
         ImageUploader.clean_image(image_path=photo.image.__str__())
     super(PhotoQuerySet, self).delete()
Example #8
0
 def delete(self, using=None, keep_parents=False):
     ImageUploader.clean_image(image_path=self.thumb.__str__())
     ImageUploader.clean_image(image_path=self.image.__str__())
     super(Photo, self).delete(using, keep_parents)