UPDATE
This commit is contained in:
@@ -18,7 +18,7 @@ class User(auth_models.AbstractUser):
|
||||
default=RoleChoice.USER,
|
||||
)
|
||||
avatar = models.ImageField(upload_to="avatars/", null=True, blank=True)
|
||||
role_permission = models.ForeignKey(Role, on_delete=models.SET_NULL, null=True)
|
||||
permission = models.ForeignKey(Role, on_delete=models.SET_NULL, null=True)
|
||||
|
||||
USERNAME_FIELD = "phone"
|
||||
objects = UserManager()
|
||||
|
||||
@@ -5,7 +5,7 @@ Accounts app urls
|
||||
from django.urls import path, include
|
||||
from rest_framework_simplejwt import views as jwt_views
|
||||
from .views import RegisterView, ResetPasswordView, MeView, ChangePasswordView, UserListApiView, AdminUserListApiView, \
|
||||
AdminUpdate, AdminCreate
|
||||
AdminUpdateAPIView, AdminCreateAPIView
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
router = DefaultRouter()
|
||||
@@ -26,6 +26,6 @@ urlpatterns = [
|
||||
),
|
||||
path("user/list/", UserListApiView.as_view(), name="user-list"),
|
||||
path("admin-user/list/", AdminUserListApiView.as_view(), name="admin-user-list"),
|
||||
path("admin/create/", AdminCreate.as_view(), name="user-create"),
|
||||
path("admin/update/", AdminUpdate.as_view(), name="user-update"),
|
||||
path("admin/create/", AdminCreateAPIView.as_view(), name="user-create"),
|
||||
path("admin/update/", AdminUpdateAPIView.as_view(), name="user-update"),
|
||||
]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.shortcuts import get_object_or_404
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from h11 import Response
|
||||
from rest_framework import generics, filters
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from core.apps.accounts.choices.user import RoleChoice
|
||||
@@ -36,7 +36,7 @@ class AdminUserListApiView(generics.ListAPIView):
|
||||
@extend_schema(tags=['User'],
|
||||
responses={200: UserSerializer},
|
||||
request=UserCreateSerializer)
|
||||
class AdminCreate(APIView):
|
||||
class AdminCreateAPIView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
@@ -52,7 +52,7 @@ class AdminCreate(APIView):
|
||||
@extend_schema(tags=['User'],
|
||||
responses={200: UserSerializer},
|
||||
request=UserCreateSerializer)
|
||||
class AdminUpdate(APIView):
|
||||
class AdminUpdateAPIView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def put(self, request, pk):
|
||||
|
||||
@@ -1,21 +1,60 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class PermissionToAction(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.code}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Harakatlar uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Harakatlar uchun ruxsatnomalar')
|
||||
|
||||
|
||||
class PermissionToTab(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='permission_to_tabs'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Bo'lim uchun ruxsatnoma")
|
||||
verbose_name_plural = _("Bo'lim uchun ruxsatnomalar")
|
||||
|
||||
|
||||
class Permission(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_tab = models.ManyToManyField(PermissionToTab, related_name='permissions')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Sahifa uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Sahifa uchun ruxsatnomalar')
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
permissions = models.ManyToManyField(Permission, related_name='roles', blank=True)
|
||||
permission_to_tabs = models.ManyToManyField(PermissionToTab, related_name='roles', blank=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='roles', blank=True
|
||||
)
|
||||
comment = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Permission(models.Model):
|
||||
class Action(models.TextChoices):
|
||||
CREATE = "create_avto_valuation"
|
||||
CREATE_FAST = "create_fast_auto_valuation"
|
||||
CREATE_AVTO_APPEAL = "create_avto_appeal"
|
||||
class Meta:
|
||||
verbose_name = _('Rol')
|
||||
verbose_name_plural = _('Rollar')
|
||||
|
||||
page = models.CharField(max_length=100)
|
||||
section = models.CharField(max_length=100, null=True, blank=True)
|
||||
action = models.CharField(max_length=20, choices=Action.choices)
|
||||
|
||||
|
||||
class RolePermission(models.Model):
|
||||
role = models.ForeignKey(Role, on_delete=models.CASCADE)
|
||||
permission = models.ForeignKey(Permission, on_delete=models.CASCADE)
|
||||
|
||||
@@ -29,7 +29,7 @@ from .views import (
|
||||
DidoxCompanyInfoAPIView,
|
||||
TechPassportAPIView,
|
||||
EvaluationStatusChange,
|
||||
AutoEvaluationRequestView, GetArchivedEvaluation
|
||||
GetArchivedEvaluationListAPIView
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
@@ -76,8 +76,6 @@ urlpatterns = [
|
||||
),
|
||||
path("evaluation-request/<int:pk>/change-status/", EvaluationStatusChange.as_view(),
|
||||
name="evaluation-change-status"),
|
||||
path("auto-evaluation-request/", AutoEvaluationRequestView.as_view(),
|
||||
name="evaluation-request-price-estimate"),
|
||||
path("archived-evaluvation/", GetArchivedEvaluation.as_view(),
|
||||
path("archived-evaluvation/", GetArchivedEvaluationListAPIView.as_view(),
|
||||
name="archived-evaluation"),
|
||||
]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import requests
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
@@ -14,7 +13,6 @@ from rest_framework.viewsets import ModelViewSet
|
||||
from core.apps.accounts.serializers.user import UserSerializer
|
||||
from core.apps.evaluation.filters.auto import AutoevaluationFilter
|
||||
from core.apps.evaluation.models import AutoEvaluationModel
|
||||
from core.apps.evaluation.serializers import AutoEvaluationSerializer
|
||||
from core.apps.evaluation.serializers.auto import (
|
||||
CreateAutoevaluationSerializer,
|
||||
ListAutoevaluationSerializer,
|
||||
@@ -159,32 +157,8 @@ class AutoEvaluationListAppraisersView(GenericAPIView):
|
||||
return Response({"error": str(e)}, status=500)
|
||||
|
||||
|
||||
@extend_schema(
|
||||
tags=["AutoEvaluation"],
|
||||
request=AutoEvaluationSerializer,
|
||||
)
|
||||
class AutoEvaluationRequestView(APIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def post(self, request):
|
||||
serializer = AutoEvaluationSerializer(data=request.data)
|
||||
|
||||
if serializer.is_valid():
|
||||
data = serializer.validated_data
|
||||
url = "https://uzxarid.felixits.uz/api/v1/ad/price-estimate/"
|
||||
response = requests.post(url, json=data)
|
||||
|
||||
return Response({
|
||||
"success": True,
|
||||
"external_status": response.status_code,
|
||||
"data": response.json(),
|
||||
})
|
||||
return Response({"error": serializer.errors}, status=400)
|
||||
|
||||
|
||||
@extend_schema(tags=["AutoEvaluation"])
|
||||
class GetArchivedEvaluation(ListAPIView):
|
||||
class GetArchivedEvaluationListAPIView(ListAPIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@@ -192,4 +166,13 @@ class GetArchivedEvaluation(ListAPIView):
|
||||
return AutoEvaluationModel.objects.filter(is_archived=True)
|
||||
|
||||
|
||||
@extend_schema(tags=["AutoEvaluation"])
|
||||
class ArchivedEvaluation(APIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request, pk):
|
||||
auto_evaluation = get_object_or_404(AutoEvaluationModel, pk=pk)
|
||||
auto_evaluation.is_archived = request.data["is_archived"]
|
||||
auto_evaluation.save()
|
||||
return Response({"success": True}, status=200)
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework import status
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import status
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from core.apps.accounts.choices import RoleChoice
|
||||
from core.apps.evaluation.choices.request import RequestStatus
|
||||
from core.apps.evaluation.filters.request import EvaluationrequestFilter
|
||||
from core.apps.evaluation.models import EvaluationrequestModel
|
||||
from core.apps.evaluation.serializers.request import (
|
||||
@@ -19,7 +18,6 @@ from core.apps.evaluation.serializers.request import (
|
||||
ListEvaluationrequestSerializer,
|
||||
RetrieveEvaluationrequestSerializer,
|
||||
)
|
||||
from core.apps.evaluation.choices.request import RequestStatus
|
||||
|
||||
|
||||
# class RequestPagination(PageNumberPagination):
|
||||
|
||||
Reference in New Issue
Block a user