Thursday, January 3, 2013

Re: Django app custom settings testing

This approach is only useful for modules that import app.settings and use things that it defines.  It doesn't affect things that import settings from django.conf .

Your app can import settings from app, and get your settings.  That's not going to affect any other app.  If you want to affect what other apps see, you must either put the settings in the main settings file, or modify django.conf.settings itself.  This last is fraught with peril, since you can't reliably control the order in which you modify the settings object versus when other modules may use its values in a persistent way.

Or am I missing your point?

Bill

On Thu, Jan 3, 2013 at 12:05 AM, Pedro J. Aramburu <paramburu@tres42.com.ar> wrote:
Hi, I'm having troubles using the override_settings decorator. The thing is I'm writing an app that has it's own settings and I'm doing it with the approach of putting a settings.py file on the app folder with something like this:

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured


SETTING_A = getattr(settings, 'APP_SETTING_A', False)

SETTING_B = getattr(settings, 'APP_SETTING_B', False)

if SETTING_A and not SETTING_B:
    raise ImproperlyConfigured('"SETTING_A" is set to True but "SETTING_B" is missing.')
-----
Where SETTING_B should be a tuple that depends on SETTING_A (I know I didn't type check yet). Then I use the settings importing app.settings. The thing is, I believe, that the settings are loaded once and as they're outside the project settings.py, override settings doesn't have any effect.

What would you recommend?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/22xrwU84AG8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment