# Path: formunculous/fields.py
# class HoneypotField(Field):
#     """
#     Creates a hidden text input field, that when validated, if the
#     field has a different value in it than when initialized, the form
#     is invalid.  This is used to stop simple SPAM bots.
#     """
# 
#     widget = HoneypotWidget
# 
#     def clean(self, value):
# 
#         # If the value is empty or changed from the initial
#         # invalidate the field.
#         if (self.initial in EMPTY_VALUES and value \
#             in EMPTY_VALUES) or value == self.initial:
#             return value
# 
#         raise ValidationError('Honeypot field changed in value.')
# 
# class MultipleChoiceToStringField(MultipleChoiceField):
# 
#     def clean(self, value):
# 
#         super(MultipleChoiceToStringField, self).clean(value)
#         return ' | '.join(value)


from django import forms
from django.db import models
from django.utils.safestring import mark_safe
from django.forms.util import ErrorList
from django.contrib.auth.models import User
from formunculous.models import *
from formunculous.fields import HoneypotField, MultipleChoiceToStringField
from django.utils.translation import ugettext as _
from django.forms import ModelForm
from django.forms.widgets import RadioSelect, Select, SelectMultiple, CheckboxSelectMultiple, HiddenInput
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.forms.formsets import BaseFormSet, TOTAL_FORM_COUNT, INITIAL_FORM_COUNT, ORDERING_FIELD_NAME, DELETION_FIELD_NAME, ManagementForm
import formunculous.models as funcmodels
    import django
                    widget = RadioSelect

                if field_def.multi_select:
                    form_field = MultipleChoiceToStringField(
                        choices = choices, widget = widget)
                else:
                    form_field = forms.ChoiceField(choices=choices,
                                             widget = widget)
            else:
                form_field = field_model._meta.get_field('value').formfield()
                # Custom field widgets
                if field_model.widget:
                    attrs = form_field.widget.attrs
                    form_field.widget = field_model.widget(attrs = attrs)

            form_field.required = False # Will check required on final submission
            form_field.label = mark_safe(field_def.label)
            form_field.initial = data
            form_field.help_text = mark_safe(field_def.help_text)

            # Add it to the growing fieldset
            self.fields[field_def.slug] = form_field
            
        # Create a honeypot field automatically
        if not self.fields.has_key('company'):
            self.fields['company'] = HoneypotField()
        else:
            i = 0
            while self.fields.has_key('company%s' % i):
                i+=1

# Path: formunculous/fields.py
# class HoneypotField(Field):
#     """
#     Creates a hidden text input field, that when validated, if the
#     field has a different value in it than when initialized, the form
#     is invalid.  This is used to stop simple SPAM bots.
#     """
# 
#     widget = HoneypotWidget
# 
#     def clean(self, value):
# 
#         # If the value is empty or changed from the initial
#         # invalidate the field.
#         if (self.initial in EMPTY_VALUES and value \
#             in EMPTY_VALUES) or value == self.initial:
#             return value
# 
#         raise ValidationError('Honeypot field changed in value.')
# 
# class MultipleChoiceToStringField(MultipleChoiceField):
# 
#     def clean(self, value):
# 
#         super(MultipleChoiceToStringField, self).clean(value)
#         return ' | '.join(value)


# Path: formunculous/forms.py
from django import forms
from django.db import models
from django.utils.safestring import mark_safe
from django.forms.util import ErrorList
from django.contrib.auth.models import User
from formunculous.models import *
from formunculous.fields import HoneypotField, MultipleChoiceToStringField
from django.utils.translation import ugettext as _
from django.forms import ModelForm
from django.forms.widgets import RadioSelect, Select, SelectMultiple, CheckboxSelectMultiple, HiddenInput
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.forms.formsets import BaseFormSet, TOTAL_FORM_COUNT, INITIAL_FORM_COUNT, ORDERING_FIELD_NAME, DELETION_FIELD_NAME, ManagementForm
import formunculous.models as funcmodels
    import django

                    widget = RadioSelect

                if field_def.multi_select:
                    form_field = MultipleChoiceToStringField(
                        choices = choices, widget = widget)
                else:
                    form_field = forms.ChoiceField(choices=choices,
                                             widget = widget)
            else:
                form_field = field_model._meta.get_field('value').formfield()
                # Custom field widgets
                if field_model.widget:
                    attrs = form_field.widget.attrs
                    form_field.widget = field_model.widget(attrs = attrs)

            form_field.required = False # Will check required on final submission
            form_field.label = mark_safe(field_def.label)
            form_field.initial = data
            form_field.help_text = mark_safe(field_def.help_text)

            # Add it to the growing fieldset
            self.fields[field_def.slug] = form_field
            
        # Create a honeypot field automatically
        if not self.fields.has_key('company'):
            self.fields['company'] = HoneypotField()
        else:
            i = 0
            while self.fields.has_key('company%s' % i):
                i+=1

            self.fields['company%s' % i] = HoneypotField()