import config from django.conf import settings from django.utils.translation import gettext as _ import importlib USERS_SELF_REGISTRATION = "USERS_SELF_REGISTRATION" USERS_MAIL_VALIDATION = "USERS_MAIL_VALIDATION" USERS_ADMIN_ACTIVATION = "USERS_ADMIN_ACTIVATION" USERS_PROFILE_ADDITIONS = "USERS_PROFILE_ADDITIONS" DEFAULTS = { USERS_SELF_REGISTRATION: False, USERS_MAIL_VALIDATION: True, USERS_ADMIN_ACTIVATION: True, USERS_PROFILE_ADDITIONS: {}, } def __get_object_by_name__(object_name): class_data = object_name.split(".") module_path = ".".join(class_data[:-1]) class_str = class_data[-1] # module = importlib.import_module(module_path) return getattr(module, class_str) def get(key): # take data from config, settings or defaults try: data = getattr(config, key) except AttributeError: try: data = getattr(settings, key) except AttributeError: data = DEFAULTS.get(key) if key in [USERS_PROFILE_ADDITIONS, ]: # Change given string to object return {key: __get_object_by_name__(data[key]) for key in data} # return data def registration_flow_description(username): if not get(USERS_MAIL_VALIDATION) and not get(USERS_ADMIN_ACTIVATION): return _("Your account has been created. You are now able to Login as %s.") % username elif get(USERS_MAIL_VALIDATION) and get(USERS_ADMIN_ACTIVATION): 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.") elif get(USERS_MAIL_VALIDATION): 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 else: return _("Your account has been created. You have to wait for the activation by an administrator.")