36 lines
545 B
Python
36 lines
545 B
Python
import json
|
|
from tinysql import Row
|
|
from .base import DEFAULT_CONFIG
|
|
from ..misc import DotDict, boolean
|
|
|
|
|
|
ROWS = []
|
|
|
|
|
|
def register(cls):
|
|
ROWS.append(cls)
|
|
return cls
|
|
|
|
|
|
@register
|
|
class ConfigRow(Row):
|
|
__table__ = 'config'
|
|
|
|
@property
|
|
def value(self):
|
|
type = DEFAULT_CONFIG[self.key][0]
|
|
|
|
if type == 'int':
|
|
return int(self['value'])
|
|
|
|
elif type == 'bool':
|
|
return boolean(self['value'])
|
|
|
|
elif type == 'list':
|
|
return json.loads(self['value'])
|
|
|
|
elif type == 'json':
|
|
return DotDict.parse(self['value'])
|
|
|
|
return self['value']
|