<commit_before>from django.db import models
from djorm_pgarray.fields import ArrayField

from .base import CommonBase, LinkBase
from .people_orgs import Organization, Person
from .jurisdiction import JurisdictionSession


class RelatedEntityBase(models.Model):
    name = models.CharField(max_length=300)
    entity_type = models.CharField(max_length=20)

    # optionally tied to an organization or person if it was linkable
    organization = models.ForeignKey(Organization, null=True)
    person = models.ForeignKey(Person, null=True)

    @property
    def entity_name(self):
        if entity_type == 'organization' and self.organization_id:
            return self.organization.name
        elif entity_type == 'person' and self.person_id:
            return self.person.name
        else:
            return self.name

    class Meta:
        abstract = True


class BillLinkBase(models.Model):
    mimetype = models.CharField(max_length=100)
    url = models.URLField()

    class Meta:
        abstract = True


# the actual models

class Bill(CommonBase):
    id = models.CharField(max_length=100, primary_key=True)
    session = models.ForeignKey(JurisdictionSession, related_name='bills')
    name = models.CharField(max_length=100)

    title = models.TextField()

    from_organization = models.ForeignKey(Organization, related_name='bills', null=True)
    classification = ArrayField(dbtype="text")
    subject = ArrayField(dbtype="text")

    def __str__(self):
        return '{} in {}'.format(self.name, self.session)


class BillSummary(models.Model):
    bill = models.ForeignKey(Bill, related_name='summaries')
    text = models.TextField()
    note = models.TextField(blank=True)


class BillTitle(models.Model):
    bill = models.ForeignKey(Bill, related_name='other_titles')
    text = models.TextField()
    note = models.TextField(blank=True)


class BillName(models.Model):
    bill = models.ForeignKey(Bill, related_name='other_names')
    name = models.CharField(max_length=100)
    note = models.TextField(blank=True)


class BillAction(models.Model):
    bill = models.ForeignKey(Bill, related_name='actions')
    actor = models.CharField(max_length=100)
    actor = models.CharField(max_length=100)
    date = models.CharField(max_length=10)    # YYYY[-MM[-DD]]
    classification = ArrayField(dbtype="text")


class BillActionRelatedEntity(RelatedEntityBase):
    action = models.ForeignKey(BillAction, related_name='related_entities')


class RelatedBill(models.Model):
    bill = models.ForeignKey(Bill, related_name='related_bills')
    related_bill = models.ForeignKey(Bill, related_name='related_bills_reverse')
    relation_type = models.CharField(max_length=100)        # enum?

    def __str__(self):
        return 'relationship of {} to {} ({})'.format(self.bill, self.related_bill,
                                                      self.relation_type)



class BillSponsor(RelatedEntityBase):
    bill = models.ForeignKey(Bill, related_name='sponsors')
    primary = models.BooleanField(default=False)
    classification = models.CharField(max_length=100)   # enum?

    def __str__(self):
        return '{} ({}) sponsorship of {}'.format(self.name, self.entity_type, self.bill)<commit_msg>add action ordering and description<commit_after>from django.db import models
from djorm_pgarray.fields import ArrayField

from .base import CommonBase, LinkBase
from .people_orgs import Organization, Person
from .jurisdiction import JurisdictionSession


class RelatedEntityBase(models.Model):
    name = models.CharField(max_length=300)
    entity_type = models.CharField(max_length=20)

    # optionally tied to an organization or person if it was linkable
    organization = models.ForeignKey(Organization, null=True)
    person = models.ForeignKey(Person, null=True)

    @property
    def entity_name(self):
        if entity_type == 'organization' and self.organization_id:
            return self.organization.name
        elif entity_type == 'person' and self.person_id:
            return self.person.name
        else:
            return self.name

    class Meta:
        abstract = True


class BillLinkBase(models.Model):
    mimetype = models.CharField(max_length=100)
    url = models.URLField()

    class Meta:
        abstract = True


# the actual models

class Bill(CommonBase):
    id = models.CharField(max_length=100, primary_key=True)
    session = models.ForeignKey(JurisdictionSession, related_name='bills')
    name = models.CharField(max_length=100)

    title = models.TextField()

    from_organization = models.ForeignKey(Organization, related_name='bills', null=True)
    classification = ArrayField(dbtype="text")
    subject = ArrayField(dbtype="text")

    def __str__(self):
        return '{} in {}'.format(self.name, self.session)


class BillSummary(models.Model):
    bill = models.ForeignKey(Bill, related_name='summaries')
    text = models.TextField()
    note = models.TextField(blank=True)


class BillTitle(models.Model):
    bill = models.ForeignKey(Bill, related_name='other_titles')
    text = models.TextField()
    note = models.TextField(blank=True)


class BillName(models.Model):
    bill = models.ForeignKey(Bill, related_name='other_names')
    name = models.CharField(max_length=100)
    note = models.TextField(blank=True)


class BillAction(models.Model):
    bill = models.ForeignKey(Bill, related_name='actions')
    actor = models.CharField(max_length=100)
    description = models.TextField()
    date = models.CharField(max_length=10)    # YYYY[-MM[-DD]]
    classification = ArrayField(dbtype="text")
    order = models.PositiveIntegerField()

    class Meta:
        ordering = ['order']


class BillActionRelatedEntity(RelatedEntityBase):
    action = models.ForeignKey(BillAction, related_name='related_entities')


class RelatedBill(models.Model):
    bill = models.ForeignKey(Bill, related_name='related_bills')
    related_bill = models.ForeignKey(Bill, related_name='related_bills_reverse')
    relation_type = models.CharField(max_length=100)        # enum?

    def __str__(self):
        return 'relationship of {} to {} ({})'.format(self.bill, self.related_bill,
                                                      self.relation_type)



class BillSponsor(RelatedEntityBase):
    bill = models.ForeignKey(Bill, related_name='sponsors')
    primary = models.BooleanField(default=False)
    classification = models.CharField(max_length=100)   # enum?

    def __str__(self):
        return '{} ({}) sponsorship of {}'.format(self.name, self.entity_type, self.bill)
{'fraction_non_alphanumeric': 0.10714285714285714, 'fraction_numerical': 0.008966565349544073, 'mean_word_length': 3.8141916605705926, 'pattern_counts': {'":': 0, '<': 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': '3193717', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1864, 'n_words': 393}