Merge pull request #10959 from edx/course_overview/manual_seeding
Course Overview - require manual seeding of the table
This commit is contained in:
@@ -33,12 +33,10 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
course_keys = []
|
||||
if options['all']:
|
||||
# Have CourseOverview generate course overviews for all
|
||||
# the courses in the system.
|
||||
CourseOverview.get_all_courses(force_reseeding=True)
|
||||
course_keys = [course.id for course in modulestore().get_courses()]
|
||||
else:
|
||||
course_keys = []
|
||||
if len(args) < 1:
|
||||
raise CommandError('At least one course or --all must be specified.')
|
||||
try:
|
||||
@@ -49,4 +47,4 @@ class Command(BaseCommand):
|
||||
if not course_keys:
|
||||
log.fatal('No courses specified.')
|
||||
|
||||
CourseOverview.get_select_courses(course_keys)
|
||||
CourseOverview.get_select_courses(course_keys)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('course_overviews', '0004_courseoverview_org'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='CourseOverviewGeneratedHistory',
|
||||
),
|
||||
]
|
||||
@@ -447,45 +447,20 @@ class CourseOverview(TimeStampedModel):
|
||||
return course_overviews
|
||||
|
||||
@classmethod
|
||||
def get_all_courses(cls, force_reseeding=False, org=None):
|
||||
def get_all_courses(cls, org=None):
|
||||
"""
|
||||
Returns all CourseOverview objects in the database.
|
||||
|
||||
Arguments:
|
||||
force_reseeding (bool): Optional parameter.
|
||||
|
||||
If True, the modulestore is used as the source of truth for
|
||||
the list of courses, even if the CourseOverview table was
|
||||
previously seeded. However, only non-existing CourseOverview
|
||||
entries or those with older data model versions or will get
|
||||
populated.
|
||||
|
||||
If False, the list of courses is retrieved from the
|
||||
CourseOverview table if it was previously seeded, falling
|
||||
back to the modulestore if it wasn't seeded.
|
||||
|
||||
org (string): Optional parameter that allows filtering
|
||||
by organization.
|
||||
"""
|
||||
if force_reseeding or not CourseOverviewGeneratedHistory.objects.first():
|
||||
# Seed the CourseOverview table with data for all
|
||||
# courses in the system.
|
||||
course_keys = [course.id for course in modulestore().get_courses()]
|
||||
course_overviews = cls.get_select_courses(course_keys)
|
||||
num_courses = len(course_overviews)
|
||||
CourseOverviewGeneratedHistory.objects.create(num_courses=num_courses)
|
||||
if org:
|
||||
course_overviews = [c for c in course_overviews if c.org == org]
|
||||
|
||||
else:
|
||||
# Note: If a newly created course is not returned in this QueryList,
|
||||
# make sure the "publish" signal was emitted when the course was
|
||||
# created. For tests using CourseFactory, use emit_signals=True.
|
||||
# Or pass True for force_reseeding.
|
||||
course_overviews = CourseOverview.objects.all()
|
||||
if org:
|
||||
course_overviews = course_overviews.filter(org=org)
|
||||
|
||||
# Note: If a newly created course is not returned in this QueryList,
|
||||
# make sure the "publish" signal was emitted when the course was
|
||||
# created. For tests using CourseFactory, use emit_signals=True.
|
||||
course_overviews = CourseOverview.objects.all()
|
||||
if org:
|
||||
course_overviews = course_overviews.filter(org=org)
|
||||
return course_overviews
|
||||
|
||||
@classmethod
|
||||
@@ -516,14 +491,3 @@ class CourseOverviewTab(models.Model):
|
||||
"""
|
||||
tab_id = models.CharField(max_length=50)
|
||||
course_overview = models.ForeignKey(CourseOverview, db_index=True, related_name="tabs")
|
||||
|
||||
|
||||
class CourseOverviewGeneratedHistory(TimeStampedModel):
|
||||
"""
|
||||
Model for keeping track of when CourseOverview Models are
|
||||
generated/seeded.
|
||||
"""
|
||||
num_courses = IntegerField(null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.num_courses
|
||||
|
||||
@@ -450,7 +450,7 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
|
||||
)
|
||||
|
||||
def test_get_all_courses(self):
|
||||
course_ids = [CourseFactory.create().id for __ in range(3)]
|
||||
course_ids = [CourseFactory.create(emit_signals=True).id for __ in range(3)]
|
||||
self.assertSetEqual(
|
||||
{course_overview.id for course_overview in CourseOverview.get_all_courses()},
|
||||
set(course_ids),
|
||||
@@ -462,22 +462,14 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
|
||||
CourseOverview.get_all_courses()
|
||||
self.assertFalse(mock_get_from_id.called)
|
||||
|
||||
CourseOverview.get_all_courses(force_reseeding=True)
|
||||
self.assertTrue(mock_get_from_id.called)
|
||||
|
||||
def test_get_all_courses_by_org(self):
|
||||
org_courses = [] # list of lists of courses
|
||||
for index in range(2):
|
||||
org_courses.append([
|
||||
CourseFactory.create(org='test_org_' + unicode(index))
|
||||
CourseFactory.create(org='test_org_' + unicode(index), emit_signals=True)
|
||||
for __ in range(3)
|
||||
])
|
||||
|
||||
self.assertSetEqual(
|
||||
{c.id for c in CourseOverview.get_all_courses(org='test_org_0', force_reseeding=True)},
|
||||
{c.id for c in org_courses[0]},
|
||||
)
|
||||
|
||||
self.assertSetEqual(
|
||||
{c.id for c in CourseOverview.get_all_courses(org='test_org_1')},
|
||||
{c.id for c in org_courses[1]},
|
||||
|
||||
Reference in New Issue
Block a user