diff --git a/atdb/atdb/settings/base.py b/atdb/atdb/settings/base.py index e5329724880fb6fdcae523734c9d0ab0b5018857..c8fe98fd707693532465a4dc3a5c21bd70a99cd2 100644 --- a/atdb/atdb/settings/base.py +++ b/atdb/atdb/settings/base.py @@ -24,6 +24,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'rest_framework.authtoken', 'corsheaders', 'django_filters', 'django_extensions', @@ -72,6 +73,9 @@ REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' ], + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework.authentication.TokenAuthentication', + ], 'DEFAULT_FILTER_BACKENDS': ( 'django_filters.rest_framework.DjangoFilterBackend', ), diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index c4d19f0288ae20daef5b0a009672d741eb6100f7..2fa718cc3b3e9118e47107b0897da417387af04d 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 1.0.0 (11 feb 2021 - 15:00) + <p class="footer"> Version 1.0.0 (4 mar 2021 - 11:00) </div> diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py index e881851e89c2b92ba3ed002227e868a85eccac56..744fa7e2d29dffe8bf3d935ada373a356e5c46cc 100644 --- a/atdb/taskdatabase/urls.py +++ b/atdb/taskdatabase/urls.py @@ -92,4 +92,6 @@ urlpatterns = [ path('tasks/<int:pk>/hold/<hold_it>/<page>', views.Hold, name='task-hold-resume'), path('tasks/<int:pk>/hold/<hold_it>', views.Hold, name='task-hold-resume'), path('tasks/<int:pk>/query-hold/<hold_it>/<query_params>', views.HoldQuery, name='query-hold-resume'), + + path('hello/', views.HelloView.as_view(), name='hello'), ] diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py index 3161ae9e708470e1584c6d2c93f713c4cd6b210b..37456f44e39dfc305fb18cfb8cf17d593cca9d53 100644 --- a/atdb/taskdatabase/views.py +++ b/atdb/taskdatabase/views.py @@ -10,6 +10,9 @@ from django.http import QueryDict from rest_framework import generics, pagination from rest_framework.response import Response +from rest_framework.views import APIView +from rest_framework.response import Response +from rest_framework.permissions import IsAuthenticated import django_filters from django_filters import rest_framework as filters @@ -522,7 +525,6 @@ class TaskListViewAPI(generics.ListCreateAPIView): """ model = Task queryset = Task.objects.all().order_by('-priority', 'id') - # serializer_class = TaskSerializer # using the Django Filter Backend - https://django-filter.readthedocs.io/en/latest/index.html filter_backends = (filters.DjangoFilterBackend,) @@ -1004,3 +1006,13 @@ class GetUniqueValuesForKey(generics.ListAPIView): return Response({ 'error': str(error) }) + +# 4 mar 2022 +# this is a test class to test token authentication +# can be removed if it all also works in production +class HelloView(APIView): + permission_classes = (IsAuthenticated,) + queryset = Task.objects.all() + def get(self, request): + content = {'message': 'Hello, World!'} + return Response(content) \ No newline at end of file