Improve structure

This commit is contained in:
Kumi 2020-04-08 16:55:18 +02:00
parent 264a433574
commit a1bf7c0dbd
4 changed files with 21 additions and 21 deletions

View file

@ -1 +1,3 @@
from dbsettings.functions import *
default_app_config = 'dbsettings.apps.SettingsConfig' default_app_config = 'dbsettings.apps.SettingsConfig'

17
functions.py Normal file
View file

@ -0,0 +1,17 @@
from dbsettings.models import Setting
def getValue(key, default=None):
try:
return Setting.objects.get(key=key).value
except:
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

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,17 +1 @@
from django.shortcuts import render from dbsettings.functions import *
from dbsettings.models import Setting
def getValue(key, default=None):
try:
return Setting.objects.get(key=key).value
except:
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