Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

__init__.py 3.0KB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # @name: __init__.py
  2. # @creation_date: 2021-10-20
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: Initialises the app, SQLAlchemy, and configuration variables
  6. # @acknowledgements:
  7. # https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login
  8. # Config stuff adapted from https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms
  9. from flask import Flask
  10. from flask_sqlalchemy import SQLAlchemy
  11. from flask_login import LoginManager
  12. from flask_moment import Moment
  13. import os
  14. # initiate SQLAlchemy so we can use it later in our models
  15. db = SQLAlchemy()
  16. # initiate Moment for datetime functions
  17. moment = Moment()
  18. def create_app():
  19. app = Flask(__name__)
  20. # get config variables from OS environment variables: set in env file passed through Docker Compose
  21. app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
  22. app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
  23. app.config['SQLALCHEMY_ECHO'] = False
  24. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  25. db.init_app(app)
  26. login_manager = LoginManager()
  27. login_manager.login_view = 'auth.login'
  28. login_manager.init_app(app)
  29. moment.init_app(app)
  30. from .models import User
  31. @login_manager.user_loader
  32. def load_user(user_id):
  33. # since the user_id is just the primary key of our user table, use it in the query for the user
  34. return User.query.get(int(user_id))
  35. # blueprint for auth routes in our app
  36. from .auth import auth as auth_blueprint
  37. app.register_blueprint(auth_blueprint)
  38. # blueprint for main parts of app
  39. from .main import main as main_blueprint
  40. app.register_blueprint(main_blueprint)
  41. # blueprint for tools parts of app
  42. from .tool import tool as tool_blueprint
  43. app.register_blueprint(tool_blueprint)
  44. # blueprint for practice parts of app
  45. from .practice import practice as practice_blueprint
  46. app.register_blueprint(practice_blueprint)
  47. # blueprint for sensitivity parts of app
  48. from .sensitivity import sensitivity as sensitivity_blueprint
  49. app.register_blueprint(sensitivity_blueprint)
  50. # blueprint for typology parts of app
  51. from .typology import typology as typology_blueprint
  52. app.register_blueprint(typology_blueprint)
  53. # blueprint for workflow parts of app
  54. from .workflow import workflow as workflow_blueprint
  55. app.register_blueprint(workflow_blueprint)
  56. # blueprint for publisher parts of app
  57. from .publisher import publisher as publisher_blueprint
  58. app.register_blueprint(publisher_blueprint)
  59. # blueprint for book parts of app
  60. from .book import book as book_blueprint
  61. app.register_blueprint(book_blueprint)
  62. # blueprint for reference parts of app
  63. from .reference import reference as reference_blueprint
  64. app.register_blueprint(reference_blueprint)
  65. # blueprint for create parts of app
  66. from .create import create as create_blueprint
  67. app.register_blueprint(create_blueprint)
  68. return app