def create_course_reference_data(course_key): """ Populates DB with test data """ user = UserFactory() group = GroupFactory() CourseGroupRelationship(course_id=course_key, group=group).save() StudentGradebook( user=user, course_id=course_key, grade=0.9, proforma_grade=0.91, progress_summary='test', grade_summary='test', grading_policy='test', ).save() StudentProgress(user=user, course_id=course_key, completions=1).save() CourseModuleCompletion(user=user, course_id=course_key, content_id='test', stage='test').save() CourseEnrollment(user=user, course_id=course_key).save() CourseAccessRole(user=user, course_id=course_key, org='test', role='TA').save() handouts_usage_key = course_key.make_usage_key('course_info', 'handouts') StudentModule(student=user, course_id=course_key, module_state_key=handouts_usage_key).save() CourseAggregatedMetaData(id=course_key, total_assessments=10, total_modules=20).save() structure_json = '{"test": true}' course_structure, created = CourseStructure.objects.get_or_create( course_id=course_key, defaults={'structure_json': structure_json} ) if not created: course_structure.structure_json = structure_json course_structure.save() CourseOverview.get_from_id(course_key)
def handle_cmc_post_save_signal(sender, instance, created, **kwargs): """ Broadcast the progress change event """ content_id = unicode(instance.content_id) detached_categories = getattr(settings, 'PROGRESS_DETACHED_CATEGORIES', []) if created and not any(category in content_id for category in detached_categories): try: progress = StudentProgress.objects.get(user=instance.user, course_id=instance.course_id) progress.completions += 1 progress.save() except ObjectDoesNotExist: progress = StudentProgress(user=instance.user, course_id=instance.course_id, completions=1) progress.save() except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() logging.error("Exception type: {} with value: {}".format(exc_type, exc_value))
def handle_cmc_post_save_signal(sender, instance, created, **kwargs): # pylint: disable=unused-argument """ Broadcast the progress change event """ content_id = unicode(instance.content_id) if is_valid_progress_module(content_id): try: progress = StudentProgress.objects.get( user=instance.user, course_id=instance.course_id) progress.completions = F('completions') + 1 progress.save() except ObjectDoesNotExist: progress = StudentProgress(user=instance.user, course_id=instance.course_id, completions=1) progress.save() except Exception: # pylint: disable=broad-except exc_type, exc_value, __ = sys.exc_info() logging.error("Exception type: %s with value: %s", exc_type, exc_value)
def handle_progress_pre_save_signal(sender, instance, **kwargs): # pylint: disable=unused-argument """ Handle the pre-save ORM event on CourseModuleCompletions """ if settings.FEATURES['ENABLE_NOTIFICATIONS']: # If notifications feature is enabled, then we need to get the user's # rank before the save is made, so that we can compare it to # after the save and see if the position changes instance.presave_leaderboard_rank = StudentProgress.get_user_position( instance.course_id, instance.user.id, get_aggregate_exclusion_user_ids(instance.course_id))['position']
def handle_progress_post_save_signal(sender, instance, **kwargs): # pylint: disable=unused-argument, invalid-name """ Handle the pre-save ORM event on CourseModuleCompletions """ if settings.FEATURES['ENABLE_NOTIFICATIONS']: # If notifications feature is enabled, then we need to get the user's # rank before the save is made, so that we can compare it to # after the save and see if the position changes leaderboard_rank = StudentProgress.get_user_position( instance.course_id, instance.user.id, get_aggregate_exclusion_user_ids(instance.course_id))['position'] # logic for Notification trigger is when a user enters into the Leaderboard leaderboard_size = getattr(settings, 'LEADERBOARD_SIZE', 3) presave_leaderboard_rank = sys.maxint if instance.presave_leaderboard_rank: presave_leaderboard_rank = instance.presave_leaderboard_rank if leaderboard_rank <= leaderboard_size and presave_leaderboard_rank > leaderboard_size: try: notification_msg = NotificationMessage( msg_type=get_notification_type( u'open-edx.lms.leaderboard.progress.rank-changed'), namespace=unicode(instance.course_id), payload={ '_schema_version': '1', 'rank': leaderboard_rank, 'leaderboard_name': 'Progress', }) # # add in all the context parameters we'll need to # generate a URL back to the website that will # present the new course announcement # # IMPORTANT: This can be changed to msg.add_click_link() if we # have a particular URL that we wish to use. In the initial use case, # we need to make the link point to a different front end website # so we need to resolve these links at dispatch time # notification_msg.add_click_link_params({ 'course_id': unicode(instance.course_id), }) publish_notification_to_user(int(instance.user.id), notification_msg) except Exception, ex: # pylint: disable=broad-except # Notifications are never critical, so we don't want to disrupt any # other logic processing. So log and continue. log.exception(ex)
def handle_progress_pre_save_signal(sender, instance, **kwargs): """ Handle the pre-save ORM event on CourseModuleCompletions """ if settings.FEATURES['ENABLE_NOTIFICATIONS']: # If notifications feature is enabled, then we need to get the user's # rank before the save is made, so that we can compare it to # after the save and see if the position changes instance.presave_leaderboard_rank = StudentProgress.get_user_position( instance.course_id, instance.user.id, get_aggregate_exclusion_user_ids(instance.course_id) )['position']
def handle_progress_post_save_signal(sender, instance, **kwargs): """ Handle the pre-save ORM event on CourseModuleCompletions """ if settings.FEATURES['ENABLE_NOTIFICATIONS']: # If notifications feature is enabled, then we need to get the user's # rank before the save is made, so that we can compare it to # after the save and see if the position changes leaderboard_rank = StudentProgress.get_user_position( instance.course_id, instance.user.id, get_aggregate_exclusion_user_ids(instance.course_id) )['position'] # logic for Notification trigger is when a user enters into the Leaderboard leaderboard_size = getattr(settings, 'LEADERBOARD_SIZE', 3) presave_leaderboard_rank = instance.presave_leaderboard_rank if instance.presave_leaderboard_rank else sys.maxint if leaderboard_rank <= leaderboard_size and presave_leaderboard_rank > leaderboard_size: try: notification_msg = NotificationMessage( msg_type=get_notification_type(u'open-edx.lms.leaderboard.progress.rank-changed'), namespace=unicode(instance.course_id), payload={ '_schema_version': '1', 'rank': leaderboard_rank, 'leaderboard_name': 'Progress', } ) # # add in all the context parameters we'll need to # generate a URL back to the website that will # present the new course announcement # # IMPORTANT: This can be changed to msg.add_click_link() if we # have a particular URL that we wish to use. In the initial use case, # we need to make the link point to a different front end website # so we need to resolve these links at dispatch time # notification_msg.add_click_link_params({ 'course_id': unicode(instance.course_id), }) publish_notification_to_user(int(instance.user.id), notification_msg) except Exception, ex: # Notifications are never critical, so we don't want to disrupt any # other logic processing. So log and continue. log.exception(ex)