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
ced32800
Commit
ced32800
authored
Mar 28, 2016
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new djangoapp that allows for configuration of
Verified Track Cohorts through the admin interface.
parent
7b549bc3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
214 additions
and
0 deletions
+214
-0
lms/djangoapps/verified_track_content/__init__.py
+0
-0
lms/djangoapps/verified_track_content/admin.py
+14
-0
lms/djangoapps/verified_track_content/forms.py
+54
-0
lms/djangoapps/verified_track_content/migrations/0001_initial.py
+22
-0
lms/djangoapps/verified_track_content/migrations/__init__.py
+0
-0
lms/djangoapps/verified_track_content/models.py
+39
-0
lms/djangoapps/verified_track_content/tests/test_forms.py
+45
-0
lms/djangoapps/verified_track_content/tests/test_models.py
+37
-0
lms/envs/common.py
+3
-0
No files found.
lms/djangoapps/verified_track_content/__init__.py
0 → 100644
View file @
ced32800
lms/djangoapps/verified_track_content/admin.py
0 → 100644
View file @
ced32800
"""
Django admin page for verified track configuration
"""
from
django.contrib
import
admin
from
verified_track_content.forms
import
VerifiedTrackCourseForm
from
verified_track_content.models
import
VerifiedTrackCohortedCourse
@admin.register
(
VerifiedTrackCohortedCourse
)
class
VerifiedTrackCohortedCourseAdmin
(
admin
.
ModelAdmin
):
"""Admin for enabling verified track cohorting. """
form
=
VerifiedTrackCourseForm
lms/djangoapps/verified_track_content/forms.py
0 → 100644
View file @
ced32800
"""
Forms for configuring courses for verified track cohorting
"""
from
django
import
forms
from
django.utils.translation
import
ugettext
as
_
from
xmodule.modulestore.django
import
modulestore
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
from
verified_track_content.models
import
VerifiedTrackCohortedCourse
class
VerifiedTrackCourseForm
(
forms
.
ModelForm
):
"""Validate course keys for the VerifiedTrackCohortedCourse model
The default behavior in Django admin is to:
* Save course keys for courses that do not exist.
* Return a 500 response if the course key format is invalid.
Using this form ensures that we display a user-friendly
error message instead.
"""
class
Meta
(
object
):
# pylint:disable=missing-docstring
model
=
VerifiedTrackCohortedCourse
fields
=
'__all__'
def
clean_course_key
(
self
):
"""Validate the course key.
Checks that the key format is valid and that
the course exists. If not, displays an error message.
Arguments:
field_name (str): The name of the field to validate.
Returns:
CourseKey
"""
cleaned_id
=
self
.
cleaned_data
[
'course_key'
]
error_msg
=
_
(
'COURSE NOT FOUND. Please check that the course ID is valid.'
)
try
:
course_key
=
CourseKey
.
from_string
(
cleaned_id
)
except
InvalidKeyError
:
raise
forms
.
ValidationError
(
error_msg
)
if
not
modulestore
()
.
has_course
(
course_key
):
raise
forms
.
ValidationError
(
error_msg
)
return
course_key
lms/djangoapps/verified_track_content/migrations/0001_initial.py
0 → 100644
View file @
ced32800
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
xmodule_django.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'VerifiedTrackCohortedCourse'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'course_key'
,
xmodule_django
.
models
.
CourseKeyField
(
help_text
=
'The course key for the course we would like to be auto-cohorted.'
,
unique
=
True
,
max_length
=
255
,
db_index
=
True
)),
(
'enabled'
,
models
.
BooleanField
()),
],
),
]
lms/djangoapps/verified_track_content/migrations/__init__.py
0 → 100644
View file @
ced32800
lms/djangoapps/verified_track_content/models.py
0 → 100644
View file @
ced32800
"""
Models for verified track selections.
"""
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
from
xmodule_django.models
import
CourseKeyField
class
VerifiedTrackCohortedCourse
(
models
.
Model
):
"""
Tracks which courses have verified track auto-cohorting enabled.
"""
course_key
=
CourseKeyField
(
max_length
=
255
,
db_index
=
True
,
unique
=
True
,
help_text
=
ugettext_lazy
(
u"The course key for the course we would like to be auto-cohorted."
)
)
enabled
=
models
.
BooleanField
()
def
__unicode__
(
self
):
return
u"Course: {}, enabled: {}"
.
format
(
unicode
(
self
.
course_key
),
self
.
enabled
)
@classmethod
def
is_verified_track_cohort_enabled
(
cls
,
course_key
):
"""
Checks whether or not verified track cohort is enabled for the given course.
Args:
course_key (CourseKey): a course key representing the course we want to check
Returns:
True if the course has verified track cohorts is enabled
False if not
"""
try
:
return
cls
.
objects
.
get
(
course_key
=
course_key
)
.
enabled
except
cls
.
DoesNotExist
:
return
False
lms/djangoapps/verified_track_content/tests/test_forms.py
0 → 100644
View file @
ced32800
"""
Test for forms helpers.
"""
from
opaque_keys.edx.keys
import
CourseKey
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
verified_track_content.forms
import
VerifiedTrackCourseForm
class
TestVerifiedTrackCourseForm
(
SharedModuleStoreTestCase
):
"""
Test form validation.
"""
FAKE_COURSE
=
'edX/Test_Course/Run'
BAD_COURSE_KEY
=
'bad_course_key'
@classmethod
def
setUpClass
(
cls
):
super
(
TestVerifiedTrackCourseForm
,
cls
)
.
setUpClass
()
cls
.
course
=
CourseFactory
.
create
()
def
test_form_validation_success
(
self
):
form_data
=
{
'course_key'
:
unicode
(
self
.
course
.
id
),
'enabled'
:
True
}
form
=
VerifiedTrackCourseForm
(
data
=
form_data
)
self
.
assertTrue
(
form
.
is_valid
())
def
test_form_validation_failure
(
self
):
form_data
=
{
'course_key'
:
self
.
FAKE_COURSE
,
'enabled'
:
True
}
form
=
VerifiedTrackCourseForm
(
data
=
form_data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
[
'course_key'
],
[
'COURSE NOT FOUND. Please check that the course ID is valid.'
]
)
form_data
=
{
'course_key'
:
self
.
BAD_COURSE_KEY
,
'enabled'
:
True
}
form
=
VerifiedTrackCourseForm
(
data
=
form_data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
[
'course_key'
],
[
'COURSE NOT FOUND. Please check that the course ID is valid.'
]
)
lms/djangoapps/verified_track_content/tests/test_models.py
0 → 100644
View file @
ced32800
"""
Tests for Verified Track Cohorting models
"""
from
django.test
import
TestCase
from
opaque_keys.edx.keys
import
CourseKey
from
verified_track_content.models
import
VerifiedTrackCohortedCourse
class
TestVerifiedTrackCohortedCourse
(
TestCase
):
"""
Tests that the configuration works as expected.
"""
SAMPLE_COURSE
=
'edX/Test_Course/Run'
def
test_course_enabled
(
self
):
course_key
=
CourseKey
.
from_string
(
self
.
SAMPLE_COURSE
)
# Test when no configuration exists
self
.
assertFalse
(
VerifiedTrackCohortedCourse
.
is_verified_track_cohort_enabled
(
course_key
))
# Enable for a course
config
=
VerifiedTrackCohortedCourse
.
objects
.
create
(
course_key
=
course_key
,
enabled
=
True
)
config
.
save
()
self
.
assertTrue
(
VerifiedTrackCohortedCourse
.
is_verified_track_cohort_enabled
(
course_key
))
# Disable for the course
config
.
enabled
=
False
config
.
save
()
self
.
assertFalse
(
VerifiedTrackCohortedCourse
.
is_verified_track_cohort_enabled
(
course_key
))
def
test_unicode
(
self
):
course_key
=
CourseKey
.
from_string
(
self
.
SAMPLE_COURSE
)
# Enable for a course
config
=
VerifiedTrackCohortedCourse
.
objects
.
create
(
course_key
=
course_key
,
enabled
=
True
)
config
.
save
()
self
.
assertEqual
(
unicode
(
config
),
"Course: {}, enabled: True"
.
format
(
self
.
SAMPLE_COURSE
))
lms/envs/common.py
View file @
ced32800
...
...
@@ -2016,6 +2016,9 @@ INSTALLED_APPS = (
# Management commands used for configuration automation
'edx_management_commands.management_commands'
,
# Verified Track Content Cohorting
'verified_track_content'
,
)
# Migrations which are not in the standard module "migrations"
...
...
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