<commit_before>"""Models used by django-watson."""

from __future__ import unicode_literals

import uuid

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import python_2_unicode_compatible, force_text
from django.utils.functional import cached_property

try:
    from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError:
    from django.contrib.contenttypes.generic import GenericForeignKey


def has_int_pk(model):
    """Tests whether the given model has an integer primary key."""
    pk = model._meta.pk
    return (
        (
            isinstance(pk, (models.IntegerField, models.AutoField)) and
            not isinstance(pk, models.BigIntegerField)
        ) or (
            isinstance(pk, models.ForeignKey) and has_int_pk(pk.remote_field.model)
        )
    )<commit_msg>Adding support for Django 2.0 BigAutoField. Closes #238.<commit_after>"""Models used by django-watson."""

from __future__ import unicode_literals

import uuid

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import python_2_unicode_compatible, force_text
from django.utils.functional import cached_property

try:
    from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError:
    from django.contrib.contenttypes.generic import GenericForeignKey


INTEGER_FIELDS = (models.IntegerField, models.AutoField,)
BIG_INTEGER_FIELDS = (models.BigIntegerField,)

try:
    BIG_INTEGER_FIELDS += (models.BigAutoField,)
except AttributeError:  # Django < 2.0.
    pass


def has_int_pk(model):
    """Tests whether the given model has an integer primary key."""
    pk = model._meta.pk
    return (
        isinstance(pk, INTEGER_FIELDS) and
        not isinstance(pk, BIG_INTEGER_FIELDS)
    ) or (
        isinstance(pk, models.ForeignKey) and has_int_pk(pk.remote_field.model)
    )
{'fraction_non_alphanumeric': 0.07917737789203085, 'fraction_numerical': 0.004627249357326478, 'mean_word_length': 4.107611548556431, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6370292', 'n_tokens_mistral': 572, 'n_tokens_neox': 548, 'n_words': 149}