Closed mbdaso closed 5 years ago
Aparece en el comentario Image y BadgeImage ¿es un error? ¿no deberian ser ambos BadgeImage?
Donde?
En open_image en el comentario al menos. NO he visto el código
def open_image(self, badge: Badge) -> BufferedIOBase:
'''
Método para acceder a la imagen de una medalla
'''
if isinstance(badge.image, str):
if Path(badge.image).exists:
badge.image = Image(path=badge.image)
else:
raise ValueError(f'BadgeService.open_image: path {badge.image} doesn\'t exist')
if isinstance(badge.image, BadgeImage):
return badge.image.get_data()
raise TypeError(f'BadgeService.open_image: Can\'t open image of type {type(badge.image)}')
Si, es que cambié el nombre de la clase y se me olvidó cambiarlo ahí también
He creado una clase BadgeImage en que guarda la ruta, los datos y el tipo (.png, .svg) de la imagen. Tiene un método get_data() que carga la imagen si está en un archivo.
Cuando se guarda una medalla se sustituye el BadgeImage.image por un string que indica la ruta del archivo. Quité lo de file:///... porque una medalla siempre va a tener una ruta de archivo local:
La función load queda igual que antes.
BadgeService.open_image sustituye el atributo image por un BadgeImage si detecta que es un string, y luego llama a BadgeImage.get_data que devuelve un BufferedBaseIO
Intenté hacerlo con
@property
, haciendo un setter que al pasarle un string o un BytesIO creara la imagen, pero daba problemas por todos lados.