Skip to content

Commit a46f82b

Browse files
author
Emmanouil Konstantinidis
committed
Setup Urls and sample view
1 parent 2629c02 commit a46f82b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

tests/urls.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
from django.conf.urls import include, url
22
from django.contrib import admin
3+
from tests import views
4+
5+
accounts_urls = [
6+
url(r'^login/$', views.LoginView.as_view(), name="login"),
7+
]
8+
9+
organisations_urls = [
10+
11+
]
312

413
urlpatterns = [
514
url(r'^admin/', include(admin.site.urls)),
615
url(r'^docs/', include('rest_framework_docs.urls')),
716

817
# API
9-
# url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts')),
10-
# url(r'^organisations/', view=include('project.organisations.urls', namespace='organisations')),
18+
url(r'^accounts/', view=include(accounts_urls, namespace='accounts')),
19+
url(r'^organisations/', view=include(organisations_urls, namespace='organisations')),
1120
]

tests/views.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from django.views.generic.base import TemplateView
2+
from rest_framework import parsers, renderers
3+
from rest_framework.authtoken.models import Token
4+
from rest_framework.authtoken.serializers import AuthTokenSerializer
5+
from rest_framework.response import Response
6+
from rest_framework.views import APIView
7+
8+
9+
class TestView(TemplateView):
10+
"""
11+
This view should not be included in DRF Docs.
12+
"""
13+
template_name = "a_test.html"
14+
15+
16+
class LoginView(APIView):
17+
18+
throttle_classes = ()
19+
permission_classes = ()
20+
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
21+
renderer_classes = (renderers.JSONRenderer,)
22+
serializer_class = AuthTokenSerializer
23+
24+
def post(self, request):
25+
serializer = self.serializer_class(data=request.data)
26+
serializer.is_valid(raise_exception=True)
27+
user = serializer.validated_data['user']
28+
token, created = Token.objects.get_or_create(user=user)
29+
return Response({'token': token.key})

0 commit comments

Comments
 (0)