Skip to content

Latest commit

 

History

History
65 lines (39 loc) · 1.49 KB

viewsets.rst

File metadata and controls

65 lines (39 loc) · 1.49 KB

Viewsets

Kinto-Core maps URLs, endpoints and permissions to resources using ViewSets.

Since a resource defines two URLs with several HTTP methods, a view set can be considered as a set of rules for registring the resource views into the routing mechanism of Pyramid.

To use Kinto-Core in a basic fashion, there is no need to understand how viewsets work in full detail.

Override defaults

Viewsets defaults can be overriden by passing arguments to the kinto.core.resource.register class decorator:

from kinto.core import resource


@resource.register(collection_methods=('GET',))
class Resource(resource.UserResource):
    mapping = BookmarkSchema()

Subclassing

In case this isn't enough, the kinto.core.resource.viewset.ViewSet class can be subclassed and specified during registration:

from kinto.core import resource


class NoSchemaViewSet(resource.ViewSet):

    def get_record_schema(self, resource_cls, method):
        simple_mapping = colander.MappingSchema(unknown='preserve')
        return simple_mapping


@resource.register(viewset=NoSchemaViewSet())
class Resource(resource.UserResource):
    mapping = BookmarkSchema()

ViewSet class

kinto.core.resource.viewset.ViewSet

kinto.core.resource.viewset.ShareableViewSet