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
5284f397
Commit
5284f397
authored
4 years ago
by
stvn
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Make discussions helper method more accessible
so we can use it elsewhere.
parent
b1fa2bda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/discussions/views.py
+18
-17
18 additions, 17 deletions
openedx/core/djangoapps/discussions/views.py
with
18 additions
and
17 deletions
openedx/core/djangoapps/discussions/views.py
+
18
−
17
View file @
5284f397
...
...
@@ -170,7 +170,7 @@ class DiscussionsConfigurationView(APIView):
"""
Handle HTTP/GET requests
"""
course_key
=
self
.
_validate_course_key
(
course_key_string
)
course_key
=
_validate_course_key
(
course_key_string
)
configuration
=
DiscussionsConfiguration
.
get
(
course_key
)
serializer
=
self
.
Serializer
(
configuration
)
return
Response
(
serializer
.
data
)
...
...
@@ -181,25 +181,26 @@ class DiscussionsConfigurationView(APIView):
TODO: Should we cleanup orphaned LTI config when swapping to cs_comments_service?
"""
course_key
=
self
.
_validate_course_key
(
course_key_string
)
course_key
=
_validate_course_key
(
course_key_string
)
configuration
=
DiscussionsConfiguration
.
get
(
course_key
)
serializer
=
self
.
Serializer
(
configuration
,
data
=
request
.
data
,
partial
=
True
)
if
serializer
.
is_valid
(
raise_exception
=
True
):
serializer
.
save
()
return
Response
(
serializer
.
data
)
def
_validate_course_key
(
self
,
course_key_string
:
str
)
->
CourseKey
:
"""
Validate and parse a course_key string, if supported
"""
try
:
course_key
=
CourseKey
.
from_string
(
course_key_string
)
except
InvalidKeyError
as
error
:
raise
serializers
.
ValidationError
(
f
"
{
course_key_string
}
is not a valid CourseKey
"
)
from
error
if
course_key
.
deprecated
:
raise
serializers
.
ValidationError
(
'
Deprecated CourseKeys (Org/Course/Run) are not supported.
'
)
return
course_key
def
_validate_course_key
(
course_key_string
:
str
)
->
CourseKey
:
"""
Validate and parse a course_key string, if supported
"""
try
:
course_key
=
CourseKey
.
from_string
(
course_key_string
)
except
InvalidKeyError
as
error
:
raise
serializers
.
ValidationError
(
f
"
{
course_key_string
}
is not a valid CourseKey
"
)
from
error
if
course_key
.
deprecated
:
raise
serializers
.
ValidationError
(
'
Deprecated CourseKeys (Org/Course/Run) are not supported.
'
)
return
course_key
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