configuration humble bundle

This commit is contained in:
Kepka Ludovic
2025-08-11 10:39:58 +02:00
parent 38b2ecc216
commit 84b92f636f
5 changed files with 55 additions and 24 deletions

32
database/helpers.py Normal file
View 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)

View File

@@ -22,4 +22,3 @@ CREATE TABLE IF NOT EXISTS `message` (
`text` VARCHAR(256) NULL,
periodicity INTEGER NULL
);