Add default return value argument to getValue()

This commit is contained in:
Kumi 2020-04-08 16:43:56 +02:00
parent e8e5142f96
commit 264a433574

View file

@ -1,14 +1,17 @@
from django.shortcuts import render
from dbsettings.models import Setting
def getValue(key):
def getValue(key, default=None):
try:
return Setting.objects.get(key=key).value
except:
raise KeyError("No such setting: %s" % key)
if default is None:
raise KeyError("No such setting: %s" % key)
else:
return default
def setValue(key, value):
obj = Setting.objects.get_or_create(key=key)[0] # pylint: disable=E1101
obj.value = value
obj.save()
return True
return True