Add default return value argument to getValue()
This commit is contained in:
parent
e8e5142f96
commit
264a433574
1 changed files with 6 additions and 3 deletions
9
views.py
9
views.py
|
@ -1,14 +1,17 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from dbsettings.models import Setting
|
from dbsettings.models import Setting
|
||||||
|
|
||||||
def getValue(key):
|
def getValue(key, default=None):
|
||||||
try:
|
try:
|
||||||
return Setting.objects.get(key=key).value
|
return Setting.objects.get(key=key).value
|
||||||
except:
|
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):
|
def setValue(key, value):
|
||||||
obj = Setting.objects.get_or_create(key=key)[0] # pylint: disable=E1101
|
obj = Setting.objects.get_or_create(key=key)[0] # pylint: disable=E1101
|
||||||
obj.value = value
|
obj.value = value
|
||||||
obj.save()
|
obj.save()
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue