Skip to content

Commit

Permalink
Merge branch 'documentation'
Browse files Browse the repository at this point in the history
  • Loading branch information
PRITAM CHAKRABORTY committed Mar 5, 2022
2 parents c1b211e + fc4a680 commit 18d8dcc
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gunicorn = "*"
dj-database-url = "*"
psycopg2 = "*"
termcolor = "*"
drf-yasg = "*"

[dev-packages]
autopep8 = "*"
Expand Down
79 changes: 75 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions blogapp/swagger_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from drf_yasg.inspectors import SwaggerAutoSchema


class CustomAutoSchema(SwaggerAutoSchema):

def get_tags(self, operation_keys=None):
tags = self.overrides.get('tags', None) or getattr(
self.view, 'my_tags', [])
if not tags:
tags = [operation_keys[0]]

return tags
1 change: 0 additions & 1 deletion blogapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# all_blogger_blogs.register('blogs', OwnerBlogListVSet, 'blogs')



comment_router = NestedDefaultRouter(all_blogger_blogs, 'blog', lookup='blog')
comment_router.register('comments', CommentVSet, basename='comments')

Expand Down
8 changes: 8 additions & 0 deletions blogapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@


class BloggerViewSet(ModelViewSet):
""" Blogger can retrive own details as well as others detail, but can only perform update,delete for own
list:
to get all bloggers
"""
http_method_names = ["get", "patch", "delete", "head", "options"]
filter_backends = [
DjangoFilterBackend,
Expand All @@ -42,6 +46,7 @@ class BloggerViewSet(ModelViewSet):
permission_classes = [IsAdminUser | (IsAuthenticated & IsSelf)]
queryset = Blogger.objects.all()
serializer_class = BloggerAdminSerializer
my_tags = ["Blogger"]

def get_permissions(self):
method = self.request.method
Expand All @@ -67,6 +72,7 @@ class OwnBlogViewSet(ModelViewSet):
ordering_fields = ["title", "created_at"]
serializer_class = BlogReadSerializer
permission_classes = [IsAdminUser | (IsAuthenticated & IsBlogOwner)]
my_tags = ["Blogger-Blog"]
# queryset = Blog.objects.prefetch_related(
# 'comments').select_related('creator').all()

Expand Down Expand Up @@ -100,10 +106,12 @@ class AllBlogVSet(ListModelMixin, GenericViewSet):
queryset = Blog.objects.select_related(
'creator').prefetch_related('comments').all()
serializer_class = BlogReadSerializer
my_tags = ["All Blogs"]


class CommentVSet(ModelViewSet):
http_method_names = ["get", "post", "patch", "delete", "option", "head"]
my_tags = ["Blog-Comments"]

def get_permissions(self):
if self.request.method == 'GET':
Expand Down
16 changes: 15 additions & 1 deletion core/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
# 3rd party apps
# 'django.contrib.staticfiles', # required for serving swagger ui's css/js files
'drf_yasg',
# "debug_toolbar",
'rest_framework',
'djoser',
Expand Down Expand Up @@ -60,6 +62,16 @@

ROOT_URLCONF = 'core.urls'


SWAGGER_SETTINGS = {
"DEFAULT_AUTO_SCHEMA_CLASS": "blogapp.swagger_schema.CustomAutoSchema",
"LOGIN_URL": 'admin/',
"LOGOUT_URL":'admin/logout',
"OPERATIONS_SORTER":'method',
"TAGS_SORTER":'alpha',
"DOC_EXPANSION":"none",
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down Expand Up @@ -130,7 +142,9 @@
),
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
]
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 5,
}

SIMPLE_JWT = {
Expand Down
32 changes: 30 additions & 2 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,49 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings ,urls
from django.conf import settings, urls
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static

# DRF_YASG
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi


schema_view = get_schema_view(
openapi.Info(
title="Blogapp API",
default_version='v1',
description="""
# This is the `Blogapp API` documentation
> ### Here all the api routes are grouped by tags
""",
# terms_of_service="https://www.google.com/policies/terms/",
# contact=openapi.Contact(email="pritam.chk98@gmail.com"),
# license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
)
# DRF_YASG


urlpatterns = [
path('admin/', admin.site.urls),
path('auth/', include('djoser.urls')),
path('auth/', include('djoser.urls.jwt')),
# path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# own app routes
path('blogapp/', include("blogapp.urls")),
#FIXME: drf_yasg url
path('', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
]
# urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
import debug_toolbar
urlpatterns+=path("__debug__/", include(debug_toolbar.urls)),
urlpatterns += path("__debug__/", include(debug_toolbar.urls)),

0 comments on commit 18d8dcc

Please sign in to comment.