__init__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. Initialize the modules needed for the website
  3. """
  4. import os
  5. from flask import Flask
  6. from flask_sqlalchemy import SQLAlchemy
  7. from flask_migrate import Migrate
  8. from flask_login import LoginManager
  9. from flask_compress import Compress
  10. from flask_argon2 import Argon2
  11. from flask_menu import Menu
  12. from sqlalchemy import MetaData
  13. from dotenv import load_dotenv
  14. load_dotenv()
  15. class Config(object):
  16. """Flask configuration"""
  17. UPLOAD_FOLDER = 'app/static/uploads'
  18. SCHEDULER_API_ENABLED = True
  19. SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URI"]
  20. SECRET_KEY = os.environ["SECRET_KEY"]
  21. SQLALCHEMY_TRACK_MODIFICATIONS = False
  22. SEND_FILE_MAX_AGE_DEFAULT = 1296000
  23. app = Flask(__name__)
  24. app.config.from_object(Config())
  25. app.jinja_env.lstrip_blocks = True
  26. app.jinja_env.trim_blocks = True
  27. app.config['TESTING'] = False
  28. # Compress settings
  29. COMPRESS_MIMETYPES = [
  30. 'text/html',
  31. 'text/css',
  32. 'text/xml',
  33. 'application/json',
  34. 'application/javascript'
  35. ]
  36. COMPRESS_LEVEL = 6
  37. COMPRESS_MIN_SIZE = 500
  38. Compress(app)
  39. Menu(app=app)
  40. convention = {
  41. "ix": 'ix_%(column_0_label)s',
  42. "uq": "uq_%(table_name)s_%(column_0_name)s",
  43. "ck": "ck_%(table_name)s_%(constraint_name)s",
  44. "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
  45. "pk": "pk_%(table_name)s"
  46. }
  47. metadata = MetaData(naming_convention=convention)
  48. db = SQLAlchemy(app, metadata=metadata)
  49. migrate = Migrate(app, db)
  50. argon2 = Argon2(app)
  51. # Login
  52. login_manager = LoginManager()
  53. login_manager.init_app(app)
  54. login_manager.login_view = "auth.login"
  55. login_manager.login_message_category = "warning"