Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
c7a4f97b
Commit
c7a4f97b
authored
4 years ago
by
stvn
Browse files
Options
Downloads
Patches
Plain Diff
Add get-accessor helper for discussions plugins
parent
590286f3
No related branches found
Branches containing commit
Tags
release-2020-12-18-12.59
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/discussions/models.py
+12
-2
12 additions, 2 deletions
openedx/core/djangoapps/discussions/models.py
openedx/core/djangoapps/discussions/tests/test_models.py
+33
-0
33 additions, 0 deletions
openedx/core/djangoapps/discussions/tests/test_models.py
with
45 additions
and
2 deletions
openedx/core/djangoapps/discussions/models.py
+
12
−
2
View file @
c7a4f97b
"""
Provide django models to back the discussions app
"""
from
__future__
import
annotations
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -75,8 +77,16 @@ class DiscussionsConfiguration(TimeStampedModel):
Default to False, if no configuration exists
"""
configuration
=
cls
.
get
(
context_key
)
return
configuration
.
enabled
@classmethod
def
get
(
cls
,
context_key
)
->
cls
:
"""
Lookup a model by context_key
"""
try
:
configuration
=
cls
.
objects
.
get
(
context_key
=
context_key
)
except
cls
.
DoesNotExist
:
return
False
return
configuration
.
enabled
configuration
=
cls
(
context_key
=
context_key
,
enabled
=
False
)
return
configuration
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/discussions/tests/test_models.py
+
33
−
0
View file @
c7a4f97b
...
...
@@ -103,3 +103,36 @@ class DiscussionsConfigurationModelTest(TestCase):
"""
is_enabled
=
DiscussionsConfiguration
.
is_enabled
(
self
.
course_key_with_values
)
assert
not
is_enabled
def
test_get_nonexistent
(
self
):
"""
Assert we get an
"
empty
"
model back for nonexistent records
"""
configuration
=
DiscussionsConfiguration
.
get
(
self
.
course_key_without_config
)
assert
configuration
is
not
None
assert
not
configuration
.
enabled
assert
not
configuration
.
lti_configuration
assert
not
configuration
.
plugin_configuration
assert
not
configuration
.
provider_type
def
test_get_defaults
(
self
):
"""
Assert we can lookup a record with default values
"""
configuration
=
DiscussionsConfiguration
.
get
(
self
.
course_key_with_defaults
)
assert
configuration
is
not
None
assert
configuration
.
enabled
assert
not
configuration
.
lti_configuration
assert
not
configuration
.
plugin_configuration
assert
not
configuration
.
provider_type
def
test_get_explicit
(
self
):
"""
Assert we can lookup a record with explicitly-set values
"""
configuration
=
DiscussionsConfiguration
.
get
(
self
.
course_key_with_values
)
assert
configuration
is
not
None
assert
not
configuration
.
enabled
assert
not
configuration
.
lti_configuration
assert
configuration
.
plugin_configuration
assert
configuration
.
provider_type
==
'
cs_comments_service
'
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