Django Library Users
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

parameter.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_MAIL_VALIDATION = "USERS_MAIL_VALIDATION"
  7. USERS_ADMIN_ACTIVATION = "USERS_ADMIN_ACTIVATION"
  8. USERS_PROFILE_ADDITIONS = "USERS_PROFILE_ADDITIONS"
  9. DEFAULTS = {
  10. USERS_SELF_REGISTRATION: False,
  11. USERS_MAIL_VALIDATION: True,
  12. USERS_ADMIN_ACTIVATION: True,
  13. USERS_PROFILE_ADDITIONS: {},
  14. }
  15. def __get_object_by_name__(object_name):
  16. class_data = object_name.split(".")
  17. module_path = ".".join(class_data[:-1])
  18. class_str = class_data[-1]
  19. #
  20. module = importlib.import_module(module_path)
  21. return getattr(module, class_str)
  22. def get(key):
  23. # take data from config, settings or defaults
  24. try:
  25. data = getattr(config, key)
  26. except AttributeError:
  27. try:
  28. data = getattr(settings, key)
  29. except AttributeError:
  30. data = DEFAULTS.get(key)
  31. if key in [USERS_PROFILE_ADDITIONS, ]:
  32. # Change given string to object
  33. return {key: __get_object_by_name__(data[key]) for key in data}
  34. #
  35. return data
  36. def registration_flow_description(username):
  37. if not get(USERS_MAIL_VALIDATION) and not get(USERS_ADMIN_ACTIVATION):
  38. return _("Your account has been created. You are now able to Login as %s.") % username
  39. elif get(USERS_MAIL_VALIDATION) and get(USERS_ADMIN_ACTIVATION):
  40. 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.")
  41. elif get(USERS_MAIL_VALIDATION):
  42. 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
  43. else:
  44. return _("Your account has been created. You have to wait for the activation by an administrator.")