#10098: LazySettings.get function with default value ---------------------------+------------------------------------------------ Reporter: fero | Owner: nobody Status: new | Milestone: Component: Uncategorized | Version: 1.0 Keywords: | Stage: Unreviewed Has_patch: 1 | ---------------------------+------------------------------------------------ Add a 'get' method to LazySettings class in order to easily get a settings.py variable or its default value.
settings.get(var_name, default) instead of try: myvar = settings.var except AttributeError: myvar = default_value my current patch is: --- django/conf/__init__.py 2009-01-22 18:19:38.585001432 +0100 +++ django/conf/__init__.py.new 2009-01-22 18:23:00.221043810 +0100 @@ -41,6 +41,13 @@ self._import_settings() setattr(self._target, name, value) + def get(self, name, default=None): + + try: + getattr(self, name) + except AttributeError: + return default + def _import_settings(self): """ Load the settings module pointed to by the environment variable. This -- Ticket URL: <http://code.djangoproject.com/ticket/10098> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---