<commit_before>from cla_common.constants import FEEDBACK_ISSUE
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext as _

from model_utils.models import TimeStampedModel
from uuidfield import UUIDField


class ProviderManager(models.Manager):
    def active(self):
        return self.get_queryset().filter(active=True)


class Provider(TimeStampedModel):
    name = models.CharField(max_length=255)
    opening_hours = models.CharField(max_length=100)
    law_category = models.ManyToManyField('legalaid.Category',
                                          through='ProviderAllocation')
    active = models.BooleanField(default=False)
    short_code = models.CharField(max_length=100, blank=True)
    telephone_frontdoor = models.CharField(max_length=100, blank=True)
    telephone_backdoor = models.CharField(max_length=100, blank=True)

    email_address = models.EmailField(blank=True)

    objects = ProviderManager()

    def __unicode__(self):
        return u'%s' % self.name


class ProviderAllocationManager(models.Manager):
    def has_category(self, category):
        """
        @param category: type legalaid.Category
        """
        return self.get_queryset().filter(category=category)


class ProviderAllocation(TimeStampedModel):
    provider = models.ForeignKey(Provider)
    category = models.ForeignKey('legalaid.Category')
    weighted_distribution = models.FloatField()  # see XXXXXXXXXXXX

    objects = ProviderAllocationManager()

    def __unicode__(self):
        return u'%s provides %s' % (self.provider, self.category)


class Staff(TimeStampedModel):
    user = models.OneToOneField('auth.User')
    provider = models.ForeignKey(Provider)
    is_manager = models.BooleanField(default=False)


class OutOfHoursRotaManager(models.Manager):
    def get_current(self, category, as_of=None):
        if not as_of: as_of = timezone.localtime(timezone.now())

        return self.get_queryset().get(category=category,
                                 start_date__lte=as_of,
                                 end_date__gte=as_of)

class OutOfHoursRota(TimeStampedModel):
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    category = models.ForeignKey('legalaid.Category')
    provider = models.ForeignKey(Provider)

    objects = OutOfHoursRotaManager()

    def __unicode__(self):
        return u'%s provides out of hours service for %s between %s - %s' \
               % (
            self.provider,
            self.category.code,
            self.start_date,
            self.end_date
        )<commit_msg>cla_provider.Staff object now more readable in django admin<commit_after>from cla_common.constants import FEEDBACK_ISSUE
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext as _

from model_utils.models import TimeStampedModel
from uuidfield import UUIDField


class ProviderManager(models.Manager):
    def active(self):
        return self.get_queryset().filter(active=True)


class Provider(TimeStampedModel):
    name = models.CharField(max_length=255)
    opening_hours = models.CharField(max_length=100)
    law_category = models.ManyToManyField('legalaid.Category',
                                          through='ProviderAllocation')
    active = models.BooleanField(default=False)
    short_code = models.CharField(max_length=100, blank=True)
    telephone_frontdoor = models.CharField(max_length=100, blank=True)
    telephone_backdoor = models.CharField(max_length=100, blank=True)

    email_address = models.EmailField(blank=True)

    objects = ProviderManager()

    def __unicode__(self):
        return u'%s' % self.name


class ProviderAllocationManager(models.Manager):
    def has_category(self, category):
        """
        @param category: type legalaid.Category
        """
        return self.get_queryset().filter(category=category)


class ProviderAllocation(TimeStampedModel):
    provider = models.ForeignKey(Provider)
    category = models.ForeignKey('legalaid.Category')
    weighted_distribution = models.FloatField()  # see XXXXXXXXXXXX

    objects = ProviderAllocationManager()

    def __unicode__(self):
        return u'%s provides %s' % (self.provider, self.category)


class Staff(TimeStampedModel):
    user = models.OneToOneField('auth.User')
    provider = models.ForeignKey(Provider)
    is_manager = models.BooleanField(default=False)

    class Meta:
        verbose_name_plural = 'staff'

    def __unicode__(self):
        return self.user.username


class OutOfHoursRotaManager(models.Manager):
    def get_current(self, category, as_of=None):
        if not as_of: as_of = timezone.localtime(timezone.now())

        return self.get_queryset().get(category=category,
                                 start_date__lte=as_of,
                                 end_date__gte=as_of)

class OutOfHoursRota(TimeStampedModel):
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    category = models.ForeignKey('legalaid.Category')
    provider = models.ForeignKey(Provider)

    objects = OutOfHoursRotaManager()

    def __unicode__(self):
        return u'%s provides out of hours service for %s between %s - %s' \
               % (
            self.provider,
            self.category.code,
            self.start_date,
            self.end_date
        )
{'fraction_non_alphanumeric': 0.0903387703889586, 'fraction_numerical': 0.005377307761247535, 'mean_word_length': 3.2857142857142856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3505278', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1560, 'n_words': 319}