Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Hsin-Yu Chien
edx-platform-release
Commits
996eceb6
Commit
996eceb6
authored
6 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Add a facility for getting the SiteConfiguration that an org belongs to
parent
96972887
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/site_configuration/models.py
+24
-9
24 additions, 9 deletions
openedx/core/djangoapps/site_configuration/models.py
openedx/core/djangoapps/site_configuration/tests/test_models.py
+28
-0
28 additions, 0 deletions
...x/core/djangoapps/site_configuration/tests/test_models.py
with
52 additions
and
9 deletions
openedx/core/djangoapps/site_configuration/models.py
+
24
−
9
View file @
996eceb6
...
...
@@ -60,6 +60,25 @@ class SiteConfiguration(models.Model):
return
default
@classmethod
def
get_configuration_for_org
(
cls
,
org
):
"""
This returns a SiteConfiguration object which has an org_filter that matches
the supplied org
Args:
org (str): Org to use to filter SiteConfigurations
"""
for
configuration
in
cls
.
objects
.
filter
(
values__contains
=
org
,
enabled
=
True
).
all
():
course_org_filter
=
configuration
.
get_value
(
'
course_org_filter
'
,
[])
# The value of 'course_org_filter' can be configured as a string representing
# a single organization or a list of strings representing multiple organizations.
if
not
isinstance
(
course_org_filter
,
list
):
course_org_filter
=
[
course_org_filter
]
if
org
in
course_org_filter
:
return
configuration
return
None
@classmethod
def
get_value_for_org
(
cls
,
org
,
name
,
default
=
None
):
"""
...
...
@@ -74,15 +93,11 @@ class SiteConfiguration(models.Model):
Returns:
Configuration value for the given key.
"""
for
configuration
in
cls
.
objects
.
filter
(
values__contains
=
org
,
enabled
=
True
).
all
():
course_org_filter
=
configuration
.
get_value
(
'
course_org_filter
'
,
[])
# The value of 'course_org_filter' can be configured as a string representing
# a single organization or a list of strings representing multiple organizations.
if
not
isinstance
(
course_org_filter
,
list
):
course_org_filter
=
[
course_org_filter
]
if
org
in
course_org_filter
:
return
configuration
.
get_value
(
name
,
default
)
return
default
configuration
=
cls
.
get_configuration_for_org
(
org
)
if
configuration
is
None
:
return
default
else
:
return
configuration
.
get_value
(
name
,
default
)
@classmethod
def
get_all_orgs
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/site_configuration/tests/test_models.py
+
28
−
0
View file @
996eceb6
...
...
@@ -275,6 +275,34 @@ class SiteConfigurationTests(TestCase):
"
dummy-default-value
"
,
)
def
test_get_site_for_org
(
self
):
"""
Test that get_value_for_org returns correct value for any given key.
"""
# add SiteConfiguration to database
config1
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site
,
values
=
self
.
test_config1
,
)
config2
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site2
,
values
=
self
.
test_config2
,
)
# Make sure entry is saved and retrieved correctly
self
.
assertEqual
(
SiteConfiguration
.
get_configuration_for_org
(
self
.
test_config1
[
'
course_org_filter
'
]),
config1
,
)
self
.
assertEqual
(
SiteConfiguration
.
get_configuration_for_org
(
self
.
test_config2
[
'
course_org_filter
'
]),
config2
,
)
self
.
assertEqual
(
SiteConfiguration
.
get_configuration_for_org
(
'
something else
'
),
None
,
)
def
test_get_all_orgs
(
self
):
"""
Test that get_all_orgs returns all orgs from site configuration.
...
...
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