<commit_before>import datetime

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.core import exceptions
from django.db.models import Q
from django.conf import settings

from django_date_extensions.fields import ApproximateDateField
from markitup.fields import MarkupField

from popit.models import ModelBase, date_help_text, Person, Organisation, DataKey, Data

class PositionCategory(ModelBase):
    #category_choices = (
    #    ('political', 'Political'),
    #    ('education', 'Education (as a learner)'),
    #    ('other',     'Anything else'),
    #)
    category = models.CharField(max_length=100)

    class Meta:
        ordering = [ 'category' ]
        app_label = 'popit'
        verbose_name_plural = 'position categories'

    def __unicode__(self):
        return self.category

class PositionType(ModelBase):
    name            = models.CharField(max_length=100)
    slug            = models.SlugField()
    summary         = MarkupField(blank=True, default='')
    requires_place  = models.BooleanField(default=False, help_text="Does this job type require a place to complete the position?")
    organisation    = models.ForeignKey(Organisation, null=True, blank=True)
    category        = models.ForeignKey(PositionCategory, null=True, blank=True, help_text="What sort of position is this?")

    class Meta:
        ordering = [ "name" ]
        app_label = 'popit'

    def __unicode__(self):
        if self.organisation:
            return u'%s (%s)' % (self.name, self.organisation)
        return self.name
    
#    @models.permalink
#    def get_absolute_url(self):
#        return ( 'position', [ self.slug ] )
#
#    def organisations(self):
#        """
#        Return a qs of organisations, with the most frequently related first.
#
#        Each organisation is also annotated with 'position_count' which might be
#        useful.
#
#        This is intended as an alternative to assigning a org to each
#        position_title. Instead we can deduce it from the postions.
#        """
#
#        orgs = (
#            Organisation
#                .objects
#                .filter(position__title=self)
#                .annotate( position_count=models.Count('position') )
#                .order_by( '-position_count' )
#        )
#
#        return orgs

class Position(ModelBase):
    person          = models.ForeignKey(Person)
    organisation    = models.ForeignKey(Organisation, null=True, blank=True)

    type            = models.ForeignKey(PositionType, null=True, blank=True)
    title           = models.CharField(max_length=200, blank=True, default='')

    # XXX: Working with South here presumably, umm, tricky
    if 'mapit' in settings.INSTALLED_APPS:
        place       = models.ForeignKey('Place', null=True, blank=True, help_text="use if needed to identify the position - eg add constituency for an 'MP'" )
    else:
        place       = models.CharField(max_length=100, blank=True, help_text="use if needed to identify the position - eg add constituency for an 'MP'")

    note            = models.CharField(max_length=300, blank=True, default='')

    start_date      = ApproximateDateField(blank=True, help_text=date_help_text)
    end_date        = ApproximateDateField(blank=True, help_text=date_help_text, default="future")

    # Two hidden fields that are only used to do sorting. Filled in by code.
    sorting_start_date      = models.CharField(editable=True, default='', max_length=10)
    sorting_end_date        = models.CharField(editable=True, default='', max_length=10)

    def __unicode__(self):
        if self.organisation:
            organisation = self.organisation.name
        elif self.type and self.type.organisation:
            organisation = self.type.organisation.name
        else:
            organisation = 'Unknown'
        if self.title and self.type:
            title = u'%s (%s)' % (self.title, self.type)<commit_msg>When mapit is installed use the Area model for the foreign key<commit_after>import datetime

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.core import exceptions
from django.db.models import Q
from django.conf import settings

from django_date_extensions.fields import ApproximateDateField
from markitup.fields import MarkupField

from popit.models import ModelBase, date_help_text, Person, Organisation, DataKey, Data

class PositionCategory(ModelBase):
    #category_choices = (
    #    ('political', 'Political'),
    #    ('education', 'Education (as a learner)'),
    #    ('other',     'Anything else'),
    #)
    category = models.CharField(max_length=100)

    class Meta:
        ordering = [ 'category' ]
        app_label = 'popit'
        verbose_name_plural = 'position categories'

    def __unicode__(self):
        return self.category

class PositionType(ModelBase):
    name            = models.CharField(max_length=100)
    slug            = models.SlugField()
    summary         = MarkupField(blank=True, default='')
    requires_place  = models.BooleanField(default=False, help_text="Does this job type require a place to complete the position?")
    organisation    = models.ForeignKey(Organisation, null=True, blank=True)
    category        = models.ForeignKey(PositionCategory, null=True, blank=True, help_text="What sort of position is this?")

    class Meta:
        ordering = [ "name" ]
        app_label = 'popit'

    def __unicode__(self):
        if self.organisation:
            return u'%s (%s)' % (self.name, self.organisation)
        return self.name
    
#    @models.permalink
#    def get_absolute_url(self):
#        return ( 'position', [ self.slug ] )
#
#    def organisations(self):
#        """
#        Return a qs of organisations, with the most frequently related first.
#
#        Each organisation is also annotated with 'position_count' which might be
#        useful.
#
#        This is intended as an alternative to assigning a org to each
#        position_title. Instead we can deduce it from the postions.
#        """
#
#        orgs = (
#            Organisation
#                .objects
#                .filter(position__title=self)
#                .annotate( position_count=models.Count('position') )
#                .order_by( '-position_count' )
#        )
#
#        return orgs

class Position(ModelBase):
    person          = models.ForeignKey(Person)
    organisation    = models.ForeignKey(Organisation, null=True, blank=True)

    type            = models.ForeignKey(PositionType, null=True, blank=True)
    title           = models.CharField(max_length=200, blank=True, default='')

    # XXX: Working with South here presumably, umm, tricky
    if 'mapit' in settings.INSTALLED_APPS:
        from mapit import models as mapit_models
        place       = models.ForeignKey(mapit_models.Area, null=True, blank=True, help_text="use if needed to identify the position - eg add constituency for an 'MP'" )
    else:
        place       = models.CharField(max_length=100, blank=True, help_text="use if needed to identify the position - eg add constituency for an 'MP'")

    note            = models.CharField(max_length=300, blank=True, default='')

    start_date      = ApproximateDateField(blank=True, help_text=date_help_text)
    end_date        = ApproximateDateField(blank=True, help_text=date_help_text, default="future")

    # Two hidden fields that are only used to do sorting. Filled in by code.
    sorting_start_date      = models.CharField(editable=True, default='', max_length=10)
    sorting_end_date        = models.CharField(editable=True, default='', max_length=10)

    def __unicode__(self):
        if self.organisation:
            organisation = self.organisation.name
        elif self.type and self.type.organisation:
            organisation = self.type.organisation.name
        else:
            organisation = 'Unknown'
        if self.title and self.type:
            title = u'%s (%s)' % (self.title, self.type)
{'fraction_non_alphanumeric': 0.09695256819857459, 'fraction_numerical': 0.004669451953797002, 'mean_word_length': 2.8301176470588234, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7556767', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2256, 'n_words': 624}