Exemple #1
0
    def get_object_list(self, request):
        '''Get the list of playlists based from a request'''
        playlists = None

        # here, we limit the returned playlists depending on the logged in user's privileges
        if not request.is_logged_in:
            # not logged in, allow no playlists for them
            playlists = []
        elif request.is_logged_in and request.is_admin:  # either actual admin, or a teacher
            # allow access to all playlists
            playlists = Playlist.all()
            if 'facility_user' in request.session:
                facility_id = request.session['facility_user'].facility.id
                unit = get_current_unit_settings_value(facility_id)
                facility = request.session['facility_user'].facility
                playlists = [pl for pl in playlists if (pl.unit <= unit and int((pl.tag).split()[-1]) == get_grade_by_facility(facility))]

        elif request.is_logged_in and not request.is_admin:  # user is a student
            # only allow them to access playlists that they're assigned to
            # and on the current unit
            playlists = Playlist.all()
            group = request.session['facility_user'].group
            facility_id = request.session['facility_user'].facility.id
            playlist_mappings_for_user_group = PlaylistToGroupMapping.objects.filter(group=group).values('playlist').values()
            playlist_ids_assigned = [mapping['playlist'] for mapping in playlist_mappings_for_user_group]
            unit = get_current_unit_settings_value(facility_id)
            playlists = [pl for pl in playlists if (pl.id in playlist_ids_assigned and pl.unit <= unit)]

        return playlists
Exemple #2
0
def modify_dynamic_settings(ds, request=None, user=None):

    user = user or request.session.get('facility_user')

    if user and not user.is_teacher:

        # determine the facility and unit for the current user
        facility = user.facility
        unit = get_current_unit_settings_value(facility.id)

        # look up what condition the user is currently assigned to
        condition = get_condition_by_facility_and_unit(facility, unit)

        # Set grade level on students to enable dynamic checking of student playlists within a unit.
        # TODO (richard): (doge) Much hardcode. Such hack. So get rid. Wow.
        ds["ab_testing"].student_grade_level = get_grade_by_facility(facility)
        ds["ab_testing"].unit = unit

        # load the settings associated with the user's current condition
        new_settings = CONDITION_SETTINGS.get(condition, {})

        # merge the settings into the distributed settings (ds) object
        for key, value in new_settings.items():
            namespace, setting = key.split(".")
            if namespace not in ds:
                raise Exception(
                    "Could not modify setting '%s': the '%s' app has not defined a dynamic_assets.py file containing DynamicSettings."
                    % (key, namespace))
            if not hasattr(ds[namespace], setting):
                raise Exception(
                    "Could not modify setting '%s': no such setting defined in the '%s' app's DynamicSettings."
                    % (key, namespace))
            setattr(ds[namespace], setting, value)
def modify_dynamic_settings(ds, request=None, user=None):

    user = user or request.session.get('facility_user')

    if user and not user.is_teacher:

        # determine the facility and unit for the current user
        facility = user.facility
        unit = get_current_unit_settings_value(facility.id)

        # look up what condition the user is currently assigned to
        condition = get_condition_by_facility_and_unit(facility, unit)

        # Set grade level on students to enable dynamic checking of student playlists within a unit.
        # TODO (richard): (doge) Much hardcode. Such hack. So get rid. Wow.
        ds["ab_testing"].student_grade_level = get_grade_by_facility(facility)
        ds["ab_testing"].unit = unit
        
        # load the settings associated with the user's current condition
        new_settings = CONDITION_SETTINGS.get(condition, {})

        # merge the settings into the distributed settings (ds) object
        for key, value in new_settings.items():
            namespace, setting = key.split(".")
            if namespace not in ds:
                raise Exception("Could not modify setting '%s': the '%s' app has not defined a dynamic_assets.py file containing DynamicSettings." % (key, namespace))
            if not hasattr(ds[namespace], setting):
                raise Exception("Could not modify setting '%s': no such setting defined in the '%s' app's DynamicSettings." % (key, namespace))
            setattr(ds[namespace], setting, value)
Exemple #4
0
    def get_object_list(self, request):
        '''Get the list of playlists based from a request'''
        playlists = None

        # here, we limit the returned playlists depending on the logged in user's privileges
        if not request.is_logged_in:
            # not logged in, allow no playlists for them
            playlists = []
        elif request.is_logged_in and request.is_admin:  # either actual admin, or a teacher
            # allow access to all playlists
            playlists = Playlist.all()
            if 'facility_user' in request.session:
                facility_id = request.session['facility_user'].facility.id
                unit = get_current_unit_settings_value(facility_id)
                facility = request.session['facility_user'].facility
                playlists = [
                    pl for pl in playlists
                    if (pl.unit <= unit and int((pl.tag).split()[-1]) ==
                        get_grade_by_facility(facility))
                ]

        elif request.is_logged_in and not request.is_admin:  # user is a student
            # only allow them to access playlists that they're assigned to
            # and on the current unit
            playlists = Playlist.all()
            group = request.session['facility_user'].group
            facility_id = request.session['facility_user'].facility.id
            playlist_mappings_for_user_group = PlaylistToGroupMapping.objects.filter(
                group=group).values('playlist').values()
            playlist_ids_assigned = [
                mapping['playlist']
                for mapping in playlist_mappings_for_user_group
            ]
            unit = get_current_unit_settings_value(facility_id)
            playlists = [
                pl for pl in playlists
                if (pl.id in playlist_ids_assigned and pl.unit <= unit)
            ]

        return playlists
Exemple #5
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()
Exemple #6
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()