def image_pre_save(sender, instance, **kwargs): basetitle = instance.original_filename try: p = Photo.objects.get(title=basetitle) except Photo.DoesNotExist: p = Photo(title=basetitle) p.image = instance.file.file p.save() fld = instance.folder if fld is not None and fgs.AUTOCREATE and is_gallery_folder(fld.pretty_logical_path)[0]: try: gal = get_cached_object(Gallery, slug=slug_from_folder(fld)) if GalleryItem.objects.filter(gallery=gal, photo=p).count() == 0: GalleryItem.objects.create( gallery=gal, photo=p, order=fld.file_count ) except Gallery.DoesNotExist: pass
def generate_photo(self, instance, time): # TODO: handle fails dir_name = Photo._meta.get_field_by_name('image')[0].get_directory_name() file_name = path.join(dir_name, 'screenshot-' + instance.file.token) try: makedirs(path.join(settings.MEDIA_ROOT, dir_name)) except OSError: # Directory already exists pass instance.file.create_thumb(path.join(settings.MEDIA_ROOT, file_name), time=time) photo = Photo() photo.title = "%s screenshot" % instance.title photo.slug = slugify(photo.title) photo.image = file_name size = get_img_size(path.join(settings.MEDIA_ROOT, file_name)) photo.width = size['width'] photo.height = size['height'] photo.save() instance.photo = photo
def generate_photo(self, instance, time): # TODO: handle fails dir_name = Photo._meta.get_field_by_name( 'image')[0].get_directory_name() file_name = path.join(dir_name, 'screenshot-' + instance.file.token) try: makedirs(path.join(settings.MEDIA_ROOT, dir_name)) except OSError: # Directory already exists pass instance.file.create_thumb(path.join(settings.MEDIA_ROOT, file_name), time=time) photo = Photo() photo.title = "%s screenshot" % instance.title photo.slug = slugify(photo.title) photo.image = file_name size = get_img_size(path.join(settings.MEDIA_ROOT, file_name)) photo.width = size['width'] photo.height = size['height'] photo.save() instance.photo = photo