Beispiel #1
0
def on_course_enrollment_change(sender, event=None, user=None, **kwargs):  # pylint: disable=unused-argument
    """
    Updates course enrollment count cache.
    """
    course_id = kwargs.get('course_id', None)
    if course_id:
        invalid_user_data_cache("course_enrollments", course_id)
        invalid_user_data_cache("cities_count", course_id)
Beispiel #2
0
def on_studentengagementscore_save(sender, instance, **kwargs):
    """
    When a studentengagementscore is saved, we want to also store the
    score value in the history table, so we have a complete history
    of the student's engagement score
    """
    invalid_user_data_cache('social', instance.course_id, instance.user.id)
    history_entry = StudentSocialEngagementScoreHistory(
        user=instance.user, course_id=instance.course_id, score=instance.score)
    history_entry.save()
def handle_studentgradebook_post_save_signal(sender, instance, **kwargs):
    """
    Handle the pre-save ORM event on CourseModuleCompletions
    """
    invalid_user_data_cache('grade', instance.course_id, instance.user.id)

    if settings.FEATURES['ENABLE_NOTIFICATIONS']:
        # attach the rank of the user before the save is completed
        data = StudentGradebook.get_user_position(
            instance.course_id,
            user_id=instance.user.id,
            exclude_users=get_aggregate_exclusion_user_ids(instance.course_id)
        )

        leaderboard_rank = data['user_position']
        grade = data['user_grade']

        # logic for Notification trigger is when a user enters into the Leaderboard
        if grade > 0.0:
            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.gradebook.rank-changed'),
                        namespace=unicode(instance.course_id),
                        payload={
                            '_schema_version': '1',
                            'rank': leaderboard_rank,
                            'leaderboard_name': 'Proficiency',
                        }
                    )

                    #
                    # 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)
def on_studentengagementscore_save(sender, instance, created, **kwargs):
    """
    When a studentengagementscore is saved, we want to also store the
    score value in the history table, so we have a complete history
    of the student's engagement score
    """
    instance.refresh_from_db()
    invalid_user_data_cache('social', instance.course_id, instance.user.id)
    history_entry = StudentSocialEngagementScoreHistory(
        user=instance.user,
        course_id=instance.course_id,
        score=instance.score
    )
    history_entry.save()
Beispiel #5
0
def generate_user_gradebook(course_key, user):
    """
    Recalculates the specified user's gradebook entry
    """
    with modulestore().bulk_operations(course_key):
        course_descriptor = get_course(course_key, depth=None)
        course_grade = CourseGradeFactory().create(user, course_descriptor)
        grade_summary = course_grade.summary
        is_passed = course_grade.passed
        progress_summary = make_courseware_summary(course_grade)
        grading_policy = course_descriptor.grading_policy
        grade = grade_summary['percent']
        proforma_grade = calculate_proforma_grade(course_grade, grading_policy)

    progress_summary = get_json_data(progress_summary)
    grade_summary = get_json_data(grade_summary)
    grading_policy = get_json_data(grading_policy)
    gradebook_entry, created = StudentGradebook.objects.get_or_create(
        user=user,
        course_id=course_key,
        defaults={
            'grade': grade,
            'proforma_grade': proforma_grade,
            'progress_summary': progress_summary,
            'grade_summary': grade_summary,
            'grading_policy': grading_policy,
            'is_passed': is_passed,
        })

    if gradebook_entry.grade != grade or \
            gradebook_entry.proforma_grade != proforma_grade or \
            gradebook_entry.is_passed != is_passed:
        gradebook_entry.grade = grade
        gradebook_entry.proforma_grade = proforma_grade
        gradebook_entry.progress_summary = progress_summary
        gradebook_entry.grade_summary = grade_summary
        gradebook_entry.grading_policy = grading_policy
        gradebook_entry.is_passed = is_passed
        gradebook_entry.save()
        invalid_user_data_cache('grade', course_key, user.id)

    return gradebook_entry
Beispiel #6
0
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()
            invalid_user_data_cache('progress', instance.course_id,
                                    instance.user.id)
        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)