Beispiel #1
0
    def get(self, request, gradebook_id=None, format=None):
        try:
            if gradebook_id is None:
                grade_system_lookup_session = grutils.get_session(
                    self.gm, 'grade_system', 'lookup')
                grade_system_query_session = grutils.get_session(
                    self.gm, 'grade_system', 'query')

                grade_system_lookup_session.use_federated_gradebook_view()
                grade_system_query_session.use_federated_gradebook_view()
            else:
                grade_system_query_session = grade_system_lookup_session = self.gm.get_gradebook(
                    gutils.clean_id(gradebook_id))

            if len(self.data) == 0:
                grade_systems = grade_system_lookup_session.get_grade_systems()
            else:
                allowable_query_terms = ['displayName', 'description']
                if any(term in self.data for term in allowable_query_terms):
                    querier = grade_system_query_session.get_grade_system_query(
                    )
                    querier = gutils.config_osid_object_querier(
                        querier, self.data)
                    grade_systems = grade_system_query_session.get_grade_systems_by_query(
                        querier)
                else:
                    grade_systems = grade_system_query_session.get_grade_systems(
                    )

            data = gutils.extract_items(request, grade_systems)

            return Response(data)
        except (PermissionDenied, NotFound) as ex:
            gutils.handle_exceptions(ex)
Beispiel #2
0
 def get(self, request, format=None):
     try:
         banks = gutils.extract_items(request, self.lm.objective_banks)
         banks['data']['results'] = sorted(
             banks['data']['results'],
             key=lambda k: k['displayName']['text'].lower())
         return Response(banks)
     except (PermissionDenied, IntegrityError) as ex:
         gutils.handle_exceptions(ex)
Beispiel #3
0
 def get(self, request, format=None):
     """
     List all available gradebooks
     """
     try:
         gradebooks = self.gm.gradebooks
         gradebooks = gutils.extract_items(request, gradebooks)
         return Response(gradebooks)
     except PermissionDenied as ex:
         gutils.handle_exceptions(ex)
Beispiel #4
0
    def get(self, request, bank_id=None, format=None):
        try:
            if bank_id is None:
                objectives = []
                for bank in self.lm.objective_banks:
                    objectives += list(bank.get_objectives())

                objectives = gutils.extract_items(request, objectives)
            else:
                bank = self.lm.get_objective_bank(gutils.clean_id(bank_id))

                objectives = gutils.extract_items(request,
                                                  bank.get_objectives())
            objectives['data']['results'] = sorted(
                objectives['data']['results'],
                key=lambda k: k['displayName']['text'])
            return Response(objectives)
        except (PermissionDenied, IntegrityError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #5
0
    def get(self, request, bank_id=None, format=None):
        try:
            if bank_id is None:
                item_lookup_session = autils.get_session(
                    self.am, 'item', 'lookup')
                item_query_session = autils.get_session(
                    self.am, 'item', 'query')

                item_lookup_session.use_federated_bank_view()
                item_query_session.use_federated_bank_view()
            else:
                item_query_session = item_lookup_session = self.am.get_bank(
                    gutils.clean_id(bank_id))

            if (len(self.data) == 0 or
                (len(self.data) == 1 and self.data.keys()[0] == 'files')):
                items = item_lookup_session.get_items()
            else:
                allowable_query_terms = [
                    'maximumDifficulty', 'minimumDifficulty',
                    'maximumDiscrimination', 'mininumDiscrimination',
                    'displayName', 'learningObjectiveId', 'description'
                ]
                if any(term in self.data for term in allowable_query_terms):
                    querier = item_query_session.get_item_query()
                    querier = gutils.config_osid_object_querier(
                        querier, self.data)
                    items = item_query_session.get_items_by_query(querier)
                else:
                    items = item_lookup_session.get_items()

            data = gutils.extract_items(request, items)
            if 'files' in self.data:
                for item in data['data']['results']:
                    # Without complete authz, not a great way to handle
                    # this -- ignore ?files on items where user has no permissions.
                    # Ideally, they wouldn't even have these items in their list...
                    bank = autils.get_object_bank(self.am,
                                                  gutils.clean_id(item['id']),
                                                  'item')
                    try:
                        dlkit_item = bank.get_item(gutils.clean_id(item['id']))

                        if 'fileIds' in item:
                            item['files'] = dlkit_item.get_files()
                        if item['question'] and 'fileIds' in item['question']:
                            item['question'][
                                'files'] = dlkit_item.get_question().get_files(
                                )
                    except PermissionDenied:
                        pass

            return Response(data)
        except (PermissionDenied, IntegrityError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #6
0
    def get(self, request, column_id=None, format=None):
        try:
            if column_id is None:
                entry_lookup_session = grutils.get_session(
                    self.gm, 'grade_entry', 'lookup')
                entry_query_session = grutils.get_session(
                    self.gm, 'grade_entry', 'query')

                entry_lookup_session.use_federated_gradebook_view()
                entry_query_session.use_federated_gradebook_view()
            else:
                entry_query_session = entry_lookup_session = grutils.get_object_gradebook(
                    self.gm, column_id, 'gradebook_column')

            if len(self.data) == 0 and column_id is None:
                entries = entry_lookup_session.get_grade_entries()
            elif column_id is not None:
                if len(self.data) == 0:
                    entries = entry_lookup_session.get_grade_entries_for_gradebook_column(
                        gutils.clean_id(column_id))
                else:
                    allowable_query_terms = ['displayName', 'description']
                    if any(term in self.data
                           for term in allowable_query_terms):
                        querier = entry_query_session.get_grade_entry_query()
                        querier = gutils.config_osid_object_querier(
                            querier, self.data)
                        querier.match_gradebook_column_id(
                            gutils.clean_id(column_id))
                        entries = entry_query_session.get_grade_entries_by_query(
                            querier)
                    else:
                        entries = entry_lookup_session.get_grade_entries_for_gradebook_column(
                            gutils.clean_id(column_id))
            else:
                allowable_query_terms = ['displayName', 'description']
                if any(term in self.data for term in allowable_query_terms):
                    querier = entry_query_session.get_grade_entry_query()
                    querier = gutils.config_osid_object_querier(
                        querier, self.data)
                    entries = entry_query_session.get_grade_entries_by_query(
                        querier)
                else:
                    entries = entry_lookup_session.get_grade_entries()

            data = gutils.extract_items(request, entries)

            return Response(data)
        except (PermissionDenied, NotFound) as ex:
            gutils.handle_exceptions(ex)
Beispiel #7
0
    def get(self, request, item_id, format=None):
        try:
            bank = autils.get_object_bank(self.am,
                                          item_id,
                                          object_type='item',
                                          bank_id=None)

            item = bank.get_item(gutils.clean_id(item_id))
            data = {'data': {'data': [], 'count': 0}}
            try:
                data = gutils.extract_items(request,
                                            item.get_learning_objectives())
            except KeyError:
                pass
            except IllegalState:
                # no learning objectives
                pass
            return Response(data)
        except (PermissionDenied, NotFound) as ex:
            gutils.handle_exceptions(ex)
Beispiel #8
0
    def get(self, request, format=None):
        """
        List all available assessment banks
        """
        try:
            if len(self.data) == 0:
                assessment_banks = self.am.banks
            else:
                querier = self.am.get_bank_query()

                allowable_query_terms = ['displayName', 'description']
                if any(term in self.data for term in allowable_query_terms):
                    querier = gutils.config_osid_object_querier(
                        querier, self.data)
                    assessment_banks = self.am.get_banks_by_query(querier)
                else:
                    assessment_banks = self.am.banks

            banks = gutils.extract_items(request, assessment_banks)
            return Response(banks)
        except PermissionDenied as ex:
            gutils.handle_exceptions(ex)