Exemplo n.º 1
0
def display_profile_image(entity: Entity) -> str:
    if not entity.image_id:
        return ''
    path = get_file_path(entity.image_id)
    if not path:
        return ''  # pragma: no cover
    resized = None
    size = app.config['IMAGE_SIZE']['thumbnail']
    if g.settings['image_processing'] and check_processed_image(path.name):
        if path_ := get_file_path(entity.image_id, size):
            resized = url_for('display_file', filename=path_.name, size=size)
Exemplo n.º 2
0
 def get(filename: str) -> Response:  # pragma: no cover
     entity = Entity.get_by_id(int(Pathlib_path(filename).stem), types=True)
     license_ = get_license(entity)
     if not license_:
         raise AccessDeniedError
     parser = image.parse_args()
     if parser['download']:
         return send_file(
             f"{app.config['UPLOAD_DIR']}/{filename}",
             as_attachment=True)
     if parser['image_size'] and check_processed_image(filename):
         size = app.config['IMAGE_SIZE'][parser['image_size']]
         return send_from_directory(
             f"{app.config['RESIZED_IMAGES']}/{size}",
             filename)
     return send_from_directory(app.config['UPLOAD_DIR'], filename)
Exemplo n.º 3
0
    else:
        classes = 'place' if view == 'place' else g.view_class_mapping[view]
        entities = Entity.get_by_class(classes, types=True, aliases=True)
        table.rows = [get_base_table_data(entity) for entity in entities]
    return table


def file_preview(entity_id: int) -> str:
    size = app.config['IMAGE_SIZE']['table']
    parameter = f"loading='lazy' alt='image' width='{size}'"
    if icon_path := get_file_path(entity_id,
                                  app.config['IMAGE_SIZE']['table']):
        url = url_for('display_file', filename=icon_path.name, size=size)
        return f"<img src='{url}' {parameter}>"
    path = get_file_path(entity_id)
    if path and check_processed_image(path.name):
        if icon := get_file_path(entity_id, app.config['IMAGE_SIZE']['table']):
            url = url_for('display_file', filename=icon.name, size=size)
            return f"<img src='{url}' {parameter}>"
    return ''


def delete_entity(id_: int) -> Optional[str]:
    url = None
    entity = Entity.get_by_id(id_)
    if not is_authorized(entity.class_.write_access):
        abort(403)  # pragma: no cover
    if isinstance(entity, ReferenceSystem):
        if entity.system:
            abort(403)
        if entity.classes: