# Path: django_core/forms/widgets.py
# class CommaSeparatedListWidget(TextInput):
#     """Widget for rendering a comma separated list using a text field."""
# 
#     def __init__(self, *args, **kwargs):
#         super(CommaSeparatedListWidget, self).__init__(*args, **kwargs)
# 
#     def render(self, name, value, attrs=None):
#         if isinstance(value, (list, tuple)):
#             # It's a list, join the values for display
#             value = ', '.join(map(str, value))
# 
#         return super(CommaSeparatedListWidget, self).render(name=name,
#                                                             value=value,
#                                                             attrs=attrs)
# 
#     def value_from_datadict(self, data, files, name, **kwargs):
#         value = super(CommaSeparatedListWidget,
#                       self).value_from_datadict(data=data, files=files,
#                                                 name=name, **kwargs)
# 
#         if value and isinstance(value, string_types):
#             return [item.strip() for item in value.split(',') if item.strip()]
# 
#         return value
# 
# 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 django.test.testcases import TestCase
from django_core.forms.widgets import CommaSeparatedListWidget
from django_core.forms.widgets import MultipleDecimalInputWidget


class CommaSeparatedListWidgetTestCase(TestCase):

    def test_widget_value_from_datadict(self):
        field_name = 'some_field'
        data = {field_name: '1,4, 5 , hello'}
        widget = CommaSeparatedListWidget()
        value = widget.value_from_datadict(data=data, files={},
                                           name=field_name)
        self.assertEqual(value, ['1', '4', '5', 'hello'])

    def test_widget_value_from_datadict_ints(self):
        field_name = 'some_field'
        data = {field_name: '1,4,5'}

# Path: django_core/forms/widgets.py
# class CommaSeparatedListWidget(TextInput):
#     """Widget for rendering a comma separated list using a text field."""
# 
#     def __init__(self, *args, **kwargs):
#         super(CommaSeparatedListWidget, self).__init__(*args, **kwargs)
# 
#     def render(self, name, value, attrs=None):
#         if isinstance(value, (list, tuple)):
#             # It's a list, join the values for display
#             value = ', '.join(map(str, value))
# 
#         return super(CommaSeparatedListWidget, self).render(name=name,
#                                                             value=value,
#                                                             attrs=attrs)
# 
#     def value_from_datadict(self, data, files, name, **kwargs):
#         value = super(CommaSeparatedListWidget,
#                       self).value_from_datadict(data=data, files=files,
#                                                 name=name, **kwargs)
# 
#         if value and isinstance(value, string_types):
#             return [item.strip() for item in value.split(',') if item.strip()]
# 
#         return value
# 
# 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: tests/test_form_widgets.py
from django.test.testcases import TestCase
from django_core.forms.widgets import CommaSeparatedListWidget
from django_core.forms.widgets import MultipleDecimalInputWidget



class CommaSeparatedListWidgetTestCase(TestCase):

    def test_widget_value_from_datadict(self):
        field_name = 'some_field'
        data = {field_name: '1,4, 5 , hello'}
        widget = CommaSeparatedListWidget()
        value = widget.value_from_datadict(data=data, files={},
                                           name=field_name)
        self.assertEqual(value, ['1', '4', '5', 'hello'])

    def test_widget_value_from_datadict_ints(self):
        field_name = 'some_field'
        data = {field_name: '1,4,5'}

        widget = CommaSeparatedListWidget()