Django Library Users
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import config
  2. from django.conf import settings
  3. from django.utils.translation import gettext as _
  4. import importlib
  5. USERS_SELF_REGISTRATION = "USERS_SELF_REGISTRATION"
  6. USERS_PASSWORD_RECOVERY = 'USERS_PASSWORD_RECOVERY'
  7. USERS_MAIL_VALIDATION = "USERS_MAIL_VALIDATION"
  8. USERS_ADMIN_ACTIVATION = "USERS_ADMIN_ACTIVATION"
  9. USERS_PROFILE_ADDITIONS = "USERS_PROFILE_ADDITIONS"
  10. DEFAULTS = {
  11. USERS_SELF_REGISTRATION: False,
  12. USERS_PASSWORD_RECOVERY: False,
  13. USERS_MAIL_VALIDATION: True,
  14. USERS_ADMIN_ACTIVATION: True,
  15. USERS_PROFILE_ADDITIONS: {},
  16. }
  17. def __get_object_by_name__(object_name):
  18. class_data = object_name.split(".")
  19. module_path = ".".join(class_data[:-1])
  20. class_str = class_data[-1]
  21. #
  22. module = importlib.import_module(module_path)
  23. return getattr(module, class_str)
  24. def get(key):
  25. # take data from config, settings or defaults
  26. try:
  27. data = getattr(config, key)
  28. except AttributeError:
  29. try:
  30. data = getattr(settings, key)
  31. except AttributeError:
  32. data = DEFAULTS.get(key)
  33. if key in [USERS_PROFILE_ADDITIONS, ]:
  34. # Change given string to object
  35. return {key: __get_object_by_name__(data[key]) for key in data}
  36. #
  37. return data
  38. def registration_flow_description(username):
  39. if not get(USERS_MAIL_VALIDATION) and not get(USERS_ADMIN_ACTIVATION):
  40. return _("Your account has been created. You are now able to Login as %s.") % username
  41. elif get(USERS_MAIL_VALIDATION) and get(USERS_ADMIN_ACTIVATION):
  42. return _("Your account has been created. You'll get an email to validate your account. Then you have to wait for the activation by an administrator.")
  43. elif get(USERS_MAIL_VALIDATION):
  44. return _("Your account has been created. You'll get an email to validate your account. After validation you are able to Login as %s.") % username
  45. else:
  46. return _("Your account has been created. You have to wait for the activation by an administrator.")