Skip to content

Commit 5166627

Browse files
committed
comment & validate api_task_manager #22
1 parent abb2fc4 commit 5166627

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

api_task_manager/permissions.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from rest_framework import permissions
22

3-
3+
"""
4+
Only give permission to manage objects to users who own them
5+
"""
46
class IsOwnerOrReadOnly(permissions.BasePermission):
5-
def has_object_permission(self, request, view, obj):
6-
if request.method in permissions.SAFE_METHODS:
7-
return True
8-
return obj.owner == request.user
7+
def has_object_permission(self, request, view, obj):
8+
if request.method in permissions.SAFE_METHODS:
9+
return True
10+
return obj.owner == request.user

api_task_manager/serializers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CurrentUserSerializer(UserDetailsSerializer):
1414

1515
class Meta(UserDetailsSerializer.Meta):
1616
fields = UserDetailsSerializer.Meta.fields + (
17-
'profile_id', 'profile_firstname', 'profile_lastname',
17+
'profile_id', 'profile_firstname', 'profile_lastname',
1818
'profile_image'
19-
)
19+
)
20+

api_task_manager/settings.py

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
# SECURITY WARNING: don't run with debug turned on in production!
7676
DEBUG = True
7777

78+
# get allowe hosts from the environment
7879
ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOST'),]
7980

8081
# allowed frontend apps
@@ -157,13 +158,16 @@
157158
# Database
158159
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
159160

161+
162+
# use the built-in SQLite database in development
160163
if 'DEV' in os.environ:
161164
DATABASES = {
162165
'default': {
163166
'ENGINE': 'django.db.backends.sqlite3',
164167
'NAME': BASE_DIR / 'db.sqlite3',
165168
}
166169
}
170+
# use the database specified in the environment in production
167171
else:
168172
DATABASES = {
169173
'default': dj_database_url.parse(os.environ.get("DATABASE_URL"))

api_task_manager/urls.py

-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
33
The `urlpatterns` list routes URLs to views. For more information please see:
44
https://docs.djangoproject.com/en/3.2/topics/http/urls/
5-
Examples:
6-
Function views
7-
1. Add an import: from my_app import views
8-
2. Add a URL to urlpatterns: path('', views.home, name='home')
9-
Class-based views
10-
1. Add an import: from other_app.views import Home
11-
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12-
Including another URLconf
13-
1. Import the include() function: from django.urls import include, path
14-
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
155
"""
166
from django.contrib import admin
177
from django.urls import path, include

api_task_manager/views.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
)
77

88

9+
# Welcome message by the APi when viewed in the browser or called from the FE
910
@api_view()
1011
def root_route(request):
1112
return Response({
1213
"message": "Welcome to the Task Manager API!"
1314
})
1415

15-
# dj-rest-auth logout view fix
16+
17+
# Fix know dj-rest-auth logout view issue by defining a custom view
1618
@api_view(['POST'])
1719
def logout_route(request):
1820
response = Response()
@@ -34,4 +36,4 @@ def logout_route(request):
3436
samesite=JWT_AUTH_SAMESITE,
3537
secure=JWT_AUTH_SECURE,
3638
)
37-
return response
39+
return response

0 commit comments

Comments
 (0)