Skip to content

Commit 25d8dd3

Browse files
committed
Refactored suit init defaults
1 parent 586b64c commit 25d8dd3

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

suit/__init__.py

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
from django.conf import settings
2-
from django.contrib.admin import ModelAdmin
3-
41
VERSION = '0.1.0'
52

6-
# Reverse default actions position
7-
ModelAdmin.actions_on_top = False
8-
ModelAdmin.actions_on_bottom = True
93

104
def default_config():
115
return {
@@ -27,7 +21,7 @@ def default_config():
2721
'MENU_ICONS': {
2822
'auth': 'icon-lock',
2923
'sites': 'icon-leaf',
30-
},
24+
},
3125
# 'MENU_ORDER': (
3226
# ('sites',),
3327
# ('auth', ('user','group')),
@@ -38,20 +32,32 @@ def default_config():
3832
}
3933

4034

41-
def get_config(param=None):
42-
config_key = 'SUIT_CONFIG'
43-
if hasattr(settings, config_key):
44-
config = getattr(settings, config_key, {})
45-
else:
46-
config = default_config()
47-
if param:
48-
value = None
49-
if param in config:
50-
value = config.get(param)
51-
if value is None:
52-
value = default_config().get(param)
53-
return value
54-
return config
55-
56-
# Set global list_per_page
57-
ModelAdmin.list_per_page = get_config('LIST_PER_PAGE')
35+
from os import getenv
36+
37+
if getenv('DJANGO_SETTINGS_MODULE', None):
38+
39+
from django.contrib.admin import ModelAdmin
40+
from django.conf import settings
41+
42+
def get_config(param=None):
43+
44+
config_key = 'SUIT_CONFIG'
45+
if hasattr(settings, config_key):
46+
config = getattr(settings, config_key, {})
47+
else:
48+
config = default_config()
49+
if param:
50+
value = None
51+
if param in config:
52+
value = config.get(param)
53+
if value is None:
54+
value = default_config().get(param)
55+
return value
56+
return config
57+
58+
# Reverse default actions position
59+
ModelAdmin.actions_on_top = False
60+
ModelAdmin.actions_on_bottom = True
61+
62+
# Set global list_per_page
63+
ModelAdmin.list_per_page = get_config('LIST_PER_PAGE')

0 commit comments

Comments
 (0)