<commit_before>from django.utils.translation import ugettext as _
from django.core.exceptions import ValidationError
from django.db import models

import re

class ShortNameField(models.SlugField):
    """ Short name field used by several of the core models.

    We have a hierarchy of objects with a short name, but they are not
    strictly equal (eg. we cannot use a superclass because Subject has a
    unique short_name).
    """
    patt = re.compile(r'^[a-z0-9_-]+$')
    def __init__(self, *args, **kwargs):
        kw = dict(
            max_length = 20,
            verbose_name = _('Short name'),
            db_index = True,
            help_text=_(
                "Max 20 characters. Only numbers, lowercase characters, '_' " \
                    "and '-'. " ))
        kw.update(kwargs)
        super(ShortNameField, self).__init__(*args, **kw)

    def validate(self, value, *args, **kwargs):
        super(ShortNameField, self).validate(value, *args, **kwargs)
        if not self.patt.match(value):
            raise ValidationError(_(
                "Can only contain numbers, lowercase letters, '_' and '-'. "))


class LongNameField(models.CharField):
    def __init__(self, *args, **kwargs):
        kw = dict(max_length=100,
            verbose_name='Long name',
            db_index = True,
            help_text=_(
                'A longer name, more descriptive than "Short name". '\
                'This is the name visible to students.'))
        kw.update(kwargs)
        super(LongNameField, self).__init__(*args, **kw)<commit_msg>apps.core.models.custom_db_fields: Added South introspection rules.<commit_after>from django.utils.translation import ugettext as _
from django.core.exceptions import ValidationError
from django.db import models
from south.modelsinspector import add_introspection_rules

import re

class ShortNameField(models.SlugField):
    """ Short name field used by several of the core models.

    We have a hierarchy of objects with a short name, but they are not
    strictly equal (eg. we cannot use a superclass because Subject has a
    unique short_name).
    """
    patt = re.compile(r'^[a-z0-9_-]+$')
    def __init__(self, *args, **kwargs):
        kw = dict(
            max_length = 20,
            verbose_name = _('Short name'),
            db_index = True,
            help_text=_(
                "Max 20 characters. Only numbers, lowercase characters, '_' " \
                    "and '-'. " ))
        kw.update(kwargs)
        super(ShortNameField, self).__init__(*args, **kw)

    def validate(self, value, *args, **kwargs):
        super(ShortNameField, self).validate(value, *args, **kwargs)
        if not self.patt.match(value):
            raise ValidationError(_(
                "Can only contain numbers, lowercase letters, '_' and '-'. "))


class LongNameField(models.CharField):
    def __init__(self, *args, **kwargs):
        kw = dict(max_length=100,
            verbose_name='Long name',
            db_index = True,
            help_text=_(
                'A longer name, more descriptive than "Short name". '\
                'This is the name visible to students.'))
        kw.update(kwargs)
        super(LongNameField, self).__init__(*args, **kw)


add_introspection_rules([
    ([ShortNameField], [], {}),
], ["^devilry\.apps\.core\.models\.custom_db_fields\.ShortNameField"])
add_introspection_rules([
    ([LongNameField], [], {}),
], ["^devilry\.apps\.core\.models\.custom_db_fields\.LongNameField"])
{'fraction_non_alphanumeric': 0.12050256996002284, 'fraction_numerical': 0.005139920045688178, 'mean_word_length': 2.5100200400801604, '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': '2557146', 'n_tokens_mistral': 1041, 'n_tokens_neox': 984, 'n_words': 287}