order cart payment update
added signals for order
This commit is contained in:
@@ -241,4 +241,11 @@ class SecurityBreachAttemptModel(models.Model):
|
|||||||
return f'تلاش نفوذ از {self.ip_address} در {self.city}, {self.country}'
|
return f'تلاش نفوذ از {self.ip_address} در {self.city}, {self.country}'
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "تلاش نفوذ"
|
verbose_name = "تلاش نفوذ"
|
||||||
verbose_name_plural = "تلاشهای نفوذ"
|
verbose_name_plural = "تلاشهای نفوذ"
|
||||||
|
|
||||||
|
# class NotifModel(models.Model):
|
||||||
|
# subject = models.CharField(max_length=100)
|
||||||
|
# description = models.TextField()
|
||||||
|
|
||||||
|
# def __str__(self):
|
||||||
|
# return f'{self.subject[:30]}'
|
||||||
@@ -143,7 +143,7 @@ USE_TZ = True
|
|||||||
# Static Files Configuration
|
# Static Files Configuration
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
os.path.join(BASE_DIR, "custom_static"),
|
# os.path.join(BASE_DIR, "custom_static"),
|
||||||
BASE_DIR / "core" / "static",
|
BASE_DIR / "core" / "static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ class OrderConfig(AppConfig):
|
|||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'order'
|
name = 'order'
|
||||||
verbose_name = 'سفارش'
|
verbose_name = 'سفارش'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import order.signals
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from django.db.models.signals import pre_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from .models import OrderModel
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=OrderModel)
|
||||||
|
def order_status_changed(sender, instance, **kwargs):
|
||||||
|
if instance.pk:
|
||||||
|
previous = OrderModel.objects.get(pk=instance.pk)
|
||||||
|
|
||||||
|
print(f'pervios {previous.status} instance {instance.status}')
|
||||||
|
if previous.status != instance.status:
|
||||||
|
send_change_status_notif(instance)
|
||||||
|
|
||||||
|
|
||||||
|
def send_change_status_notif(order):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def update_cart_price_fields(order):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def update_sell_data(order):
|
||||||
|
pass
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ urlpatterns = [
|
|||||||
path('cart/discount', ApplyDiscountView.as_view()),
|
path('cart/discount', ApplyDiscountView.as_view()),
|
||||||
path('cart/all', CartItemClear.as_view()),
|
path('cart/all', CartItemClear.as_view()),
|
||||||
path('cart/item/<int:pk>', CartItemViews.as_view(), name='change-item-cart'),
|
path('cart/item/<int:pk>', CartItemViews.as_view(), name='change-item-cart'),
|
||||||
path('payment', PaymentView.as_view(), name='payment'),
|
path('cart/payment', PaymentView.as_view(), name='payment'),
|
||||||
path('callback', callback_view, name='callback-gateway'),
|
path('callback', callback_view, name='callback-gateway'),
|
||||||
path('<int:pk>', OrderGetView.as_view(), name='order-get'),
|
path('<int:pk>', OrderGetView.as_view(), name='order-get'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -176,9 +176,22 @@ class OrderGetView(APIView):
|
|||||||
order_ser = self.serializer_class(order_object, context={'request': request})
|
order_ser = self.serializer_class(order_object, context={'request': request})
|
||||||
return Response(order_ser.data, status=status.HTTP_200_OK)
|
return Response(order_ser.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
class BankTypeSerializer(serializers.Serializer):
|
||||||
|
gateway_type = serializers.ChoiceField(choices=['BMI', 'SEP', 'ZARINPAL', 'IDPAY', 'ZIBAL', 'BAHAMTA', 'MELLAT', 'PAYV1'])
|
||||||
|
|
||||||
|
|
||||||
class PaymentView(APIView):
|
class PaymentView(APIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
@extend_schema(
|
||||||
|
request=BankTypeSerializer,
|
||||||
|
description="choices=['BMI', 'SEP', 'ZARINPAL', 'IDPAY', 'ZIBAL', 'BAHAMTA', 'MELLAT', 'PAYV1']"
|
||||||
|
)
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
print(request.data.get('gateway_type'))
|
||||||
cart_order = get_object_or_404(OrderModel, user=request.user, status='CART')
|
cart_order = get_object_or_404(OrderModel, user=request.user, status='CART')
|
||||||
amount = 5000
|
amount = 5000
|
||||||
user_mobile_number = request.user.phone
|
user_mobile_number = request.user.phone
|
||||||
|
|||||||
Reference in New Issue
Block a user