shared task for send notif and sms
This commit is contained in:
+11
-27
@@ -3,6 +3,8 @@ from django.dispatch import receiver
|
||||
from .models import OrderModel
|
||||
from account.models import PushSubscription
|
||||
import ghasedak_sms
|
||||
from .tasks import send_change_status_notif, send_change_status_sms
|
||||
|
||||
|
||||
@receiver(pre_save, sender=OrderModel)
|
||||
def order_status_changed(sender, instance, **kwargs):
|
||||
@@ -10,36 +12,18 @@ def order_status_changed(sender, instance, **kwargs):
|
||||
previous = OrderModel.objects.get(pk=instance.pk)
|
||||
|
||||
if previous.status != instance.status:
|
||||
send_change_status_notif(instance)
|
||||
send_change_status_sms(instance)
|
||||
new_status = instance.get_status_display()
|
||||
send_change_status_notif.delay(instance.pk, new_status)
|
||||
send_change_status_sms.delay(instance.pk, new_status)
|
||||
|
||||
if previous.status == 'CART' and instance.status == 'ADMIN_PENDING':
|
||||
# update_cart_price_fields()
|
||||
# update_sell_data()
|
||||
# update_quantity()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user