Exemplo n.º 1
0
    def search(self):
        """Return the list of form search resources matching the input JSON query.

        :URL: ``SEARCH /formsearches`` (or ``POST /formsearches/search``)
        :request body: A JSON object of the form::

                {"query": {"filter": [ ... ], "order_by": [ ... ]},
                 "paginator": { ... }}

            where the ``order_by`` and ``paginator`` attributes are optional.

        .. note::
        
            Yes, that's right, you can search form searches.  (No, you can't
            search searches of form searches :)

        """
        try:
            json_search_params = unicode(request.body, request.charset)
            python_search_params = json.loads(json_search_params)
            query = h.eagerload_form_search(
                self.query_builder.get_SQLA_query(python_search_params.get('query')))
            return h.add_pagination(query, python_search_params.get('paginator'))
        except h.JSONDecodeError:
            response.status_int = 400
            return h.JSONDecodeErrorResponse
        except (OLDSearchParseError, Invalid), e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Exemplo n.º 2
0
    def update(self, id):
        """Update a form search and return it.
        
        :URL: ``PUT /formsearches/id``
        :Request body: JSON object representing the form search with updated
            attribute values.
        :param str id: the ``id`` value of the form search to be updated.
        :returns: the updated form search model.

        """
        form_search = h.eagerload_form_search(Session.query(FormSearch)).get(int(id))
        if form_search:
            try:
                schema = FormSearchSchema()
                values = json.loads(unicode(request.body, request.charset))
                state = h.get_state_object(values)
                state.id = id
                state.config = config
                data = schema.to_python(values, state)
                form_search = update_form_search(form_search, data)
                # form_search will be False if there are no changes (cf. update_form_search).
                if form_search:
                    Session.add(form_search)
                    Session.commit()
                    return form_search
                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()}
Exemplo n.º 3
0
    def edit(self, id):
        """GET /formsearches/id/edit: Return the data necessary to update an existing
        OLD form search.
        """
        """Return a form search and the data needed to update it.

        :URL: ``GET /formsearches/edit`` with optional query string parameters 
        :param str id: the ``id`` value of the form search that will be updated.
        :returns: a dictionary of the form::

                {"form_search": {...}, "data": {...}}

            where the value of the ``form_search`` key is a dictionary
            representation of the form search and the value of the ``data`` key
            is a dictionary containing the data necessary to update a form
            search.

        """
        form_search = h.eagerload_form_search(Session.query(FormSearch)).get(id)
        if form_search:
            data = {'search_parameters': h.get_search_parameters(self.query_builder)}
            return {'data': data, 'form_search': form_search}
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 4
0
    def search(self):
        """Return the list of form search resources matching the input JSON query.

        :URL: ``SEARCH /formsearches`` (or ``POST /formsearches/search``)
        :request body: A JSON object of the form::

                {"query": {"filter": [ ... ], "order_by": [ ... ]},
                 "paginator": { ... }}

            where the ``order_by`` and ``paginator`` attributes are optional.

        .. note::
        
            Yes, that's right, you can search form searches.  (No, you can't
            search searches of form searches :)

        """
        try:
            json_search_params = unicode(request.body, request.charset)
            python_search_params = json.loads(json_search_params)
            query = h.eagerload_form_search(
                self.query_builder.get_SQLA_query(
                    python_search_params.get('query')))
            return h.add_pagination(query,
                                    python_search_params.get('paginator'))
        except h.JSONDecodeError:
            response.status_int = 400
            return h.JSONDecodeErrorResponse
        except (OLDSearchParseError, Invalid), e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Exemplo n.º 5
0
    def edit(self, id):
        """GET /formsearches/id/edit: Return the data necessary to update an existing
        OLD form search.
        """
        """Return a form search and the data needed to update it.

        :URL: ``GET /formsearches/edit`` with optional query string parameters 
        :param str id: the ``id`` value of the form search that will be updated.
        :returns: a dictionary of the form::

                {"form_search": {...}, "data": {...}}

            where the value of the ``form_search`` key is a dictionary
            representation of the form search and the value of the ``data`` key
            is a dictionary containing the data necessary to update a form
            search.

        """
        form_search = h.eagerload_form_search(
            Session.query(FormSearch)).get(id)
        if form_search:
            data = {
                'search_parameters':
                h.get_search_parameters(self.query_builder)
            }
            return {'data': data, 'form_search': form_search}
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 6
0
    def show(self, id):
        """Return a form search.

        :URL: ``GET /formsearches/id``
        :param str id: the ``id`` value of the form search to be returned.
        :returns: a form search model object.

        """
        form_search = h.eagerload_form_search(Session.query(FormSearch)).get(id)
        if form_search:
            return form_search
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 7
0
    def show(self, id):
        """Return a form search.

        :URL: ``GET /formsearches/id``
        :param str id: the ``id`` value of the form search to be returned.
        :returns: a form search model object.

        """
        form_search = h.eagerload_form_search(
            Session.query(FormSearch)).get(id)
        if form_search:
            return form_search
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 8
0
    def delete(self, id):
        """Delete an existing form search and return it.

        :URL: ``DELETE /formsearches/id``
        :param str id: the ``id`` value of the form search to be deleted.
        :returns: the deleted form search model.

        """

        form_search = h.eagerload_form_search(Session.query(FormSearch)).get(id)
        if form_search:
            Session.delete(form_search)
            Session.commit()
            return form_search
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 9
0
    def delete(self, id):
        """Delete an existing form search and return it.

        :URL: ``DELETE /formsearches/id``
        :param str id: the ``id`` value of the form search to be deleted.
        :returns: the deleted form search model.

        """

        form_search = h.eagerload_form_search(
            Session.query(FormSearch)).get(id)
        if form_search:
            Session.delete(form_search)
            Session.commit()
            return form_search
        else:
            response.status_int = 404
            return {'error': 'There is no form search with id %s' % id}
Exemplo n.º 10
0
    def index(self):
        """Get all form search resources.

        :URL: ``GET /formsearches`` with optional query string parameters for
            ordering and pagination.
        :returns: a list of all form search resources.

        .. note::

           See :func:`utils.add_order_by` and :func:`utils.add_pagination` for the
           query string parameters that effect ordering and pagination.

        """
        try:
            query = h.eagerload_form_search(Session.query(FormSearch))
            query = h.add_order_by(query, dict(request.GET), self.query_builder)
            return h.add_pagination(query, dict(request.GET))
        except Invalid, e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Exemplo n.º 11
0
    def index(self):
        """Get all form search resources.

        :URL: ``GET /formsearches`` with optional query string parameters for
            ordering and pagination.
        :returns: a list of all form search resources.

        .. note::

           See :func:`utils.add_order_by` and :func:`utils.add_pagination` for the
           query string parameters that effect ordering and pagination.

        """
        try:
            query = h.eagerload_form_search(Session.query(FormSearch))
            query = h.add_order_by(query, dict(request.GET),
                                   self.query_builder)
            return h.add_pagination(query, dict(request.GET))
        except Invalid, e:
            response.status_int = 400
            return {'errors': e.unpack_errors()}
Exemplo n.º 12
0
    def update(self, id):
        """Update a form search and return it.
        
        :URL: ``PUT /formsearches/id``
        :Request body: JSON object representing the form search with updated
            attribute values.
        :param str id: the ``id`` value of the form search to be updated.
        :returns: the updated form search model.

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