1 | from django.conf import settings
|
---|
2 |
|
---|
3 | """
|
---|
4 | Util file for custom decorators
|
---|
5 | """
|
---|
6 |
|
---|
7 |
|
---|
8 | # Override django.conf settings for the duration of the function, then revert to original settings
|
---|
9 | def settings_override(**setting_kwargs):
|
---|
10 | def wrapper(fn):
|
---|
11 | def __inner(*args,**kwargs):
|
---|
12 | original_values = {}
|
---|
13 | for kwd in setting_kwargs:
|
---|
14 | original_values[kwd] = getattr(settings,kwd,None)
|
---|
15 | setattr(settings,kwd,setting_kwargs[kwd])
|
---|
16 | result = fn(*args,**kwargs)
|
---|
17 | for kwd in original_values:
|
---|
18 | setattr(settings,kwd,original_values[kwd])
|
---|
19 | return result
|
---|
20 | return __inner
|
---|
21 | return wrapper
|
---|