# What this PR does - Adds [`mypy` static type checking](https://mypy-lang.org/) to our CI pipeline. Currently there is still a **ton** of errors being returned by the tool, as we'll need to fix pre-existing errors. I think we can slowly chip away at these errors in small PRs, doing them all in one large PR is likely very risky. - Also, this PR starts chipping away at one of the main type errors that we have which is accessing the `datetime` class (from the `datetime` library) or `timedelta` function on the `django.utils.timezone` module. Basically we should be instead accessing these two objects from the native `datetime` module. This makes sense because the [`__all__` attribute](https://github.com/django/django/blob/main/django/utils/timezone.py#L14-L30) in `django.utils.timezone` does not re-export `datetime` or `timedelta`. - splits `engine` dependencies out into `requirements.txt` and `requirements-dev.txt` ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated (N/A) - [ ] Documentation added (or `pr:no public docs` PR label added if not required) (N/A) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) (N/A)
72 lines
1.6 KiB
Python
72 lines
1.6 KiB
Python
import logging
|
|
|
|
from django.db import models
|
|
|
|
from apps.phone_notifications.models import PhoneCallRecord
|
|
from apps.phone_notifications.phone_provider import ProviderPhoneCall
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class TwilioCallStatuses:
|
|
"""
|
|
https://www.twilio.com/docs/voice/twiml#callstatus-values
|
|
"""
|
|
|
|
QUEUED = 10
|
|
RINGING = 20
|
|
IN_PROGRESS = 30
|
|
COMPLETED = 40
|
|
BUSY = 50
|
|
FAILED = 60
|
|
NO_ANSWER = 70
|
|
CANCELED = 80
|
|
|
|
CHOICES = (
|
|
(QUEUED, "queued"),
|
|
(RINGING, "ringing"),
|
|
(IN_PROGRESS, "in-progress"),
|
|
(COMPLETED, "completed"),
|
|
(BUSY, "busy"),
|
|
(FAILED, "failed"),
|
|
(NO_ANSWER, "no-answer"),
|
|
(CANCELED, "canceled"),
|
|
)
|
|
|
|
DETERMINANT = {
|
|
"queued": QUEUED,
|
|
"ringing": RINGING,
|
|
"in-progress": IN_PROGRESS,
|
|
"completed": COMPLETED,
|
|
"busy": BUSY,
|
|
"failed": FAILED,
|
|
"no-answer": NO_ANSWER,
|
|
"canceled": CANCELED,
|
|
}
|
|
|
|
|
|
class TwilioPhoneCall(ProviderPhoneCall, models.Model):
|
|
status = models.PositiveSmallIntegerField(
|
|
blank=True,
|
|
null=True,
|
|
choices=TwilioCallStatuses.CHOICES,
|
|
)
|
|
|
|
phone_call_record = models.OneToOneField(
|
|
"phone_notifications.PhoneCallRecord",
|
|
on_delete=models.CASCADE,
|
|
related_name="twilio_phone_call",
|
|
null=False,
|
|
)
|
|
|
|
sid = models.CharField(
|
|
blank=True,
|
|
max_length=50,
|
|
db_index=True,
|
|
)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
def link_and_save(self, phone_call_record: PhoneCallRecord):
|
|
self.phone_call_record = phone_call_record
|
|
self.save()
|