How to use the cornice.resource.view function in cornice

To help you get started, we’ve selected a few cornice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cornices / cornice / tests / test_resource_callable.py View on Github external
    @view(renderer='json', accept=_accept)
    def get(self):
        return FRUITS.get(int(self.request.matchdict['id']))
github Cornices / cornice / tests / test_resource.py View on Github external
    @view(renderer='json', accept='text/json')
    def collection_post(self):
        return {'test': 'yeah'}
github NOAA-ORR-ERD / PyGnome / web / gnome / webgnome / webgnome / views / services / model.py View on Github external
    @view()
    def collection_post(self):
        """
        Create a new model with default settings.
        """
        model = self.settings.Model.create()
        self.request.session[self.settings['model_session_key']] = model.id

        return schema.ModelSchema().bind().serialize(model.to_dict())
github NOAA-ORR-ERD / PyGnome / web / gnome / webgnome / webgnome / views / services / movers.py View on Github external
    @view(validators=util.valid_model_id,
          schema=schema.RandomMoverSchema)
    def collection_post(self):
        """
        Create a :class:`model_manager.WebRandomMover` from a JSON
        representation.
        """
        data = self.request.validated
        model = data.pop('model')
        mover = WebRandomMover(**data)
        model.movers.add(mover)

        mover_data = mover.to_dict(do='create')
        return schema.RandomMoverSchema().bind().serialize(mover_data)
github makinacorpus / ODE / ode / resources / event.py View on Github external
    @view(validators=[has_provider_id], schema=EventCollectionSchema,
          content_type=CONTENT_TYPES)
    def put(self):
        return ResourceMixin.put(self)
github NOAA-ORR-ERD / PyGnome / web / gnome / webgnome / webgnome / views / services / schema_validation.py View on Github external
def __new__(mcs, name, bases, dct):
        schema = dct.get('schema')
        validators = dct.get('validators', {})

        for method in ('post', 'put'):
            if method in dct:
                continue
            try:
                _validators = validators.get(method, None)
            except AttributeError:
                _validators = validators

            view_fn = lambda request: {'valid': True}

            if _validators:
                _view = view(schema=schema, validators=_validators)(view_fn)
            else:
                _view = view(schema=schema)(view_fn)

            dct[method] = _view

        return super(ResourceValidatorMetaclass, mcs).__new__(
            mcs, name, bases, dct)
github berlin-open-wireless-lab / OpenWifiCore / openwifi / restAPI.py View on Github external
    @view(permission = 'node_access')
    def delete(self):
        openwrt = get_node_by_request(self.request)
        if openwrt:
            DBSession.delete(openwrt)
            return True
        else:
            return False
github Kinto / kinto / readinglist / views / article.py View on Github external
    @resource.view(permission='readwrite')
    def collection_post(self, *args, **kwargs):
        try:
            return super(Article, self).collection_post(*args, **kwargs)
        except httpexceptions.HTTPConflict as e:
            self.request.response.status_code = 200
            return e.existing
github openprocurement / openprocurement.api / src / openprocurement / api / views.py View on Github external
    @view(renderer='json')
    def collection_get(self):
        """Tenders List

        Get Tenders List
        ----------------

        Example request to get tenders list:

        .. sourcecode:: http

            GET /tenders HTTP/1.1
            Host: example.com
            Accept: application/json

        This is what one should expect in response:
github universalcore / unicore-cms / cms / api / page.py View on Github external
    @view(renderer='json')
    def get(self):
        models = self.get_repo_models()

        uuid = self.request.matchdict['uuid']

        try:
            page = models.GitPageModel.get(uuid)
            return page.to_dict()
        except DoesNotExist:
            self.request.errors.add('api', 'DoesNotExist', 'Page not found.')
            return