Beispiel #1
0
    def put(self, request, column_id, format=None):
        try:
            gutils.verify_at_least_one_key_present(
                self.data, ['displayName', 'description', 'gradeSystemId'])

            gradebook = grutils.get_object_gradebook(self.gm, column_id,
                                                     'gradebook_column')
            gradebook_column = gradebook.get_gradebook_column(
                gutils.clean_id(column_id))

            form = gradebook.get_gradebook_column_form_for_update(
                gradebook_column.ident)

            form = gutils.set_form_basics(form, self.data)
            if 'gradeSystemId' in self.data:
                form.set_grade_system(
                    gutils.clean_id(self.data['gradeSystemId']))

            gradebook.update_gradebook_column(form)

            gradebook_column = gradebook.get_gradebook_column(
                gradebook_column.ident)

            return gutils.UpdatedResponse(gradebook_column.object_map)
        except (PermissionDenied, InvalidArgument, KeyError) as ex:
            gutils.handle_exceptions(ex)
        except IllegalState as ex:
            modified_ex = type(ex)('Entries exist in this gradebook column. ' +
                                   'Cannot change the grade system.')
            gutils.handle_exceptions(modified_ex)
Beispiel #2
0
    def put(self, request, bank_id, format=None):
        try:
            form = self.am.get_bank_form_for_update(gutils.clean_id(bank_id))

            form = gutils.set_form_basics(form, self.data)

            updated_bank = self.am.update_bank(form)
            bank = gutils.convert_dl_object(updated_bank)
            gutils.update_links(request, bank)
            return gutils.UpdatedResponse(bank)
        except (PermissionDenied, InvalidArgument) as ex:
            gutils.handle_exceptions(ex)
Beispiel #3
0
    def put(self, request, gradebook_id, format=None):
        try:
            form = self.gm.get_gradebook_form_for_update(
                gutils.clean_id(gradebook_id))

            gutils.verify_at_least_one_key_present(
                self.data, ['displayName', 'description'])

            form = gutils.set_form_basics(form, self.data)

            updated_gradebook = self.gm.update_gradebook(form)
            updated_gradebook = gutils.convert_dl_object(updated_gradebook)

            return gutils.UpdatedResponse(updated_gradebook)
        except (PermissionDenied, KeyError, InvalidArgument, NotFound) as ex:
            gutils.handle_exceptions(ex)
Beispiel #4
0
    def post(self, request, format=None):
        """
        Create a new assessment bank, if authorized
        Create a new group in IS&T Membership service

        """
        try:
            form = self.am.get_bank_form_for_create([])

            form = gutils.set_form_basics(form, self.data)

            new_bank = gutils.convert_dl_object(self.am.create_bank(form))

            return gutils.CreatedResponse(new_bank)
        except (PermissionDenied, InvalidArgument) as ex:
            gutils.handle_exceptions(ex)
Beispiel #5
0
    def post(self, request, gradebook_id=None, format=None):
        try:
            if gradebook_id is None:
                gutils.verify_keys_present(self.data, ['gradebookId'])
                gradebook_id = self.data['gradebookId']

            gutils.verify_at_least_one_key_present(
                self.data, ['displayName', 'description'])

            gradebook = self.gm.get_gradebook(gutils.clean_id(gradebook_id))

            form = gradebook.get_grade_system_form_for_create([])

            form = gutils.set_form_basics(form, self.data)

            check_scores = True

            if 'basedOnGrades' in self.data:
                form.set_based_on_grades(bool(self.data['basedOnGrades']))
                if self.data['basedOnGrades']:
                    check_scores = False

            if check_scores:
                grutils.check_numeric_score_inputs(self.data)

                form.set_highest_numeric_score(float(
                    self.data['highestScore']))
                form.set_lowest_numeric_score(float(self.data['lowestScore']))
                form.set_numeric_score_increment(
                    float(self.data['scoreIncrement']))

            grade_system = gradebook.create_grade_system(form)

            if not check_scores:
                grutils.check_grade_inputs(self.data)
                grutils.add_grades_to_grade_system(gradebook, grade_system,
                                                   self.data)

            grade_system = gradebook.get_grade_system(grade_system.ident)

            return gutils.CreatedResponse(grade_system.object_map)
        except (PermissionDenied, InvalidArgument, KeyError) as ex:
            try:
                gradebook.delete_grade_system(grade_system.ident)
            except NameError:
                pass
            gutils.handle_exceptions(ex)
Beispiel #6
0
    def post(self, request, gradebook_id=None, format=None):
        try:
            if gradebook_id is None:
                gutils.verify_keys_present(self.data, ['gradebookId'])
                gradebook_id = self.data['gradebookId']

            gutils.verify_keys_present(self.data, ['gradeSystemId'])

            gradebook = self.gm.get_gradebook(gutils.clean_id(gradebook_id))

            form = gradebook.get_gradebook_column_form_for_create([])

            form = gutils.set_form_basics(form, self.data)

            form.set_grade_system(gutils.clean_id(self.data['gradeSystemId']))

            column = gradebook.create_gradebook_column(form)

            return gutils.CreatedResponse(column.object_map)
        except (PermissionDenied, InvalidArgument, KeyError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #7
0
    def post(self, request, column_id=None, format=None):
        try:
            if column_id is None:
                gutils.verify_keys_present(self.data, ['gradebookColumnId'])
                column_id = self.data['gradebookColumnId']

            gutils.verify_at_least_one_key_present(
                self.data, ['grade', 'score', 'ignoredForCalculations'])
            gutils.verify_keys_present(self.data, ['resourceId'])

            gradebook = grutils.get_object_gradebook(self.gm, column_id,
                                                     'gradebook_column')
            column = gradebook.get_gradebook_column(gutils.clean_id(column_id))

            grutils.validate_score_and_grades_against_system(
                column.get_grade_system(), self.data)

            form = gradebook.get_grade_entry_form_for_create(
                column.ident, gutils.clean_id(self.data['resourceId']), [])

            form = gutils.set_form_basics(form, self.data)

            if 'ignoredForCalculations' in self.data:
                form.set_ignored_for_calculations(
                    bool(self.data['ignoredForCalculations']))

            if 'grade' in self.data:
                form.set_grade(gutils.clean_id(self.data['grade']))

            if 'score' in self.data:
                form.set_score(float(self.data['score']))

            entry = gradebook.create_grade_entry(form)

            return gutils.CreatedResponse(entry.object_map)
        except (PermissionDenied, InvalidArgument, IllegalState,
                KeyError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #8
0
    def post(self, request, format=None):
        """
        Create a new bin, if authorized

        """
        try:
            if 'bankId' not in self.data:
                gutils.verify_keys_present(self.data,
                                           ['displayName', 'description'])
                form = self.gm.get_gradebook_form_for_create([])
                finalize_method = self.gm.create_gradebook
            else:
                gradebook = self.gm.get_gradebook(Id(self.data['bankId']))
                form = self.gm.get_gradebook_form_for_update(gradebook.ident)
                finalize_method = self.gm.update_gradebook

            form = gutils.set_form_basics(form, self.data)

            new_gradebook = gutils.convert_dl_object(finalize_method(form))

            return gutils.CreatedResponse(new_gradebook)
        except (PermissionDenied, InvalidArgument, NotFound, KeyError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #9
0
    def put(self, request, entry_id, format=None):
        try:
            gutils.verify_at_least_one_key_present(self.data, [
                'displayName', 'description', 'grade', 'score',
                'ignoredForCalculations'
            ])

            gradebook = grutils.get_object_gradebook(self.gm, entry_id,
                                                     'grade_entry')
            entry = gradebook.get_grade_entry(gutils.clean_id(entry_id))
            grade_system = entry.get_gradebook_column().get_grade_system()

            grutils.validate_score_and_grades_against_system(
                grade_system, self.data)

            form = gradebook.get_grade_entry_form_for_update(entry.ident)

            form = gutils.set_form_basics(form, self.data)

            if 'grade' in self.data:
                form.set_grade(gutils.clean_id(self.data['grade']))

            if 'score' in self.data:
                form.set_score(float(self.data['score']))

            if 'ignoredForCalculations' in self.data:
                form.set_ignored_for_calculations(
                    bool(self.data['ignoredForCalculations']))

            gradebook.update_grade_entry(form)

            entry = gradebook.get_grade_entry(entry.ident)

            return gutils.UpdatedResponse(entry.object_map)
        except (PermissionDenied, InvalidArgument, KeyError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #10
0
    def put(self, request, gradesystem_id, format=None):
        try:
            gutils.verify_at_least_one_key_present(self.data, [
                'displayName', 'description', 'basedOnGrades', 'grades',
                'highestScore', 'lowestScore', 'scoreIncrement'
            ])

            gradebook = grutils.get_object_gradebook(self.gm, gradesystem_id,
                                                     'grade_system')
            grade_system = gradebook.get_grade_system(
                gutils.clean_id(gradesystem_id))

            if 'basedOnGrades' in self.data:
                # do this first, so methods below work
                form = gradebook.get_grade_system_form_for_update(
                    grade_system.ident)
                form.set_based_on_grades(bool(self.data['basedOnGrades']))

                if self.data['basedOnGrades']:
                    # clear out the numeric score fields
                    form.clear_highest_numeric_score()
                    form.clear_lowest_numeric_score()
                    form.clear_numeric_score_increment()
                else:
                    # clear out grades
                    for grade in grade_system.get_grades():
                        gradebook.delete_grade(grade.ident)

                grade_system = gradebook.update_grade_system(form)

            if (grade_system.is_based_on_grades() and 'grades' in self.data):
                # user wants to update the grades
                # here, wipe out all previous grades and over-write
                grutils.check_grade_inputs(self.data)
                if len(self.data['grades']) > 0:
                    for grade in grade_system.get_grades():
                        gradebook.delete_grade(grade.ident)
                    grutils.add_grades_to_grade_system(gradebook, grade_system,
                                                       self.data)

            score_inputs = ['highestScore', 'lowestScore', 'scoreIncrement']
            if (not grade_system.is_based_on_grades()
                    and any(i in self.data for i in score_inputs)):
                form = gradebook.get_grade_system_form_for_update(
                    grade_system.ident)

                if 'highestScore' in self.data:
                    form.set_highest_numeric_score(
                        float(self.data['highestScore']))

                if 'lowestScore' in self.data:
                    form.set_lowest_numeric_score(
                        float(self.data['lowestScore']))

                if 'scoreIncrement' in self.data:
                    form.set_numeric_score_increment(
                        float(self.data['scoreIncrement']))

                gradebook.update_grade_system(form)

            if 'name' in self.data or 'description' in self.data:
                form = gradebook.get_grade_system_form_for_update(
                    grade_system.ident)

                form = gutils.set_form_basics(form, self.data)

                gradebook.update_grade_system(form)

            grade_system = gradebook.get_grade_system(grade_system.ident)

            return gutils.UpdatedResponse(grade_system.object_map)
        except (PermissionDenied, InvalidArgument, KeyError) as ex:
            gutils.handle_exceptions(ex)
Beispiel #11
0
    def put(self, request, item_id, format=None):
        try:
            bank = autils.get_object_bank(self.am,
                                          item_id,
                                          object_type='item',
                                          bank_id=None)

            if any(attr in self.data for attr in [
                    'displayName', 'description', 'learningObjectiveIds',
                    'attempts', 'markdown', 'rerandomize', 'showanswer',
                    'weight', 'difficulty', 'discrimination'
            ]):
                form = bank.get_item_form_for_update(gutils.clean_id(item_id))

                form = gutils.set_form_basics(form, self.data)

                if 'learningObjectiveIds' in self.data:
                    form = autils.set_item_learning_objectives(self.data, form)

                # update the item before the questions / answers,
                # because otherwise the old form will over-write the
                # new question / answer data

                # for edX items, update any metadata passed in
                if 'genusTypeId' not in self.data:
                    if len(form._my_map['recordTypeIds']) > 0:
                        self.data['type'] = form._my_map['recordTypeIds'][0]
                    else:
                        self.data['type'] = ''

                form = autils.update_item_metadata(self.data, form)

                updated_item = bank.update_item(form)
            else:
                updated_item = bank.get_item(gutils.clean_id(item_id))

            if 'question' in self.data:
                question = self.data['question']
                existing_question = updated_item.get_question()
                q_id = existing_question.ident

                if 'genusTypeId' not in question:
                    question['genusTypeId'] = existing_question.object_map[
                        'recordTypeIds'][0]

                qfu = bank.get_question_form_for_update(q_id)
                qfu = autils.update_question_form(request, question, qfu)
                updated_question = bank.update_question(qfu)

            if 'answers' in self.data:
                for answer in self.data['answers']:
                    if 'id' in answer:
                        a_id = gutils.clean_id(answer['id'])
                        afu = bank.get_answer_form_for_update(a_id)
                        afu = autils.update_answer_form(answer, afu)
                        bank.update_answer(afu)
                    else:
                        a_types = autils.get_answer_records(answer)
                        afc = bank.get_answer_form_for_create(
                            gutils.clean_id(item_id), a_types)
                        afc = autils.set_answer_form_genus_and_feedback(
                            answer, afc)
                        if 'multi-choice' in answer['genusTypeId']:
                            # because multiple choice answers need to match to
                            # the actual MC3 ChoiceIds, NOT the index passed
                            # in by the consumer.
                            question = updated_item.get_question()
                            afc = autils.update_answer_form(
                                answer, afc, question)
                        else:
                            afc = autils.update_answer_form(answer, afc)
                        bank.create_answer(afc)

            full_item = bank.get_item(gutils.clean_id(item_id))

            data = gutils.convert_dl_object(full_item)
            return gutils.UpdatedResponse(data)
        except (PermissionDenied, Unsupported, InvalidArgument) as ex:
            gutils.handle_exceptions(ex)