def delelte_file_hook(mapper, connection, target): if target.path: media_root = current_app.config['MEDIA_ROOT'] # Remover a imagem try: os.remove(os.path.join(media_root, target.path)) except OSError: pass # Se der erro não importa, o arquivo já não existe # Remover o thumbnail try: thumb_path = thumbgen_filename(target.path) os.remove(os.path.join(media_root, thumb_path)) except OSError: pass # Se der erro não importa, o arquivo já não existe
def delelte_image_hook(mapper, connection, target): if target.path: media_root = current_app.config['MEDIA_ROOT'] # Remover a imagem try: os.remove(os.path.join(media_root, target.path)) except OSError: pass # Se der erro não importa, o arquivo já não existe # Remover o thumbnail try: thumb_path = thumbgen_filename(target.path) os.remove(os.path.join(media_root, thumb_path)) except OSError: pass # Se der erro não importa, o arquivo já não existe
def get_thumbnail_absolute_url(self): media_url = current_app.config['MEDIA_URL'] thumb_path = thumbgen_filename(self.path) return '%s/%s' % (media_url, thumb_path)