extensions.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.extensions
  4. ~~~~~~~~~~~~~~~~~~
  5. The extensions that are used by FlaskBB.
  6. :copyright: (c) 2014 by the FlaskBB Team.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from celery import Celery
  10. from sqlalchemy import MetaData
  11. from flask_alembic import Alembic
  12. from flask_allows import Allows
  13. from flask_babelplus import Babel
  14. from flask_caching import Cache
  15. from flask_debugtoolbar import DebugToolbarExtension
  16. from flask_limiter import Limiter
  17. from flask_limiter.util import get_remote_address
  18. from flask_login import LoginManager
  19. from flask_mail import Mail
  20. from flask_redis import FlaskRedis
  21. from flask_sqlalchemy import SQLAlchemy
  22. from flask_themes2 import Themes
  23. from flask_whooshee import Whooshee
  24. from flask_wtf.csrf import CSRFProtect
  25. from flaskbb.exceptions import AuthorizationRequired
  26. # Permissions Manager
  27. allows = Allows(throws=AuthorizationRequired)
  28. # Database
  29. metadata = MetaData(
  30. naming_convention={
  31. "ix": "ix_%(column_0_label)s",
  32. "uq": "uq_%(table_name)s_%(column_0_name)s",
  33. "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
  34. "pk": "pk_%(table_name)s",
  35. }
  36. )
  37. db = SQLAlchemy(metadata=metadata)
  38. # Whooshee (Full Text Search)
  39. whooshee = Whooshee()
  40. # Login
  41. login_manager = LoginManager()
  42. # Mail
  43. mail = Mail()
  44. # Caching
  45. cache = Cache()
  46. # Redis
  47. redis_store = FlaskRedis()
  48. # Debugtoolbar
  49. debugtoolbar = DebugToolbarExtension()
  50. # Migrations
  51. alembic = Alembic()
  52. # Themes
  53. themes = Themes()
  54. # Babel
  55. babel = Babel()
  56. # CSRF
  57. csrf = CSRFProtect()
  58. # Rate Limiting
  59. limiter = Limiter(auto_check=False, key_func=get_remote_address)
  60. # Celery
  61. celery = Celery("flaskbb")