<commit_before>from __future__ import unicode_literals
import datetime
from django.db import models
from django.db.models import Q, QuerySet
from django.utils.encoding import python_2_unicode_compatible
from .base import OCDBase, LinkBase, OCDIDField, RelatedBase, IdentifierBase
from .division import Division
from .jurisdiction import Jurisdiction
from ... import common

# abstract models


@python_2_unicode_compatible
class ContactDetailBase(RelatedBase):
    type = models.CharField(max_length=50, choices=common.CONTACT_TYPE_CHOICES)
    value = models.CharField(max_length=300)
    note = models.CharField(max_length=300, blank=True)
    label = models.CharField(max_length=300, blank=True)

    class Meta:
        abstract = True

    def __str__(self):
        return '{}: {}'.format(self.get_type_display(), self.value)


@python_2_unicode_compatible
class OtherNameBase(RelatedBase):
    name = models.CharField(max_length=500, db_index=True)
    note = models.CharField(max_length=500, blank=True)
    start_date = models.CharField(max_length=10, blank=True)    # YYYY[-MM[-DD]]
    end_date = models.CharField(max_length=10, blank=True)      # YYYY[-MM[-DD]]

    class Meta:
        abstract = True

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


# the actual models

@python_2_unicode_compatible
class Organization(OCDBase):
    id = OCDIDField(ocd_type='organization')
    name = models.CharField(max_length=300, help_text="The name of the Organization.")
    image = models.URLField(
        blank=True,
        max_length=2000,
        help_text="A URL leading to an image that identifies the Organization visually."
    )
    parent = models.ForeignKey(
        'self',
        related_name='children',
        null=True,
        help_text="A link to another Organization that serves as this Organization's parent."
    )
    jurisdiction = models.ForeignKey(
        Jurisdiction,
        related_name='organizations',
        null=True,
        help_text="A link to the Jurisdiction that contains this Organization.",
    )
    classification = models.CharField(
        max_length=100,
        blank=True,
        choices=common.ORGANIZATION_CLASSIFICATION_CHOICES,
        help_text="The type of Organization being defined."
    )
    founding_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="The founding date of the Organization in YYYY[-MM[-DD]] string format."
    )
    dissolution_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="The dissolution date of the Organization in YYYY[-MM[-DD]] string format."
    )

    def __str__(self):
        return self.name

    # Access all "ancestor" organizations
    def get_parents(self):
        org = self
        while True:
            org = org.parent
            # Django accesses parents lazily, so have to check if one actually exists
            if org:
                yield org
            else:
                break

    def get_current_members(self):
        """ return all Person objects w/ current memberships to org """
        today = datetime.date.today().isoformat()

        return Person.objects.filter(Q(memberships__start_date='') |
                                     Q(memberships__start_date__lte=today),
                                     Q(memberships__end_date='') |
                                     Q(memberships__end_date__gte=today),
                                     memberships__organization_id=self.id
                                     )

    class Meta:
        db_table = 'opencivicdata_organization'
        index_together = [
            ['jurisdiction', 'classification', 'name'],
            ['classification', 'name'],
        ]


@python_2_unicode_compatible
class OrganizationIdentifier(IdentifierBase):
    organization = models.ForeignKey(Organization, related_name='identifiers')

    def __str__(self):
        tmpl = '%s identifies %s'
        return tmpl % (self.identifier, self.organization)

    class Meta:
        db_table = 'opencivicdata_organizationidentifier'


class OrganizationName(OtherNameBase):
    organization = models.ForeignKey(Organization, related_name='other_names')
<commit_msg>Added help_text for OtherNameBase and OrganizationName models<commit_after>from __future__ import unicode_literals
import datetime
from django.db import models
from django.db.models import Q, QuerySet
from django.utils.encoding import python_2_unicode_compatible
from .base import OCDBase, LinkBase, OCDIDField, RelatedBase, IdentifierBase
from .division import Division
from .jurisdiction import Jurisdiction
from ... import common

# abstract models


@python_2_unicode_compatible
class ContactDetailBase(RelatedBase):
    type = models.CharField(max_length=50, choices=common.CONTACT_TYPE_CHOICES)
    value = models.CharField(max_length=300)
    note = models.CharField(max_length=300, blank=True)
    label = models.CharField(max_length=300, blank=True)

    class Meta:
        abstract = True

    def __str__(self):
        return '{}: {}'.format(self.get_type_display(), self.value)


@python_2_unicode_compatible
class OtherNameBase(RelatedBase):
    name = models.CharField(max_length=500, db_index=True, help_text="An alternative name.")
    note = models.CharField(max_length=500, blank=True, help_text="A short, optional note about alternative name.")
    start_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="An optional start date for usage of the alternative name in YYYY[-MM[-DD]] string format."
    )
    end_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="An optional end date for usage of the alternative name in YYYY[-MM[-DD]] string format."
    )

    class Meta:
        abstract = True

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


# the actual models

@python_2_unicode_compatible
class Organization(OCDBase):
    id = OCDIDField(ocd_type='organization')
    name = models.CharField(max_length=300, help_text="The name of the Organization.")
    image = models.URLField(
        blank=True,
        max_length=2000,
        help_text="A URL leading to an image that identifies the Organization visually."
    )
    parent = models.ForeignKey(
        'self',
        related_name='children',
        null=True,
        help_text="A link to another Organization that serves as this Organization's parent."
    )
    jurisdiction = models.ForeignKey(
        Jurisdiction,
        related_name='organizations',
        null=True,
        help_text="A link to the Jurisdiction that contains this Organization.",
    )
    classification = models.CharField(
        max_length=100,
        blank=True,
        choices=common.ORGANIZATION_CLASSIFICATION_CHOICES,
        help_text="The type of Organization being defined."
    )
    founding_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="The founding date of the Organization in YYYY[-MM[-DD]] string format."
    )
    dissolution_date = models.CharField(
        max_length=10,
        blank=True,
        help_text="The dissolution date of the Organization in YYYY[-MM[-DD]] string format."
    )

    def __str__(self):
        return self.name

    # Access all "ancestor" organizations
    def get_parents(self):
        org = self
        while True:
            org = org.parent
            # Django accesses parents lazily, so have to check if one actually exists
            if org:
                yield org
            else:
                break

    def get_current_members(self):
        """ return all Person objects w/ current memberships to org """
        today = datetime.date.today().isoformat()

        return Person.objects.filter(Q(memberships__start_date='') |
                                     Q(memberships__start_date__lte=today),
                                     Q(memberships__end_date='') |
                                     Q(memberships__end_date__gte=today),
                                     memberships__organization_id=self.id
                                     )

    class Meta:
        db_table = 'opencivicdata_organization'
        index_together = [
            ['jurisdiction', 'classification', 'name'],
            ['classification', 'name'],
        ]


@python_2_unicode_compatible
class OrganizationIdentifier(IdentifierBase):
    organization = models.ForeignKey(Organization, related_name='identifiers')

    def __str__(self):
        tmpl = '%s identifies %s'
        return tmpl % (self.identifier, self.organization)

    class Meta:
        db_table = 'opencivicdata_organizationidentifier'


class OrganizationName(OtherNameBase):
    organization = models.ForeignKey(
        Organization,
        related_name='other_names',
        help_text="A link to the Organization with this alternative name.",
    )

{'fraction_non_alphanumeric': 0.08835027365129007, 'fraction_numerical': 0.008935552328828325, 'mean_word_length': 2.6923711340206187, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2752701', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2407, 'n_words': 606}