Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated query according to model update #41

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bulk_grades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.6.7'
__version__ = '0.6.8'

default_app_config = 'bulk_grades.apps.BulkGradesConfig' # pylint: disable=invalid-name
29 changes: 15 additions & 14 deletions bulk_grades/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def _get_enrollments(course_id, track=None, cohort=None):
'student_uid': institution user id from program enrollment
}
"""
enrollments = apps.get_model('student', 'CourseEnrollment').objects.filter(
course_id=course_id).select_related('user', 'programcourseenrollment')

enrollments = apps.get_model('student', 'CourseEnrollment').objects.filter(course_id=course_id).select_related(
'user').prefetch_related('programcourseenrollment_set')
if track:
enrollments = enrollments.filter(mode=track)
if cohort:
Expand All @@ -61,10 +60,11 @@ def _get_enrollments(course_id, track=None, cohort=None):
'enrolled': enrollment.is_active,
'track': enrollment.mode,
}
try:
pce = enrollment.programcourseenrollment.program_enrollment
enrollment_dict['student_uid'] = pce.external_user_key
except ObjectDoesNotExist:
program_course_enrollment = enrollment.programcourseenrollment_set.all()
awaisdar001 marked this conversation as resolved.
Show resolved Hide resolved
if program_course_enrollment.exists():
program_course_enrollment = program_course_enrollment.first().program_enrollment
enrollment_dict['student_uid'] = program_course_enrollment.external_user_key
else:
Comment on lines +63 to +67

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the program_enrollment object be the same for all the PCE? Just confirming this to avoid any incomplete/incorrect data export.

enrollment_dict['student_uid'] = None
yield enrollment_dict

Expand Down Expand Up @@ -206,6 +206,7 @@ class GradedSubsectionMixin(object):
Mixin to help generated lists of graded subsections
and appropriate column names for each.
"""

def append_columns(self, new_column_names):
"""
Appends items from ``new_column_names`` to ``self.columns``
Expand Down Expand Up @@ -365,13 +366,13 @@ def process_row(self, row):
Save a row to the persistent subsection override table.
"""
grades_api.override_subsection_grade(
row['user_id'],
row['course_id'],
row['block_id'],
overrider=self._user,
earned_graded=row['new_override'],
feature='grade-import',
comment='Bulk Grade Import',
row['user_id'],
row['course_id'],
row['block_id'],
overrider=self._user,
earned_graded=row['new_override'],
feature='grade-import',
comment='Bulk Grade Import',
)
return True, None

Expand Down
2 changes: 1 addition & 1 deletion mock_apps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ProgramEnrollment(object):


class ProgramCourseEnrollment(models.Model):
course_enrollment = models.OneToOneField(CourseEnrollment, on_delete=models.CASCADE)
course_enrollment = models.ForeignKey(CourseEnrollment, on_delete=models.CASCADE)
awaisdar001 marked this conversation as resolved.
Show resolved Hide resolved

@property
def program_enrollment(self):
Expand Down