# Path: django_core/forms/widgets.py
# class ChoiceAndCharInputWidget(ExtendedMultiWidget):
#     """Renders choice field and char field next to each other."""
# 
#     def __init__(self, choices=None, attrs=None, widgets=None,
#                  widget_css_class='choice-and-char-widget', **kwargs):
# 
#         if not attrs:
#             attrs = {}
# 
#         if not widgets:
#             widgets = (
#                 Select(choices=choices),
#                 TextInput()
#             )
# 
#         super(ChoiceAndCharInputWidget, self).__init__(
#             widgets=widgets,
#             attrs=attrs,
#             widget_css_class=widget_css_class,
#             **kwargs
#         )
# 
#     def decompress(self, value):
#         if value:
#             return value
# 
#         return [None, None]
# 
# Path: django_core/forms/widgets.py
# class MultipleDecimalInputWidget(ExtendedMultiWidget):
#     """Renders an input with 4 decimal fields."""
# 
#     def __init__(self, attrs=None, widgets=None, num_inputs=4, value_suffix='',
#                  widget_css_class='horizontal-widget multi-decimal-widget',
#                  **kwargs):
#         self.num_inputs = num_inputs
#         self.value_suffix = value_suffix
# 
#         if not attrs:
#             attrs = {}
# 
#         self.get_widget_css_class(attrs)
# 
#         if widgets is None:
#             widgets = tuple([NumberInput() for w in range(num_inputs)])
# 
#         super(MultipleDecimalInputWidget, self).__init__(
#             widgets=widgets,
#             attrs=attrs,
#             widget_css_class=widget_css_class,
#             **kwargs
#         )
# 
#     def decompress(self, value):
#         if value and self.value_suffix and isinstance(value, string_types):
#             value = value.replace(self.value_suffix, '')
# 
#         if value:
#             return value.split(' ')
# 
#         return [None for i in range(self.num_inputs)]
# 
#     def get_widget_css_class(self, attrs):
#         """Gets the class for the widget."""
#         size_class = 'size-{0}'.format(self.num_inputs)
# 
#         if 'class' in attrs:
#             attrs['class'] += ' {0}'.format(size_class)
#         else:
#             attrs['class'] = size_class


from copy import deepcopy
from django.core.exceptions import ValidationError
from django.forms.fields import CharField
from django.forms.fields import ChoiceField
from django.forms.fields import DecimalField
from django.forms.fields import MultiValueField
from django.utils.translation import ugettext as _
from django_core.forms.widgets import ChoiceAndCharInputWidget
from .widgets import MultipleDecimalInputWidget


class CommaSeparatedIntegerListField(CommaSeparatedListField):
    """Comma Separated Integer list field."""
    # TODO: this should honor:
    #    max_value (each item in the list can't be > this value)
    #    min_value (each item in the list can't be < this value)
    #    max_length (could be the number of items in the list)

    def to_python(self, value):
        value = super(CommaSeparatedIntegerListField, self).to_python(value)

        if isinstance(value, (list, tuple)):
            # Ensure all values are integers
            try:
                value = [int(item) for item in value]
            except:
                raise ValidationError('All values in list must be whole '
                                      'numbers.')
        return value


class MultipleDecimalField(MultiValueField):
    """A field with multiple decimal fields that should be converted to single
    line.

    Example response values:

    - "5px 0 5px 4px"
    """

# Path: django_core/forms/widgets.py
# class ChoiceAndCharInputWidget(ExtendedMultiWidget):
#     """Renders choice field and char field next to each other."""
# 
#     def __init__(self, choices=None, attrs=None, widgets=None,
#                  widget_css_class='choice-and-char-widget', **kwargs):
# 
#         if not attrs:
#             attrs = {}
# 
#         if not widgets:
#             widgets = (
#                 Select(choices=choices),
#                 TextInput()
#             )
# 
#         super(ChoiceAndCharInputWidget, self).__init__(
#             widgets=widgets,
#             attrs=attrs,
#             widget_css_class=widget_css_class,
#             **kwargs
#         )
# 
#     def decompress(self, value):
#         if value:
#             return value
# 
#         return [None, None]
# 
# Path: django_core/forms/widgets.py
# class MultipleDecimalInputWidget(ExtendedMultiWidget):
#     """Renders an input with 4 decimal fields."""
# 
#     def __init__(self, attrs=None, widgets=None, num_inputs=4, value_suffix='',
#                  widget_css_class='horizontal-widget multi-decimal-widget',
#                  **kwargs):
#         self.num_inputs = num_inputs
#         self.value_suffix = value_suffix
# 
#         if not attrs:
#             attrs = {}
# 
#         self.get_widget_css_class(attrs)
# 
#         if widgets is None:
#             widgets = tuple([NumberInput() for w in range(num_inputs)])
# 
#         super(MultipleDecimalInputWidget, self).__init__(
#             widgets=widgets,
#             attrs=attrs,
#             widget_css_class=widget_css_class,
#             **kwargs
#         )
# 
#     def decompress(self, value):
#         if value and self.value_suffix and isinstance(value, string_types):
#             value = value.replace(self.value_suffix, '')
# 
#         if value:
#             return value.split(' ')
# 
#         return [None for i in range(self.num_inputs)]
# 
#     def get_widget_css_class(self, attrs):
#         """Gets the class for the widget."""
#         size_class = 'size-{0}'.format(self.num_inputs)
# 
#         if 'class' in attrs:
#             attrs['class'] += ' {0}'.format(size_class)
#         else:
#             attrs['class'] = size_class


# Path: django_core/forms/fields.py
from copy import deepcopy
from django.core.exceptions import ValidationError
from django.forms.fields import CharField
from django.forms.fields import ChoiceField
from django.forms.fields import DecimalField
from django.forms.fields import MultiValueField
from django.utils.translation import ugettext as _
from django_core.forms.widgets import ChoiceAndCharInputWidget
from .widgets import MultipleDecimalInputWidget



class CommaSeparatedIntegerListField(CommaSeparatedListField):
    """Comma Separated Integer list field."""
    # TODO: this should honor:
    #    max_value (each item in the list can't be > this value)
    #    min_value (each item in the list can't be < this value)
    #    max_length (could be the number of items in the list)

    def to_python(self, value):
        value = super(CommaSeparatedIntegerListField, self).to_python(value)

        if isinstance(value, (list, tuple)):
            # Ensure all values are integers
            try:
                value = [int(item) for item in value]
            except:
                raise ValidationError('All values in list must be whole '
                                      'numbers.')
        return value


class MultipleDecimalField(MultiValueField):
    """A field with multiple decimal fields that should be converted to single
    line.

    Example response values:

    - "5px 0 5px 4px"
    """

    widget = MultipleDecimalInputWidget