53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from django.db.models.signals import pre_save
|
|
from django.dispatch import receiver
|
|
from .models import OrderModel
|
|
from account.models import PushSubscription
|
|
|
|
|
|
@receiver(pre_save, sender=OrderModel)
|
|
def order_status_changed(sender, instance, **kwargs):
|
|
if instance.pk:
|
|
previous = OrderModel.objects.get(pk=instance.pk)
|
|
|
|
if previous.status != instance.status:
|
|
send_change_status_notif(instance)
|
|
send_change_status_sms(instance)
|
|
|
|
|
|
|
|
def send_change_status_notif(instance):
|
|
user_subs = PushSubscription.objects.filter(user=instance.user)
|
|
for user_sub in user_subs:
|
|
try:
|
|
user_sub.send_notif(f'سفارش شما به {instance.get_status_display()} تغییر کرد', f'سفارش شما به {instance.get_status_display()} تغییر کرد', ProductImageModel.objects.all().first().image.url)
|
|
except:
|
|
print('log later send notif error')
|
|
|
|
|
|
def send_change_status_sms(instance):
|
|
sms_api = ghasedak_sms.Ghasedak(api_key="1227eaaddcba72bcb0169b37032cf16ae9ac6ed8b3b7c2768b74e2ee351d1b52gyRe3AGomZRPTNEd")
|
|
|
|
|
|
response = sms_api.send_single_sms(
|
|
ghasedak_sms.SendSingleSmsInput(
|
|
message=f'سفارش شما به {instance.get_status_display()} تغییر کرد',
|
|
receptor=instance.user.phone,
|
|
line_number='30005006004095',
|
|
client_reference_id=str(instance.user.pk)
|
|
)
|
|
)
|
|
if response['statusCode'] == 200:
|
|
print('done log later')
|
|
else:
|
|
print(f'error: {response}')
|
|
|
|
|
|
def update_cart_price_fields(order):
|
|
pass
|
|
|
|
def update_sell_data(order):
|
|
pass
|
|
|
|
def update_quantity(order):
|
|
pass
|