fix: users.py file code clear
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
import uuid
|
||||
from typing import cast
|
||||
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
from rest_framework.generics import GenericAPIView # type: ignore
|
||||
from rest_framework.decorators import action # type: ignore
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from rest_framework.permissions import IsAdminUser # type: ignore
|
||||
from rest_framework import status # type: ignore
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
from rest_framework.response import Response # type: ignore
|
||||
from rest_framework.permissions import ( # type: ignore
|
||||
IsAdminUser,
|
||||
)
|
||||
|
||||
from rest_framework.generics import get_object_or_404 # type: ignore
|
||||
from rest_framework.permissions import IsAdminUser # type: ignore
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
|
||||
@@ -31,7 +27,7 @@ UserModel = get_user_model()
|
||||
|
||||
|
||||
######################################################################
|
||||
# /users/{id}/companies
|
||||
# @api-view | POST, GET - users/{id}/companies
|
||||
######################################################################
|
||||
@extend_schema(tags=["User Companies"])
|
||||
class UserCompanyApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
@@ -70,21 +66,14 @@ class UserCompanyApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
summary="Create Company For User",
|
||||
description="Create Company For User",
|
||||
)
|
||||
def post(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object,
|
||||
) -> Response:
|
||||
def post(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
||||
with transaction.atomic():
|
||||
ser = CreateCompanySerializer(data=request.data) # type: ignore
|
||||
ser = cast(CreateCompanySerializer, self.get_serializer(data=request.data)) # type: ignore
|
||||
ser.is_valid(raise_exception=True)
|
||||
company = ser.save() # type: ignore
|
||||
company = ser.save()
|
||||
|
||||
user = get_object_or_404(UserModel, pk=pk)
|
||||
user = self.get_object()
|
||||
|
||||
account = CompanyAccountModel(company=company, user=user)
|
||||
account.save()
|
||||
|
||||
return Response(data=ser.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
Reference in New Issue
Block a user