__init__.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright 2013 The Distro Tracker Developers
  2. # See the COPYRIGHT file at the top-level directory of this distribution and
  3. # at http://deb.li/DTAuthors
  4. #
  5. # This file is part of Distro Tracker. It is subject to the license terms
  6. # in the LICENSE file found in the top-level directory of this
  7. # distribution and at http://deb.li/DTLicense. No part of Distro Tracker,
  8. # including this file, may be copied, modified, propagated, or distributed
  9. # except according to the terms contained in the LICENSE file.
  10. """
  11. This Django app implements a custom User authentication model which lets users
  12. log in using a set of different email addresses.
  13. """
  14. from __future__ import unicode_literals
  15. from django.conf import settings
  16. import importlib
  17. def run_hook(name, *args, **kwargs):
  18. """
  19. Since :mod:`django_email_accounts` provides a way for users to execute
  20. custom functions at certain points, this function is used to run find
  21. the appropriate one and run it with the given arguments and keyword
  22. arguments.
  23. """
  24. name_to_setting = {
  25. 'post-merge': 'DJANGO_EMAIL_ACCOUNTS_POST_MERGE_HOOK',
  26. 'pre-login': 'DJANGO_EMAIL_ACCOUNTS_PRE_LOGIN_HOOK',
  27. 'post-logout-redirect': 'DJANGO_EMAIL_ACCOUNTS_POST_LOGOUT_REDIRECT',
  28. }
  29. if name not in name_to_setting:
  30. return
  31. settings_name = name_to_setting[name]
  32. function_name = getattr(settings, settings_name, None)
  33. if not function_name:
  34. return
  35. module, function_name = function_name.rsplit('.', 1)
  36. module = importlib.import_module(module)
  37. function = getattr(module, function_name)
  38. return function(*args, **kwargs)