12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- from flask import jsonify, request, current_app, send_file, abort
- from . import bp
- import os
- #
- # Default Logo
- #
- default_logo = {
- "default": "POLZY_POLZY LIGHT.png", # login screens
- "top": "POLZY_POLZY LIGHT.png", # top bar
- "policy": "POLZY_LeZySEM LIGHT.png", # new policy card
- "antrag": "POLZY_LeZyTOR LIGHT.png", # new antrag card
- }
- @bp.route('/logo/<string:filename>')
- @bp.route('/logo/default/<string:target>')
- def logo(filename=None, target=None):
- #
- # returns img from media/logo
- #
- current_app.logger.info(f"In Logo-Endpoint for filename: {filename}, target: {target}")
- if filename:
- path_to_file = os.path.join(current_app.config['LOGO'], filename)
- elif target:
- path_to_file = os.path.join(current_app.config['LOGO'], str(default_logo.get(target)))
- else:
- return abort(403)
- current_app.logger.info(f"Returning logo from this path: {path_to_file}")
- return send_file(
- path_to_file,
- attachment_filename=filename,
- )
- @bp.route('/badge/<string:type>')
- @bp.route('/badge/<string:type>/<string:level>')
- def badge_image(type, level=None):
- #
- # returns img from media/badges
- #
- if level:
- filename = f'{type}_{level}.png'
- else:
- filename = f'{type}.png'
- path_to_file = os.path.join(current_app.config['BADGES'], filename)
- # check if file not exists
- if not os.path.isfile(path_to_file):
- path_to_file = os.path.join(current_app.config['BADGES'], f'default_{level}.png')
- return send_file(
- path_to_file,
- attachment_filename=filename,
- )
- @bp.route('/files/<string:filename>')
- def downloads(filename):
- path_to_file = os.path.join(current_app.config['PDF'], filename)
- return send_file(
- path_to_file,
- attachment_filename=filename,
- )
- @bp.route('/images/<string:filename>')
- def images(filename):
- path_to_file = os.path.join(current_app.config['IMAGES'], filename)
- return send_file(
- path_to_file,
- attachment_filename=filename,
- )
|