from django.conf.urls import url
from rest_framework import generics, versioning

from snippets.models import Snippet
from snippets.serializers import SnippetSerializer


class SnippetList(generics.ListCreateAPIView):
    """SnippetList classdoc"""
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer
    versioning_class = versioning.NamespaceVersioning

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

    def post(self, request, *args, **kwargs):
        """post method docstring"""
        return super(SnippetList, self).post(request, *args, **kwargs)


app_name = 'test_ns_versioning'

urlpatterns = [
    url(r"^$", SnippetList.as_view())
]
