Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
7f1efb9d
Commit
7f1efb9d
authored
4 years ago
by
plup
Browse files
Options
Downloads
Patches
Plain Diff
bugfix: extracted YAML loading from settings class
parent
79f1480e
No related branches found
No related tags found
2 merge requests
!167
Add python code in settings
,
!158
Load djangoldp conguration from YAML file
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/conf/ldpsettings.py
+11
-25
11 additions, 25 deletions
djangoldp/conf/ldpsettings.py
djangoldp/tests/runner.py
+3
-3
3 additions, 3 deletions
djangoldp/tests/runner.py
with
14 additions
and
28 deletions
djangoldp/conf/ldpsettings.py
+
11
−
25
View file @
7f1efb9d
...
...
@@ -20,8 +20,14 @@ logger = logging.getLogger(__name__)
def
configure
(
filename
=
'
settings.yml
'
):
"""
Helper function to configure django from LDPSettings.
"""
try
:
with
open
(
self
.
path
,
'
r
'
)
as
f
:
config
=
yaml
.
safe_load
(
f
)
except
FileNotFoundError
:
logger
.
info
(
'
Starting project without configuration file
'
)
# ref: https://docs.djangoproject.com/fr/2.2/topics/settings/#custom-default-settings
ldpsettings
=
LDPSettings
(
path
=
filename
)
ldpsettings
=
LDPSettings
(
config
)
django_settings
.
configure
(
ldpsettings
)
...
...
@@ -30,34 +36,14 @@ class LDPSettings(object):
"""
Class managing the DjangoLDP configuration.
"""
def
__init__
(
self
,
path
):
def
__init__
(
self
,
config
):
if
django_settings
.
configured
:
raise
ImproperlyConfigured
(
'
Settings have been configured already
'
)
self
.
path
=
path
self
.
_config
=
None
self
.
_config
=
config
self
.
_settings
=
self
.
build_settings
()
@property
def
config
(
self
):
"""
Load configuration from file.
"""
if
not
self
.
_config
:
try
:
with
open
(
self
.
path
,
'
r
'
)
as
f
:
self
.
_config
=
yaml
.
safe_load
(
f
)
except
FileNotFoundError
:
logger
.
info
(
'
Starting project without configuration file
'
)
return
self
.
_config
@config.setter
def
config
(
self
,
value
):
"""
Set a dict has current configuration.
"""
self
.
_config
=
value
def
build_settings
(
self
,
extend
=
[
'
INSTALLED_APPS
'
,
'
MIDDLEWARE
'
]):
"""
Look for the parameters in multiple places.
...
...
@@ -113,7 +99,7 @@ class LDPSettings(object):
# look in YAML config file 'server' section
try
:
conf
=
self
.
config
.
get
(
'
server
'
,
{})
conf
=
self
.
_
config
.
get
(
'
server
'
,
{})
update_with
(
conf
)
logger
.
debug
(
f
'
Updating settings with project config
'
)
except
KeyError
:
...
...
@@ -126,7 +112,7 @@ class LDPSettings(object):
"""
Returns the list of LDP packages configured.
"""
pkg
=
self
.
config
.
get
(
'
ldppackages
'
,
[])
pkg
=
self
.
_
config
.
get
(
'
ldppackages
'
,
[])
return
[]
if
pkg
is
None
else
pkg
@property
...
...
This diff is collapsed.
Click to expand it.
djangoldp/tests/runner.py
+
3
−
3
View file @
7f1efb9d
...
...
@@ -6,9 +6,9 @@ from django.conf import settings as django_settings
from
djangoldp.conf.ldpsettings
import
LDPSettings
from
djangoldp.tests.settings_default
import
yaml_config
#
override config loadin
g
ldpsettings
=
LDPSettings
(
""
)
ldpsettings
.
config
=
yaml
.
safe_load
(
yaml_
config
)
#
load test confi
g
config
=
yaml
.
safe_load
(
yaml_config
)
ldpsettings
=
LDPSettings
(
config
)
django_settings
.
configure
(
ldpsettings
)
django
.
setup
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment