Example #1
0
    def create(self):
        """Create a new elicitation method resource and return it.

        :URL: ``POST /elicitationmethods``
        :request body: JSON object representing the elicitation method to create.
        :returns: the newly created elicitation method.

        """
        try:
            schema = ElicitationMethodSchema()
            values = json.loads(unicode(request.body, request.charset))
            result = schema.to_python(values)
            elicitation_method = create_new_elicitation_method(result)
            Session.add(elicitation_method)
            Session.commit()
            return elicitation_method
        except h.JSONDecodeError:
            response.status_int = 400
            return h.JSONDecodeErrorResponse
        except Invalid, e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Example #2
0
    def update(self, id):
        """Update an elicitation method and return it.
        
        :URL: ``PUT /elicitationmethods/id``
        :Request body: JSON object representing the elicitation method with updated attribute values.
        :param str id: the ``id`` value of the elicitation method to be updated.
        :returns: the updated elicitation method model.

        """
        elicitation_method = Session.query(ElicitationMethod).get(int(id))
        if elicitation_method:
            try:
                schema = ElicitationMethodSchema()
                values = json.loads(unicode(request.body, request.charset))
                state = h.get_state_object(values)
                state.id = id
                data = schema.to_python(values, state)
                elicitation_method = update_elicitation_method(
                    elicitation_method, data)
                # elicitation_method will be False if there are no changes (cf. update_elicitation_method).
                if elicitation_method:
                    Session.add(elicitation_method)
                    Session.commit()
                    return elicitation_method
                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()}