Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
23fbde8e
Commit
23fbde8e
authored
Sep 21, 2017
by
Robert Raposa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Goal Enum to Choices.
parent
f94558f4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
68 deletions
+22
-68
lms/djangoapps/course_goals/api.py
+1
-36
lms/djangoapps/course_goals/models.py
+13
-12
lms/djangoapps/course_goals/views.py
+1
-14
openedx/features/course_experience/views/course_home_messages.py
+7
-6
No files found.
lms/djangoapps/course_goals/api.py
View file @
23fbde8e
"""
Course Goals Python API
"""
from
enum
import
Enum
from
opaque_keys.edx.keys
import
CourseKey
from
django.utils.translation
import
ugettext
as
_
from
openedx.core.djangolib.markup
import
Text
from
.models
import
CourseGoal
...
...
@@ -16,8 +13,7 @@ def add_course_goal(user, course_id, goal_key):
Arguments:
user: The user that is setting the goal
course_id (string): The id for the course the goal refers to
goal_key (string): The goal key that maps to one of the
enumerated goal keys from CourseGoalOption.
goal_key (string): The goal key for the new goal.
"""
# Create and save a new course goal
...
...
@@ -43,34 +39,3 @@ def remove_course_goal(user, course_key):
course_goal
=
get_course_goal
(
user
,
course_key
)
if
course_goal
:
course_goal
.
delete
()
class
CourseGoalOption
(
Enum
):
"""
Types of goals that a user can select.
These options are set to a string goal key so that they can be
referenced elsewhere in the code when necessary.
"""
CERTIFY
=
'certify'
COMPLETE
=
'complete'
EXPLORE
=
'explore'
UNSURE
=
'unsure'
@classmethod
def
get_course_goal_keys
(
self
):
return
[
key
.
value
for
key
in
self
]
def
get_goal_text
(
goal_option
):
"""
This function is used to translate the course goal option into
a translated, user-facing string to be used to represent that
particular goal.
"""
return
{
CourseGoalOption
.
CERTIFY
.
value
:
Text
(
_
(
'Earn a certificate'
)),
CourseGoalOption
.
COMPLETE
.
value
:
Text
(
_
(
'Complete the course'
)),
CourseGoalOption
.
EXPLORE
.
value
:
Text
(
_
(
'Explore the course'
)),
CourseGoalOption
.
UNSURE
.
value
:
Text
(
_
(
'Not sure yet'
)),
}[
goal_option
]
lms/djangoapps/course_goals/models.py
View file @
23fbde8e
...
...
@@ -3,26 +3,27 @@ Course Goals Models
"""
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
openedx.core.djangoapps.xmodule_django.models
import
CourseKeyField
from
model_utils
import
Choices
# Each goal is represented by a goal key and a string description.
GOAL_KEY_CHOICES
=
Choices
(
(
'certify'
,
_
(
'Earn a certificate.'
)),
(
'complete'
,
_
(
'Complete the course.'
)),
(
'explore'
,
_
(
'Explore the course.'
)),
(
'unsure'
,
_
(
'Not sure yet.'
)),
)
class
CourseGoal
(
models
.
Model
):
"""
Represents a course goal set by a user on the course home page.
The goal_key represents the goal key that maps to a translated
string through using the CourseGoalOption class.
Represents a course goal set by the user.
"""
GOAL_KEY_CHOICES
=
(
(
'certify'
,
'Earn a certificate.'
),
(
'complete'
,
'Complete the course.'
),
(
'explore'
,
'Explore the course.'
),
(
'unsure'
,
'Not sure yet.'
),
)
user
=
models
.
ForeignKey
(
User
,
blank
=
False
)
course_key
=
CourseKeyField
(
max_length
=
255
,
db_index
=
True
)
goal_key
=
models
.
CharField
(
max_length
=
100
,
choices
=
GOAL_KEY_CHOICES
,
default
=
'unsure'
)
goal_key
=
models
.
CharField
(
max_length
=
100
,
choices
=
GOAL_KEY_CHOICES
,
default
=
GOAL_KEY_CHOICES
.
unsure
)
def
__unicode__
(
self
):
return
'CourseGoal: {user} set goal to {goal} for course {course}'
.
format
(
...
...
lms/djangoapps/course_goals/views.py
View file @
23fbde8e
...
...
@@ -11,9 +11,9 @@ from openedx.core.lib.api.permissions import IsStaffOrOwner
from
rest_framework
import
permissions
,
serializers
,
viewsets
from
rest_framework.authentication
import
SessionAuthentication
from
.api
import
CourseGoalOption
from
.models
import
CourseGoal
User
=
get_user_model
()
...
...
@@ -27,19 +27,6 @@ class CourseGoalSerializer(serializers.ModelSerializer):
model
=
CourseGoal
fields
=
(
'user'
,
'course_key'
,
'goal_key'
)
def
validate_goal_key
(
self
,
value
):
"""
Ensure that the goal_key is valid.
"""
if
value
not
in
CourseGoalOption
.
get_course_goal_keys
():
raise
serializers
.
ValidationError
(
'Provided goal key, {goal_key}, is not a valid goal key (options= {goal_options}).'
.
format
(
goal_key
=
value
,
goal_options
=
[
option
.
value
for
option
in
CourseGoalOption
],
)
)
return
value
def
validate_course_key
(
self
,
value
):
"""
Ensure that the course_key is valid.
...
...
openedx/features/course_experience/views/course_home_messages.py
View file @
23fbde8e
...
...
@@ -18,7 +18,8 @@ from web_fragments.fragment import Fragment
from
course_modes.models
import
CourseMode
from
courseware.courses
import
get_course_with_access
from
lms.djangoapps.course_goals.api
import
CourseGoalOption
,
get_course_goal
,
get_goal_text
from
lms.djangoapps.course_goals.api
import
get_course_goal
from
lms.djangoapps.course_goals.models
import
GOAL_KEY_CHOICES
from
openedx.core.djangoapps.plugin_api.views
import
EdxFragmentView
from
openedx.core.djangolib.markup
import
HTML
,
Text
from
openedx.features.course_experience
import
CourseHomeMessages
...
...
@@ -157,22 +158,22 @@ def _register_course_home_messages(request, course_id, user_access, course_start
'<div tabindex="0" aria-label="{aria_label_choice}" class="goal-option dismissible" '
'data-choice="{goal_key}">'
)
.
format
(
goal_key
=
CourseGoalOption
.
UNSURE
.
valu
e
,
goal_key
=
GOAL_KEY_CHOICES
.
unsur
e
,
aria_label_choice
=
Text
(
_
(
"Set goal to: {choice}"
))
.
format
(
choice
=
get_goal_text
(
CourseGoalOption
.
UNSURE
.
value
)
choice
=
GOAL_KEY_CHOICES
[
GOAL_KEY_CHOICES
.
unsure
]
),
),
choice
=
Text
(
_
(
'{choice}'
))
.
format
(
choice
=
get_goal_text
(
CourseGoalOption
.
UNSURE
.
value
)
,
choice
=
GOAL_KEY_CHOICES
[
GOAL_KEY_CHOICES
.
unsure
]
,
),
closing_tag
=
HTML
(
'</div>'
),
)
# Add the option to set a goal to earn a certificate,
# complete the course or explore the course
goal_options
=
[
CourseGoalOption
.
CERTIFY
.
value
,
CourseGoalOption
.
COMPLETE
.
value
,
CourseGoalOption
.
EXPLORE
.
valu
e
]
goal_options
=
[
GOAL_KEY_CHOICES
.
certify
,
GOAL_KEY_CHOICES
.
complete
,
GOAL_KEY_CHOICES
.
explor
e
]
for
goal_key
in
goal_options
:
goal_text
=
get_goal_text
(
goal_key
)
goal_text
=
GOAL_KEY_CHOICES
[
goal_key
]
goal_choices_html
+=
HTML
(
'{initial_tag}{goal_text}{closing_tag}'
)
.
format
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment