From 264a433574bbaec35f96c212908e76cf8f4423bb Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 8 Apr 2020 16:43:56 +0200 Subject: [PATCH] Add default return value argument to getValue() --- views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/views.py b/views.py index 5c3bf28..54663dd 100644 --- a/views.py +++ b/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 \ No newline at end of file + return True