Added Send SMS function to traveller contacts. The send command is commented out.

This commit is contained in:
John Mullins
2023-09-07 15:42:11 +10:00
parent 49dae4892b
commit 43c23498bf
5 changed files with 103 additions and 2 deletions
+24
View File
@@ -1,6 +1,9 @@
from datetime import datetime
import phonenumbers
from django.conf import settings
from django.db import models
from twilio.rest import Client
class Setting(models.Model):
@@ -261,6 +264,27 @@ class Traveller(models.Model):
stops = 1
return f"${str(cost * stops)}"
def send_sms(self, message, parents=False, emergency=False):
numbers = []
if parents and self.parent_A_phone:
numbers.append(self.parent_A_phone)
if parents and self.parent_B_phone:
numbers.append(self.parent_B_phone)
if emergency and self.emergency_contact_A_phone:
numbers.append(self.emergency_contact_A_phone)
if emergency and self.emergency_contact_B_phone:
numbers.append(self.emergency_contact_B_phone)
count = 0
for number in numbers:
num = phonenumbers.parse(number, "AU")
if phonenumbers.is_valid_number(num):
count += 1
# num = f"+{num.country_code}{num.national_number}"
# client = Client(settings.TWILIO['ACCOUNT_SID'], settings.TWILIO['AUTH_TOKEN'])
# client.messages.create(num, from_=settings.TWILIO['SENDER'], body=message)
return count
class TravellerRoute(models.Model):
traveller = models.ForeignKey(Traveller, on_delete=models.CASCADE)