Moved the conversion thing into the ConfigAttribute.
This commit is contained in:
parent
6dccf77546
commit
8da8a21b69
3 changed files with 27 additions and 28 deletions
|
|
@ -21,13 +21,17 @@ from werkzeug.utils import import_string
|
|||
class ConfigAttribute(object):
|
||||
"""Makes an attribute forward to the config"""
|
||||
|
||||
def __init__(self, name):
|
||||
def __init__(self, name, get_converter=None):
|
||||
self.__name__ = name
|
||||
self.get_converter = get_converter
|
||||
|
||||
def __get__(self, obj, type=None):
|
||||
if obj is None:
|
||||
return self
|
||||
return obj.config[self.__name__]
|
||||
rv = obj.config[self.__name__]
|
||||
if self.get_converter is not None:
|
||||
rv = self.get_converter(rv)
|
||||
return rv
|
||||
|
||||
def __set__(self, obj, value):
|
||||
obj.config[self.__name__] = value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue