Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create directory for turn alerts and model #202

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added rp_turn_alerts/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions rp_turn_alerts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin

from .models import TurnAlerts

admin.site.register(TurnAlerts)
5 changes: 5 additions & 0 deletions rp_turn_alerts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class RpTurnAlertsConfig(AppConfig):
name = "rp_turn_alerts"
Empty file.
22 changes: 22 additions & 0 deletions rp_turn_alerts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models

from .validators import za_phone_number


class TurnAlerts(models.Model):
message_id = models.UUIDField()
msisdn = models.CharField(max_length=255, validators=[za_phone_number])
message_status = models.TextField(null=True, blank=True)
message_direction = models.TextField(null=True, blank=True)
message_body = models.TextField(null=True, blank=True)
fallback_channel = models.TextField(null=True, blank=True)
message_type = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return (
f"Recipient_ID: {self.message_id} "
f"MSISDN: {self.msisdn} \n"
f"Created_at: {self.created_at} \n"
f"message_status: {self.message_status} \n"
)
Empty file.
Empty file added rp_turn_alerts/urls.py
Empty file.
18 changes: 18 additions & 0 deletions rp_turn_alerts/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import functools

import phonenumbers
from rest_framework.serializers import ValidationError


def _phone_number(value, country):
try:
number = phonenumbers.parse(value, country)
except phonenumbers.NumberParseException as e:
raise ValidationError(str(e))
if not phonenumbers.is_possible_number(number):
raise ValidationError("Not a possible phone number")
if not phonenumbers.is_valid_number(number):
raise ValidationError("Not a valid phone number")


za_phone_number = functools.partial(_phone_number, country="ZA")
Empty file added rp_turn_alerts/views.py
Empty file.
Loading