<commit_before>from django.db import models
from twilio.rest import TwilioRestClient
from django.conf import settings


class Contact(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    number = models.CharField(max_length=15)

    def __unicode__(self):
        return u"{0} {1}: {2}".format(self.first_name, self.last_name, self.number)

class Group(models.Model):
    name = models.CharField(max_length=30)
    contacts = models.ManyToManyField("Contact")

    def __unicode__(self):
        return self.name

class Message(models.Model):
    sender = models.ForeignKey("Sender")
    recipients = models.ManyToManyField("Contact")
    body = models.CharField(max_length=1600, blank=True)

    def __unicode__(self):
        return self.body[:50]

    def send(self):
        result = {}
        client = self.sender.initiate()
        for recipient in self.recipients.all():
            number = recipient.number
            sms = client.messages.create(to=number, from_=self.sender.number, body=self.body)
            result[number] = {"sid": sms.sid}
        return result

class Sender(models.Model):
    name = models.CharField(max_length=30)
    number = models.CharField(max_length=15)

    def __unicode__(self):
        return u"{0}: {1}".format(self.name, self.number)

    def initiate(self):
        account = settings.TWILIO_SID
        token = settings.TWILIO_TOKEN
        return TwilioRestClient(account, token)
<commit_msg>Added basic group messaging capability<commit_after>from django.db import models
from twilio.rest import TwilioRestClient
from django.conf import settings


class Contact(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    number = models.CharField(max_length=15)

    def __unicode__(self):
        return u"{0} {1}: {2}".format(self.first_name, self.last_name, self.number)

class Group(models.Model):
    name = models.CharField(max_length=30)
    contacts = models.ManyToManyField("Contact")

    def __unicode__(self):
        return self.name

class Message(models.Model):
    sender = models.ForeignKey("Sender")
    contacts = models.ManyToManyField("Contact", blank=True)
    groups = models.ManyToManyField("Group", blank=True)
    body = models.CharField(max_length=1600, blank=True)

    def __unicode__(self):
        return self.body[:50]

    def send(self):
        result = {}
        client = self.sender.initiate()
        recipients = self.contacts.all()
        for group in self.groups.all():
            recipients = recipients | group.contacts.all()
        for recipient in recipients.distinct():
            number = recipient.number
            sms = client.messages.create(to=number, from_=self.sender.number, body=self.body)
            result[number] = {"sid": sms.sid}
        return result

class Sender(models.Model):
    name = models.CharField(max_length=30)
    number = models.CharField(max_length=15)

    def __unicode__(self):
        return u"{0}: {1}".format(self.name, self.number)

    def initiate(self):
        account = settings.TWILIO_SID
        token = settings.TWILIO_TOKEN
        return TwilioRestClient(account, token)

{'fraction_non_alphanumeric': 0.11498150431565968, 'fraction_numerical': 0.014180024660912454, 'mean_word_length': 3.2923280423280423, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7039816', 'n_tokens_mistral': 1024, 'n_tokens_neox': 974, 'n_words': 201}