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
7
views.py
7
views.py
|
@ -1,11 +1,14 @@
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue