Пример #1
0
    def update(self, id):
        """Update a morphological parser and return it.

        :URL: ``PUT /morphologicalparsers/id``
        :Request body: JSON object representing the morphological parser with updated attribute values.
        :param str id: the ``id`` value of the morphological parser to be updated.
        :returns: the updated morphological parser model.

        """
        morphological_parser = h.eagerload_morphological_parser(Session.query(MorphologicalParser)).get(int(id))
        if morphological_parser:
            try:
                schema = MorphologicalParserSchema()
                values = json.loads(unicode(request.body, request.charset))
                state = h.get_state_object(values)
                state.id = id
                data = schema.to_python(values, state)
                morphological_parser_dict = morphological_parser.get_dict()
                morphological_parser = update_morphological_parser(morphological_parser, data)
                # morphological_parser will be False if there are no changes (cf. update_morphological_parser).
                if morphological_parser:
                    backup_morphological_parser(morphological_parser_dict)
                    Session.add(morphological_parser)
                    Session.commit()
                    return morphological_parser
                else:
                    response.status_int = 400
                    return {'error': u'The update request failed because the submitted data were not new.'}
            except h.JSONDecodeError:
                response.status_int = 400
                return h.JSONDecodeErrorResponse
            except Invalid, e:
                response.status_int = 400
                return {'errors': e.unpack_errors()}
Пример #2
0
    def update(self, id):
        """Update a morphological parser and return it.

        :URL: ``PUT /morphologicalparsers/id``
        :Request body: JSON object representing the morphological parser with updated attribute values.
        :param str id: the ``id`` value of the morphological parser to be updated.
        :returns: the updated morphological parser model.

        """
        morphological_parser = h.eagerload_morphological_parser(
            Session.query(MorphologicalParser)).get(int(id))
        if morphological_parser:
            try:
                schema = MorphologicalParserSchema()
                values = json.loads(unicode(request.body, request.charset))
                state = h.get_state_object(values)
                state.id = id
                data = schema.to_python(values, state)
                morphological_parser_dict = morphological_parser.get_dict()
                morphological_parser = update_morphological_parser(
                    morphological_parser, data)
                # morphological_parser will be False if there are no changes (cf. update_morphological_parser).
                if morphological_parser:
                    backup_morphological_parser(morphological_parser_dict)
                    Session.add(morphological_parser)
                    Session.commit()
                    return morphological_parser
                else:
                    response.status_int = 400
                    return {
                        'error':
                        u'The update request failed because the submitted data were not new.'
                    }
            except h.JSONDecodeError:
                response.status_int = 400
                return h.JSONDecodeErrorResponse
            except Invalid, e:
                response.status_int = 400
                return {'errors': e.unpack_errors()}
Пример #3
0
    def create(self):
        """Create a new morphological parser resource and return it.

        :URL: ``POST /morphologicalparsers``
        :request body: JSON object representing the morphological parser to create.
        :returns: the newly created morphological parser.

        """
        try:
            schema = MorphologicalParserSchema()
            values = json.loads(unicode(request.body, request.charset))
            data = schema.to_python(values)
            parser = create_new_morphological_parser(data)
            Session.add(parser)
            Session.commit()
            parser.make_directory_safely(parser.directory)
            return parser
        except h.JSONDecodeError:
            response.status_int = 400
            return h.JSONDecodeErrorResponse
        except Invalid, e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Пример #4
0
    def create(self):
        """Create a new morphological parser resource and return it.

        :URL: ``POST /morphologicalparsers``
        :request body: JSON object representing the morphological parser to create.
        :returns: the newly created morphological parser.

        """
        try:
            schema = MorphologicalParserSchema()
            values = json.loads(unicode(request.body, request.charset))
            data = schema.to_python(values)
            parser = create_new_morphological_parser(data)
            Session.add(parser)
            Session.commit()
            parser.make_directory_safely(parser.directory)
            return parser
        except h.JSONDecodeError:
            response.status_int = 400
            return h.JSONDecodeErrorResponse
        except Invalid, e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}