routes.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from flask import jsonify, request, current_app, send_file, abort
  2. from . import bp
  3. import os
  4. #
  5. # Default Logo
  6. #
  7. default_logo = {
  8. "default": "POLZY_POLZY LIGHT.png", # login screens
  9. "top": "POLZY_POLZY LIGHT.png", # top bar
  10. "policy": "POLZY_LeZySEM LIGHT.png", # new policy card
  11. "antrag": "POLZY_LeZyTOR LIGHT.png", # new antrag card
  12. }
  13. @bp.route('/logo/<string:filename>')
  14. @bp.route('/logo/default/<string:target>')
  15. def logo(filename=None, target=None):
  16. #
  17. # returns img from media/logo
  18. #
  19. current_app.logger.info(f"In Logo-Endpoint for filename: {filename}, target: {target}")
  20. if filename:
  21. path_to_file = os.path.join(current_app.config['LOGO'], filename)
  22. elif target:
  23. path_to_file = os.path.join(current_app.config['LOGO'], str(default_logo.get(target)))
  24. else:
  25. return abort(403)
  26. current_app.logger.info(f"Returning logo from this path: {path_to_file}")
  27. return send_file(
  28. path_to_file,
  29. attachment_filename=filename,
  30. )
  31. @bp.route('/badge/<string:type>')
  32. @bp.route('/badge/<string:type>/<string:level>')
  33. def badge_image(type, level=None):
  34. #
  35. # returns img from media/badges
  36. #
  37. if level:
  38. filename = f'{type}_{level}.png'
  39. else:
  40. filename = f'{type}.png'
  41. path_to_file = os.path.join(current_app.config['BADGES'], filename)
  42. # check if file not exists
  43. if not os.path.isfile(path_to_file):
  44. path_to_file = os.path.join(current_app.config['BADGES'], f'default_{level}.png')
  45. return send_file(
  46. path_to_file,
  47. attachment_filename=filename,
  48. )
  49. @bp.route('/files/<string:filename>')
  50. def downloads(filename):
  51. path_to_file = os.path.join(current_app.config['PDF'], filename)
  52. return send_file(
  53. path_to_file,
  54. attachment_filename=filename,
  55. )
  56. @bp.route('/images/<string:filename>')
  57. def images(filename):
  58. path_to_file = os.path.join(current_app.config['IMAGES'], filename)
  59. return send_file(
  60. path_to_file,
  61. attachment_filename=filename,
  62. )