Fix JSON import, fix request data access inside Class Views
This commit is contained in:
parent
e50f6085cd
commit
2539be4558
6 changed files with 49 additions and 23 deletions
|
|
@ -11,16 +11,30 @@ from rest_framework.views import APIView
|
|||
|
||||
from accounts import swagger_params
|
||||
from accounts.models import Account, Tags
|
||||
from accounts.serializer import (AccountCreateSerializer, AccountSerializer,
|
||||
EmailSerializer, TagsSerailizer)
|
||||
from accounts.serializer import (
|
||||
AccountCreateSerializer,
|
||||
AccountSerializer,
|
||||
EmailSerializer,
|
||||
TagsSerailizer,
|
||||
)
|
||||
from accounts.tasks import send_email, send_email_to_assigned_user
|
||||
from cases.serializer import CaseSerializer
|
||||
from common.models import Attachments, Comment, Profile
|
||||
|
||||
# from common.custom_auth import JSONWebTokenAuthentication
|
||||
from common.serializer import (AttachmentsSerializer, CommentSerializer,
|
||||
ProfileSerializer)
|
||||
from common.utils import (CASE_TYPE, COUNTRIES, CURRENCY_CODES, INDCHOICES,
|
||||
PRIORITY_CHOICE, STATUS_CHOICE)
|
||||
from common.serializer import (
|
||||
AttachmentsSerializer,
|
||||
CommentSerializer,
|
||||
ProfileSerializer,
|
||||
)
|
||||
from common.utils import (
|
||||
CASE_TYPE,
|
||||
COUNTRIES,
|
||||
CURRENCY_CODES,
|
||||
INDCHOICES,
|
||||
PRIORITY_CHOICE,
|
||||
STATUS_CHOICE,
|
||||
)
|
||||
from contacts.models import Contact
|
||||
from contacts.serializer import ContactSerializer
|
||||
from invoices.serializer import InvoiceSerailizer
|
||||
|
|
@ -31,13 +45,12 @@ from teams.models import Teams
|
|||
|
||||
|
||||
class AccountsListView(APIView, LimitOffsetPagination):
|
||||
|
||||
# authentication_classes = (JSONWebTokenAuthentication,)
|
||||
permission_classes = (IsAuthenticated,)
|
||||
model = Account
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
params = request.post_data
|
||||
params = self.request.post_data
|
||||
queryset = self.model.objects.filter(org=self.request.org).order_by("-id")
|
||||
if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
|
||||
queryset = queryset.filter(
|
||||
|
|
@ -545,7 +558,6 @@ class AccountAttachmentView(APIView):
|
|||
|
||||
|
||||
class AccountCreateMailView(APIView):
|
||||
|
||||
# authentication_classes = (JSONWebTokenAuthentication,)
|
||||
permission_classes = (IsAuthenticated,)
|
||||
model = Account
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from cases.models import Case
|
|||
from cases.serializer import CaseCreateSerializer, CaseSerializer
|
||||
from cases.tasks import send_email_to_assigned_user
|
||||
from common.models import Attachments, Comment, Profile
|
||||
|
||||
# from common.custom_auth import JSONWebTokenAuthentication
|
||||
from common.serializer import AttachmentsSerializer, CommentSerializer
|
||||
from common.utils import CASE_TYPE, PRIORITY_CHOICE, STATUS_CHOICE
|
||||
|
|
@ -24,13 +25,12 @@ from teams.models import Teams
|
|||
|
||||
|
||||
class CaseListView(APIView, LimitOffsetPagination):
|
||||
|
||||
# authentication_classes = (JSONWebTokenAuthentication,)
|
||||
permission_classes = (IsAuthenticated,)
|
||||
model = Case
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
params = request.post_data
|
||||
params = self.request.post_data
|
||||
queryset = self.model.objects.filter(org=self.request.org).order_by("-id")
|
||||
accounts = Account.objects.filter(org=self.request.org).order_by("-id")
|
||||
contacts = Contact.objects.filter(org=self.request.org).order_by("-id")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
import json
|
||||
|
||||
|
||||
class SwaggerMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request,*args,**kwargs):
|
||||
def __call__(self, request, *args, **kwargs):
|
||||
request.body # just add this line BEFORE get_response
|
||||
|
||||
request.post_data=request.GET if len(request.POST) == 0 else request.POST # for swagger
|
||||
request.post_data = (
|
||||
request.GET if len(request.POST) == 0 else request.POST
|
||||
) # for swagger
|
||||
|
||||
if request.post_data=={} and request.body: #<--- for raw data (import)
|
||||
request.post_data=json.loads(request.body)
|
||||
if request.post_data == {} and request.body: # <--- for raw data (import)
|
||||
request.post_data = json.loads(request.body)
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -10,9 +10,13 @@ from rest_framework.response import Response
|
|||
from rest_framework.views import APIView
|
||||
|
||||
from common.models import Attachments, Comment, Profile, User
|
||||
|
||||
# from common.custom_auth import JSONWebTokenAuthentication
|
||||
from common.serializer import (AttachmentsSerializer, CommentSerializer,
|
||||
ProfileSerializer)
|
||||
from common.serializer import (
|
||||
AttachmentsSerializer,
|
||||
CommentSerializer,
|
||||
ProfileSerializer,
|
||||
)
|
||||
from contacts.models import Contact
|
||||
from contacts.serializer import ContactSerializer
|
||||
from events import swagger_params
|
||||
|
|
@ -39,7 +43,7 @@ class EventListView(APIView, LimitOffsetPagination):
|
|||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
params = request.post_data
|
||||
params = self.request.post_data
|
||||
queryset = self.model.objects.filter(org=self.request.org).order_by("-id")
|
||||
contacts = Contact.objects.filter(org=self.request.org)
|
||||
if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
|
||||
|
|
|
|||
|
|
@ -11,9 +11,13 @@ from rest_framework.views import APIView
|
|||
from accounts.models import Account
|
||||
from accounts.serializer import AccountSerializer
|
||||
from common.models import Attachments, Comment, Profile
|
||||
|
||||
# from common.custom_auth import JSONWebTokenAuthentication
|
||||
from common.serializer import (AttachmentsSerializer, CommentSerializer,
|
||||
ProfileSerializer)
|
||||
from common.serializer import (
|
||||
AttachmentsSerializer,
|
||||
CommentSerializer,
|
||||
ProfileSerializer,
|
||||
)
|
||||
from contacts.models import Contact
|
||||
from contacts.serializer import ContactSerializer
|
||||
from tasks import swagger_params
|
||||
|
|
@ -30,7 +34,7 @@ class TaskListView(APIView, LimitOffsetPagination):
|
|||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
params = request.post_data
|
||||
params = self.request.post_data
|
||||
queryset = self.model.objects.filter(org=self.request.org).order_by("-id")
|
||||
accounts = Account.objects.filter(org=self.request.org)
|
||||
contacts = Contact.objects.filter(org=self.request.org)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
# from common.custom_auth import JSONWebTokenAuthentication
|
||||
from rest_framework import status
|
||||
from rest_framework.pagination import LimitOffsetPagination
|
||||
|
|
@ -21,7 +22,7 @@ class TeamsListView(APIView, LimitOffsetPagination):
|
|||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
params = request.post_data
|
||||
params = self.request.post_data
|
||||
queryset = self.model.objects.filter(org=self.request.org).order_by("-id")
|
||||
if params:
|
||||
if params.get("team_name"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue