<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from csacompendium.utils.abstractmodels import (
    AuthUserDetail,
    CreateUpdateTime,
)
from csacompendium.utils.createslug import create_slug
from csacompendium.utils.modelmanagers import (
    model_instance_filter,
    model_foreign_key_qs,
    model_type_filter,
    create_model_type,
    get_year_choices,
    get_datetime_now,
)
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.core.urlresolvers import reverse


class Subpillar(AuthUserDetail, CreateUpdateTime):<commit_msg>Added model "indicator type"<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from csacompendium.utils.abstractmodels import (
    AuthUserDetail,
    CreateUpdateTime,
)
from csacompendium.utils.createslug import create_slug
from csacompendium.utils.modelmanagers import (
    model_instance_filter,
    model_foreign_key_qs,
    model_type_filter,
    create_model_type,
    get_year_choices,
    get_datetime_now,
)
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.core.urlresolvers import reverse


class IndicatorType(AuthUserDetail, CreateUpdateTime):
    """
    Indicator type model.  Creates indicator type entity.
    """
    slug = models.SlugField(max_length=120, unique=True, blank=True)
    indicator_type = models.CharField(max_length=120, unique=True, verbose_name='Indicator category')

    def __unicode__(self):
        return self.indicator_type

    def __str__(self):
        return self.indicator_type

    def get_api_url(self):
        """
        Get indicator type URL as a reverse from model
        :return: URL
        :rtype: String
        """
        return reverse('indicator_api:indicator_type_detail', kwargs={'slug': self.slug})

    class Meta:
        ordering = ['-time_created', '-last_update']
        verbose_name_plural = 'Indicator Types'

    @property
    def outcome_indicator_relation(self):
        """
        Get related outcome indicator
        :return: Query result from the outcome indicator model
        :rtype: object/record
        """
        instance = self
        qs = OutcomeIndicator.objects.filter_by_model_type(instance)
        return qs


@receiver(pre_save, sender=IndicatorType)
def pre_save_indicator_type_receiver(sender, instance, *args, **kwargs):
    """
    Create a slug before save.
    :param sender: Signal sending object
    :param instance: Object instance
    :param args: Any other argument
    :param kwargs: Keyword arguments
    :return: None
    :rtype: None
    """
    if not instance.slug:
        instance.slug = create_slug(instance, IndicatorType, instance.indicator_type)


class Subpillar(AuthUserDetail, CreateUpdateTime):
{'fraction_non_alphanumeric': 0.07672552166934189, 'fraction_numerical': 0.002568218298555377, 'mean_word_length': 3.9381933438985737, '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': '4420743', 'n_tokens_mistral': 903, 'n_tokens_neox': 899, 'n_words': 224}