Exemple #1
0
 def _read_facility_tests(self, facility, test_id=None, force=False):
     testscache = Test.all(force=force)
     valid_tests = dict(
         (id, test) for (id, test) in testscache.iteritems()
         if test.grade == get_grade_by_facility(facility)
         and test.unit == get_current_unit_settings_value(facility.id))
     return sorted(valid_tests.values(), key=lambda test: test.title)
Exemple #2
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 #3
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
 def _read_facility_tests(self, facility, test_id=None, force=False):
     testscache = Test.all(force=force)
     valid_tests = dict((id, test) for (id, test) in testscache.iteritems() if test.grade == get_grade_by_facility(facility) and test.unit == get_current_unit_settings_value(facility.id))
     return sorted(valid_tests.values(), key=lambda test: test.title)