settings.py 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.utils.settings
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. This module contains the interface for interacting with FlaskBB's
  6. configuration.
  7. :copyright: (c) 2014 by the FlaskBB Team.
  8. :license: BSD, see LICENSE for more details.
  9. """
  10. import collections
  11. from flaskbb.management.models import Setting
  12. class FlaskBBConfig(collections.MutableMapping):
  13. """Provides a dictionary like interface for interacting with FlaskBB's
  14. Settings cache.
  15. """
  16. def __init__(self, *args, **kwargs):
  17. self.update(dict(*args, **kwargs))
  18. def __getitem__(self, key):
  19. return Setting.as_dict()[key]
  20. def __setitem__(self, key, value):
  21. Setting.update({key.lower(): value})
  22. def __delitem__(self, key):
  23. pass
  24. def __iter__(self):
  25. return iter(Setting.as_dict())
  26. def __len__(self):
  27. return len(Setting.as_dict())
  28. flaskbb_config = FlaskBBConfig()