# Path: profiles/modules/codes/models.py
# class Code(models.Model):
#     """
#     Registration codes
#     """
#     code = models.CharField(max_length=255, unique=True)
#     is_active = models.BooleanField(default=True)
# 
#     class Meta:
#         app_label = 'profiles'
#         ordering = ('code',)
# 
#     def __unicode__(self):
#         return mark_safe(self.code)


import re
from django.core import exceptions
from django.forms import fields
from .models import Code




class CodeField(fields.CharField):
    def to_python(self, value):
        if not value:
            return value

        try:
            value = value.strip()
            value = Code.objects.get(code__iexact=value, is_active=True)

# Path: profiles/modules/codes/models.py
# class Code(models.Model):
#     """
#     Registration codes
#     """
#     code = models.CharField(max_length=255, unique=True)
#     is_active = models.BooleanField(default=True)
# 
#     class Meta:
#         app_label = 'profiles'
#         ordering = ('code',)
# 
#     def __unicode__(self):
#         return mark_safe(self.code)


# Path: profiles/modules/codes/fields.py
import re
from django.core import exceptions
from django.forms import fields
from .models import Code





class CodeField(fields.CharField):
    def to_python(self, value):
        if not value:
            return value

        try:
            value = value.strip()
            value = Code.objects.get(code__iexact=value, is_active=True)

        except Code.DoesNotExist: