示例#1
0
文件: views.py 项目: mitsei/producer
    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 = gutils.convert_dl_object(item)

            gutils.update_links(request, data)

            if 'fileIds' in data and bool(data['fileIds']):
                data['files'] = item.get_files()
            if data['question'] and 'fileIds' in data['question'] and bool(
                    data['question']['fileIds']):
                data['question']['files'] = item.get_question().get_files()

            try:
                if 'renderable_edxml' in self.data:
                    data['texts']['edxml'] = item.get_edxml_with_aws_urls()
            except AttributeError:
                pass

            return Response(data)
        except (PermissionDenied, NotFound) as ex:
            gutils.handle_exceptions(ex)
示例#2
0
文件: views.py 项目: mitsei/producer
 def get(self, request, gradebook_id, format=None):
     try:
         gradebook = self.gm.get_gradebook(gutils.clean_id(gradebook_id))
         gradebook = gutils.convert_dl_object(gradebook)
         gutils.update_links(request, gradebook)
         return Response(gradebook)
     except (PermissionDenied, InvalidId, NotFound) as ex:
         gutils.handle_exceptions(ex)
示例#3
0
文件: views.py 项目: mitsei/producer
 def get(self, request, bank_id, format=None):
     try:
         assessment_bank = self.am.get_bank(gutils.clean_id(bank_id))
         bank = gutils.convert_dl_object(assessment_bank)
         gutils.update_links(request, bank)
         return Response(bank)
     except (PermissionDenied, NotFound) as ex:
         gutils.handle_exceptions(ex)
示例#4
0
文件: views.py 项目: mitsei/producer
    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)
示例#5
0
    def get(self, request, objective_id, format=None):
        try:
            ols = self.lm._instantiate_session(
                method_name='get_objective_lookup_session',
                proxy=self.lm._proxy)
            objective = ols.get_objective(gutils.clean_id(objective_id))

            data = gutils.convert_dl_object(objective)

            gutils.update_links(request, data)

            return Response(data)
        except (PermissionDenied, NotFound) as ex:
            gutils.handle_exceptions(ex)
示例#6
0
文件: views.py 项目: mitsei/producer
    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)
示例#7
0
文件: views.py 项目: mitsei/producer
    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)
示例#8
0
文件: views.py 项目: mitsei/producer
    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)
示例#9
0
文件: views.py 项目: mitsei/producer
    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)
示例#10
0
文件: views.py 项目: mitsei/producer
    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)