<commit_before>import random

from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
from django.utils.encoding import python_2_unicode_compatible

from .tasks import add_unique_id_to_identity


@python_2_unicode_compatible
class Record(models.Model):
    """ The historical record of identities requiring unique integer refs
        write_to is the field we should write back to on the identity details
    """
    id = models.BigIntegerField(primary_key=True)
    identity = models.UUIDField()
    write_to = models.CharField(max_length=36, null=False, blank=False)
    length = models.IntegerField(default=10)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    created_by = models.ForeignKey(User, related_name='records_created',
                                   null=True)
    updated_by = models.ForeignKey(User, related_name='records_updated',
                                   null=True)
    user = property(lambda self: self.created_by)

    def __str__(self):
        return "%s for %s" % (self.id, str(self.identity))


@receiver(pre_save, sender=Record)
def record_pre_save(sender, instance, **kwargs):
    """ Pre save hook to generate a unique ID
    """
    if instance.id is None:
        instance.id = generate_unique_id(length=instance.length)


@receiver(post_save, sender=Record)
def record_post_save(sender, instance, created, **kwargs):
    """ Post save hook to patch the source identity
    """
    if created:
        add_unique_id_to_identity.apply_async(
            kwargs={
                "identity": str(instance.identity),
                "unique_id": instance.id,
                "write_to": instance.write_to
            })


def random_digits(digits):
    lower = 10**(digits-1)
    upper = 10**digits - 1
    return random.randint(lower, upper)


def digits_of(number):<commit_msg>Run send_personnel_code task if it is a hcw<commit_after>import random

from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
from django.utils.encoding import python_2_unicode_compatible

from .tasks import add_unique_id_to_identity, send_personnel_code


@python_2_unicode_compatible
class Record(models.Model):
    """ The historical record of identities requiring unique integer refs
        write_to is the field we should write back to on the identity details
    """
    id = models.BigIntegerField(primary_key=True)
    identity = models.UUIDField()
    write_to = models.CharField(max_length=36, null=False, blank=False)
    length = models.IntegerField(default=10)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    created_by = models.ForeignKey(User, related_name='records_created',
                                   null=True)
    updated_by = models.ForeignKey(User, related_name='records_updated',
                                   null=True)
    user = property(lambda self: self.created_by)

    def __str__(self):
        return "%s for %s" % (self.id, str(self.identity))


@receiver(pre_save, sender=Record)
def record_pre_save(sender, instance, **kwargs):
    """ Pre save hook to generate a unique ID
    """
    if instance.id is None:
        instance.id = generate_unique_id(length=instance.length)


@receiver(post_save, sender=Record)
def record_post_save(sender, instance, created, **kwargs):
    """ Post save hook to patch the source identity
    """
    if created:
        s = add_unique_id_to_identity.s(
            kwargs={
                "identity": str(instance.identity),
                "unique_id": instance.id,
                "write_to": instance.write_to
            })
        if instance.write_to != 'health_id':
            s.link(send_personnel_code.s(kwargs={
                "identity": str(instance.identity),
                "personnel_code": instance.id
            }))
        s.apply_async()


def random_digits(digits):
    lower = 10**(digits-1)
    upper = 10**digits - 1
    return random.randint(lower, upper)


def digits_of(number):
{'fraction_non_alphanumeric': 0.0949367088607595, 'fraction_numerical': 0.005625879043600563, 'mean_word_length': 3.1266924564796907, 'pattern_counts': {'":': 8, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3700204', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1215, 'n_words': 303}