Beispiel #1
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 #2
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 #3
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 #4
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 #5
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 #6
0
    def post(self, request, bank_id=None, format=None):
        try:
            if bank_id is None:
                expected = ['bankId']
                gutils.verify_keys_present(self.data, expected)
                bank_id = self.data['bankId']

            bank = self.am.get_bank(gutils.clean_id(bank_id))
            new_item = autils.create_new_item(bank, self.data)
            # create questions and answers if they are part of the
            # input data. There must be a better way to figure out
            # which attributes I should set, given the
            # question type?
            if 'question' in self.data:
                question = self.data['question']
                if isinstance(question, basestring):
                    question = json.loads(question)
                q_type = Type(question['type'])
                qfc = bank.get_question_form_for_create(
                    item_id=new_item.ident, question_record_types=[q_type])
                qfc = autils.update_question_form(request,
                                                  question,
                                                  qfc,
                                                  create=True)

                if 'genus' in question:
                    qfc.genus_type = Type(question['genus'])

                if ('fileIds' in new_item.object_map
                        and len(new_item.object_map['fileIds'].keys()) > 0):
                    # add these files to the question, too
                    file_ids = new_item.object_map['fileIds']
                    qfc = autils.add_file_ids_to_form(qfc, file_ids)

                new_question = bank.create_question(qfc)

            if 'answers' in self.data:
                answers = self.data['answers']
                if isinstance(answers, basestring):
                    answers = json.loads(answers)
                for answer in answers:
                    a_types = autils.get_answer_records(answer)

                    afc = bank.get_answer_form_for_create(
                        new_item.ident, a_types)

                    if 'multi-choice' in answer['type']:
                        # because multiple choice answers need to match to
                        # the actual MC3 ChoiceIds, NOT the index passed
                        # in by the consumer.
                        if not new_question:
                            raise NullArgument('Question')
                        afc = autils.update_answer_form(
                            answer, afc, new_question)
                    else:
                        afc = autils.update_answer_form(answer, afc)

                    afc = autils.set_answer_form_genus_and_feedback(
                        answer, afc)
                    new_answer = bank.create_answer(afc)

            full_item = bank.get_item(new_item.ident)
            data = gutils.convert_dl_object(full_item)
            return gutils.CreatedResponse(data)
        except (KeyError, IntegrityError, PermissionDenied, Unsupported,
                InvalidArgument, NullArgument) as ex:
            gutils.handle_exceptions(ex)