mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
configuration humble bundle
This commit is contained in:
32
database/helpers.py
Normal file
32
database/helpers.py
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
from database import db
|
||||
from database.models import Configuration
|
||||
|
||||
class ConfigurationHelper:
|
||||
def getValue(self, key:str) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if conf == None:
|
||||
return None
|
||||
if (key.endswith('_enable')) :
|
||||
return conf.value in ['true', '1', 'yes', 'on']
|
||||
return conf.value
|
||||
|
||||
def getIntValue(self, key:str) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if conf == None:
|
||||
return 0
|
||||
return int(conf.value)
|
||||
|
||||
def createOrUpdate(self, key:str, value) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if (key.endswith('_enable')) :
|
||||
value = value in ['true', '1', 'yes', 'on']
|
||||
if conf :
|
||||
conf.value = value
|
||||
else :
|
||||
conf = Configuration(key = key, value = value)
|
||||
db.session.add(conf)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,4 +22,3 @@ CREATE TABLE IF NOT EXISTS `message` (
|
||||
`text` VARCHAR(256) NULL,
|
||||
periodicity INTEGER NULL
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user