Merge pull request #15431 from open-craft/jill/studio-filter-archived-courses

Separate Archived courses into a separate list in Studio
This commit is contained in:
Jillian Vogel
2017-08-02 10:42:09 +09:30
committed by GitHub
7 changed files with 225 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ import json
import logging
from cStringIO import StringIO
from datetime import datetime, timedelta
import dateutil.parser
import requests
from lazy import lazy
@@ -1393,9 +1394,10 @@ class CourseSummary(object):
A lightweight course summary class, which constructs split/mongo course summary without loading
the course. It is used at cms for listing courses to global staff user.
"""
course_info_fields = ['display_name', 'display_coursenumber', 'display_organization']
course_info_fields = ['display_name', 'display_coursenumber', 'display_organization', 'end']
def __init__(self, course_locator, display_name=u"Empty", display_coursenumber=None, display_organization=None):
def __init__(self, course_locator, display_name=u"Empty", display_coursenumber=None, display_organization=None,
end=None):
"""
Initialize and construct course summary
@@ -1412,6 +1414,8 @@ class CourseSummary(object):
display_organization (unicode|None): Course organization that is specified & appears in the courseware
end (unicode|None): Course end date. Must contain timezone.
"""
self.display_coursenumber = display_coursenumber
self.display_organization = display_organization
@@ -1419,6 +1423,9 @@ class CourseSummary(object):
self.id = course_locator # pylint: disable=invalid-name
self.location = course_locator.make_usage_key('course', 'course')
self.end = end
if end is not None and not isinstance(end, datetime):
self.end = dateutil.parser.parse(end)
@property
def display_org_with_default(self):
@@ -1439,3 +1446,9 @@ class CourseSummary(object):
if self.display_coursenumber:
return self.display_coursenumber
return self.location.course
def has_ended(self):
"""
Returns whether the course has ended.
"""
return course_metadata_utils.has_course_ended(self.end)

View File

@@ -211,7 +211,7 @@ class DirectOnlyCategorySemantics(PureModulestoreTestCase):
"""
def verify_course_summery_fields(course_summary):
""" Verify that every `course_summary` object has all the required fields """
expected_fields = CourseSummary.course_info_fields + ['id', 'location']
expected_fields = CourseSummary.course_info_fields + ['id', 'location', 'has_ended']
return all([hasattr(course_summary, field) for field in expected_fields])
self.assertTrue(all(verify_course_summery_fields(course_summary) for course_summary in course_summaries))