Merge remote-tracking branch 'origin/main'

This commit is contained in:
marzban-dev
2025-01-16 16:06:37 +03:30
5 changed files with 33 additions and 14 deletions
+1
View File
@@ -4,6 +4,7 @@ from djoser.urls.jwt import views as djoser_jwt_views
urlpatterns = [
path('profile', views.ProfileView.as_view()),
path('verify', djoser_jwt_views.TokenVerifyView.as_view(), name='jwt-verify'),
path('send_otp', views.SendOTPView.as_view(), name='send-otp-view'),
path('address/create', views.CreateAddressView.as_view(), name='create-address'),
path('address/edit/<int:pk>', views.EditAddressView.as_view(), name='edit-address'),
+2 -2
View File
@@ -200,8 +200,8 @@ REST_FRAMEWORK = {
}
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=2),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': True,
}
+1 -1
View File
@@ -16,7 +16,7 @@ urlpatterns = [
path('token/', CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
# path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('admin/', admin.site.urls),
path('schema/', SpectacularAPIView.as_view(), name='schema'),
# path('comment/<int:pk>', views.CommentView.as_view(), name='comment-list'),
+9 -3
View File
@@ -1,8 +1,11 @@
from .models import *
from rest_framework import serializers
from django.utils import timezone
from datetime import timedelta
class ProductChatSerializer(serializers.ModelSerializer):
price = serializers.SerializerMethodField()
is_new = serializers.SerializerMethodField()
class Meta:
model = ProductModel
fields = ['name', 'description', 'price', 'in_stock', 'discount', ]
@@ -13,11 +16,14 @@ class ProductChatSerializer(serializers.ModelSerializer):
if dollor_price is None:
raise ValidationError({"dollor_price": "The 'dollor_price' must be provided in the context for dollar pricing."})
if obj.currency == 'toman':
return obj.price
toman_price = obj.price
elif obj.currency == 'dollor':
return obj.price * dollor_price
toman_price = obj.price * dollor_price
elif obj.currency == 'derham':
return obj.price * dollor_price * dollar_to_dirham
toman_price = obj.price * dollor_price * dollar_to_dirham
return "{:,.0f} تومان".format(toman_price)
def get_is_new(self, obj):
return timezone.now() < obj.created_at + timedelta(days=7)
class ProductSerializer(ProductChatSerializer):
class Meta:
+20 -8
View File
@@ -8,8 +8,7 @@ from django.db.models import Q
from django.shortcuts import get_object_or_404
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from utils.pagination import StructurePagination
from drf_spectacular.utils import extend_schema, OpenApiParameter
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
from rest_framework.permissions import AllowAny
@@ -26,8 +25,26 @@ from rest_framework.permissions import AllowAny
class AllCategories(APIView):
serializer_class = CategorySerializer
authentication_classes = []
@extend_schema(
parameters=[
OpenApiParameter(
name="search",
description="Search by category name or description.",
required=False,
type=OpenApiTypes.STR,
)
],
responses={
200: CategorySerializer(many=True),
404: OpenApiTypes.OBJECT,
},
)
def get(self, request):
categories = CategoryModel.objects.all()
search_query = request.query_params.get('search', None)
if search_query:
categories = CategoryModel.objects.filter(Q(name__icontains=search_query) | Q(slug__icontains=search_query))
else:
categories = CategoryModel.objects.all()
categories_ser = self.serializer_class(instance=categories, many=True)
return Response({"categories": categories_ser.data}, status=status.HTTP_200_OK)
@@ -40,11 +57,6 @@ class ProductView(APIView):
product_ser = self.serializer_class(instance=product, many=False)
return Response(product_ser.data, status=status.HTTP_200_OK)
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
from django.db.models import Q
class AllProductsView(APIView):
serializer_class = ProductSerializer