send message signal
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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):
|
||||
@@ -9,10 +11,36 @@ def order_status_changed(sender, instance, **kwargs):
|
||||
|
||||
if previous.status != instance.status:
|
||||
send_change_status_notif(instance)
|
||||
send_change_status_sms(instance)
|
||||
|
||||
|
||||
|
||||
def send_change_status_notif(order):
|
||||
pass
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user