Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting views to Async Views #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ awsebcli = "*"
celery = "*"
redis = "*"
flower = "*"
daphne = "*"
pyjwt = "==2.1.0"
whitenoise = "*"

[dev-packages]
pytest = "*"
Expand Down
90 changes: 49 additions & 41 deletions Pipfile.lock

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

2 changes: 1 addition & 1 deletion csvparser/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .views import CsvParserView

urlpatterns = [
path('parse-csv/', CsvParserView.as_view(), name="parse_csv"),
path('parse-csv/', CsvParserView, name="parse_csv"),
]
74 changes: 46 additions & 28 deletions csvparser/views.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
"""
Views for CSV Parsing functionality
"""
from rest_framework import generics, permissions
from rest_framework.decorators import permission_classes
from rest_framework.response import Response
from rest_framework import status
# from rest_framework import generics, permissions
# from rest_framework.decorators import permission_classes
# from rest_framework.response import Response
# from rest_framework import status

from django.http import JsonResponse

from .services import CsvParser

# @permission_classes([permissions.IsAdminUser])
# class CsvParserView(generics.GenericAPIView):
# """
# Views for Csv Parsing
# """

@permission_classes([permissions.IsAdminUser])
class CsvParserView(generics.GenericAPIView):
"""
Views for Csv Parsing
"""
# def post(self, request):
# """
# Actions for posting csv file for parsing
# """
# file = request.data.get('file', '')

def post(self, request):
"""
Actions for posting csv file for parsing
"""
file = request.data.get('file', '')
# if file != '':
# csv_parser = CsvParser(file)
# data = csv_parser.parse_file()
# data_dict = {}
# data_dict['data'] = data
# data_dict['errors'] = csv_parser.error_messages
# return Response(
# data_dict
# )
# else:
# return Response(
# {"error": "You need to upload a CSV file"},
# status=status.HTTP_400_BAD_REQUEST
# )

if file != '':
csv_parser = CsvParser(file)
data = csv_parser.parse_file()
data_dict = {}
data_dict['data'] = data
data_dict['errors'] = csv_parser.error_messages
return Response(
data_dict
)
else:
return Response(
{"error": "You need to upload a CSV file"},
status=status.HTTP_400_BAD_REQUEST
)

async def CsvParserView(request):
if request.method != "POST":
return JsonResponse({"error": "Method Not Allowed"},
status=400)
if 'file' not in request.FILES:
return JsonResponse({"error": "You need to upload a CSV file"},
status=400)
file = request.FILES['file']
csv_parser = CsvParser(file)
data = csv_parser.parse_file()
data_dict = {}
data_dict['data'] = data
data_dict['errors'] = csv_parser.error_messages
return JsonResponse(
data_dict
)
2 changes: 1 addition & 1 deletion haemosupport/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
Expand Down