Beispiel #1
0
    def update_video_log(cls,
                         facility_user,
                         video_id,
                         youtube_id,
                         total_seconds_watched,
                         language,
                         complete,
                         completion_timestamp,
                         points=0):
        assert facility_user and video_id and youtube_id, "Updating a video log requires a facility user, video ID, and a YouTube ID"

        ds = load_dynamic_settings(user=facility_user)

        # retrieve the previous video log for this user for this video, or make one if there isn't already one
        (videolog, _) = cls.get_or_initialize(user=facility_user,
                                              video_id=video_id)

        # combine the previously watched counts with the new counts
        #
        # Set total_seconds_watched directly, rather than incrementally, for robustness
        #   as sometimes an update request fails, and we'd miss the time update!
        videolog.total_seconds_watched = total_seconds_watched
        videolog.points = min(max(points, videolog.points),
                              ds["distributed"].points_per_video)
        videolog.language = language
        videolog.youtube_id = youtube_id
        videolog.complete = complete
        videolog.completion_timestamp = completion_timestamp

        # write the video log to the database, overwriting any old video log with the same ID
        # (and since the ID is computed from the user ID and YouTube ID, this will behave sanely)
        videolog.full_clean()
        videolog.save(update_userlog=True)

        return videolog
Beispiel #2
0
    def update_video_log(cls, facility_user, video_id, youtube_id, total_seconds_watched, language, complete, completion_timestamp, points=0):
        assert facility_user and video_id and youtube_id, "Updating a video log requires a facility user, video ID, and a YouTube ID"

        ds = load_dynamic_settings(user=facility_user)

        # retrieve the previous video log for this user for this video, or make one if there isn't already one
        (videolog, _) = cls.get_or_initialize(user=facility_user, video_id=video_id)

        # combine the previously watched counts with the new counts
        #
        # Set total_seconds_watched directly, rather than incrementally, for robustness
        #   as sometimes an update request fails, and we'd miss the time update!
        videolog.total_seconds_watched = total_seconds_watched
        videolog.points = min(max(points, videolog.points), ds["distributed"].points_per_video)
        videolog.language = language
        videolog.youtube_id = youtube_id
        videolog.complete = complete
        videolog.completion_timestamp = completion_timestamp

        # write the video log to the database, overwriting any old video log with the same ID
        # (and since the ID is computed from the user ID and YouTube ID, this will behave sanely)
        videolog.full_clean()
        videolog.save(update_userlog=True)

        return videolog
Beispiel #3
0
def handle_exam_unset(sender, **kwargs):
    test_id = kwargs.get("test_id")
    if test_id:
        testlogs = TestLog.objects.filter(test=test_id)
        for testlog in testlogs:
            facility_user = testlog.user
            facility = facility_user.facility
            unit_id = get_current_unit_settings_value(facility.id)
            ds = load_dynamic_settings(user=facility_user)
            if ds["student_testing"].turn_on_points_for_practice_exams:
                transaction_log, created = StoreTransactionLog.objects.get_or_create(user=testlog.user, context_id=unit_id, context_type="output_condition", item="gift_card")
                try:
                    transaction_log.value = int(round(settings.UNIT_POINTS * float(testlog.total_correct)/testlog.total_number))
                except ZeroDivisionError:  # one of the students just hasn't started answering a test when we turn it off
                    continue
                transaction_log.save()
Beispiel #4
0
def handle_exam_unset(sender, **kwargs):
    test_id = kwargs.get("test_id")
    if test_id:
        testlogs = TestLog.objects.filter(test=test_id)
        for testlog in testlogs:
            facility_user = testlog.user
            facility = facility_user.facility
            unit_id = get_current_unit_settings_value(facility.id)
            ds = load_dynamic_settings(user=facility_user)
            if ds["student_testing"].turn_on_points_for_practice_exams:
                transaction_log, created = StoreTransactionLog.objects.get_or_create(user=testlog.user, context_id=unit_id, context_type="output_condition", item="gift_card")
                try:
                    transaction_log.value = int(round(settings.UNIT_POINTS * float(testlog.total_correct)/testlog.total_number))
                except ZeroDivisionError:  # one of the students just hasn't started answering a test when we turn it off
                    continue
                transaction_log.save()