Improve structure
This commit is contained in:
parent
264a433574
commit
a1bf7c0dbd
4 changed files with 21 additions and 21 deletions
|
@ -1 +1,3 @@
|
|||
default_app_config = 'dbsettings.apps.SettingsConfig'
|
||||
from dbsettings.functions import *
|
||||
|
||||
default_app_config = 'dbsettings.apps.SettingsConfig'
|
||||
|
|
17
functions.py
Normal file
17
functions.py
Normal 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
|
||||
|
3
tests.py
3
tests.py
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
18
views.py
18
views.py
|
@ -1,17 +1 @@
|
|||
from django.shortcuts import render
|
||||
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
|
||||
from dbsettings.functions import *
|
||||
|
|
Loading…
Reference in a new issue