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 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
|
||||
|
|
Loading…
Reference in a new issue