Esempio n. 1
0
 def __init__(self, contactFormInstance, request, *args, **kwargs):
     super(ContactFormPlus, self).__init__(*args, **kwargs)
     if 'instance' not in kwargs:
         for extraField in contactFormInstance.extrafield_set.all():
             if extraField.fieldType == 'CharField':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'BooleanField':
                 self.fields[slugify(extraField.label)] = forms.BooleanField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'EmailField':
                 self.fields[slugify(extraField.label)] = forms.EmailField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'DecimalField':
                 self.fields[slugify(extraField.label)] = forms.DecimalField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'FloatField':
                 self.fields[slugify(extraField.label)] = forms.FloatField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'FileField': 
                 self.fields[slugify(extraField.label)] = forms.FileField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'ImageField': 
                 self.fields[slugify(extraField.label)] = forms.ImageField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'IntegerField':
                 self.fields[slugify(extraField.label)] = forms.IntegerField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'IPAddressField':
                 self.fields[slugify(extraField.label)] = forms.IPAddressField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'auto_Textarea':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         widget=forms.Textarea,
                         required=extraField.required)
             elif extraField.fieldType == 'auto_hidden_input':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'auto_referral_page':
                 lInitial = _("No referral available.")
                 if request:
                     lInitial = request.META.get('HTTP_REFERER', _('No referral available.'))
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=lInitial,  # NOTE: This overwrites extraField.initial!
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'MathCaptcha':
                 self.fields[slugify(extraField.label)] = MathCaptchaField(
                                             label=extraField.label,
                                             initial=extraField.initial,
                                             required=True)
             elif extraField.fieldType == 'ReCaptcha':
                 self.fields[slugify(extraField.label)] = ReCaptchaField(
                                             label=extraField.label,
                                             initial=extraField.initial,
                                             required=True)
             elif extraField.fieldType == 'auto_GET_parameter':
                 lInitial = _("Key/value parameter not available.")
                 if request:
                     lInitial = request.GET.get(slugify(extraField.label), 'n/a')
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=lInitial,  # NOTE: This overwrites extraField.initial!
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'CharFieldWithValidator':
                 self.fields[slugify(extraField.label)] = forms.CharField(
                     label=extraField.label,
                     initial=extraField.initial,
                     required=extraField.required,
                     validators=get_validators())
 def __init__(self, contactFormInstance, request, *args, **kwargs):
     super(ContactFormPlus, self).__init__(*args, **kwargs)
     if 'instance' not in kwargs:
         for extraField in contactFormInstance.extrafield_set.all():
             if extraField.fieldType == 'CharField':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'BooleanField':
                 self.fields[slugify(extraField.label)] = forms.BooleanField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'EmailField':
                 self.fields[slugify(extraField.label)] = forms.EmailField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'DecimalField':
                 self.fields[slugify(extraField.label)] = forms.DecimalField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'FloatField':
                 self.fields[slugify(extraField.label)] = forms.FloatField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'FileField': 
                 self.fields[slugify(extraField.label)] = forms.FileField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'ImageField': 
                 self.fields[slugify(extraField.label)] = forms.ImageField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'IntegerField':
                 self.fields[slugify(extraField.label)] = forms.IntegerField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'IPAddressField':
                 self.fields[slugify(extraField.label)] = forms.IPAddressField(label=extraField.label,
                         initial=extraField.initial,
                         required=extraField.required)
             elif extraField.fieldType == 'auto_Textarea':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         widget=forms.Textarea,
                         required=extraField.required)
             elif extraField.fieldType == 'auto_hidden_input':
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=extraField.initial,
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'auto_referral_page':
                 lInitial = _("No referral available.")
                 if request:
                     lInitial = request.META.get('HTTP_REFERER', _('No referral available.'))
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=lInitial,  # NOTE: This overwrites extraField.initial!
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'MathCaptcha':
                 self.fields[slugify(extraField.label)] = MathCaptchaField(
                                             label=extraField.label,
                                             initial=extraField.initial,
                                             required=True)
             elif extraField.fieldType == 'ReCaptcha':
                 self.fields[slugify(extraField.label)] = ReCaptchaField(
                                             label=extraField.label,
                                             initial=extraField.initial,
                                             required=True)
             elif extraField.fieldType == 'auto_GET_parameter':
                 lInitial = _("Key/value parameter not available.")
                 if request:
                     lInitial = request.GET.get(slugify(extraField.label), 'n/a')
                 self.fields[slugify(extraField.label)] = forms.CharField(label=extraField.label,
                         initial=lInitial,  # NOTE: This overwrites extraField.initial!
                         widget=forms.HiddenInput,
                         required=False)
             elif extraField.fieldType == 'CharFieldWithValidator':
                 self.fields[slugify(extraField.label)] = forms.CharField(
                     label=extraField.label,
                     initial=extraField.initial,
                     required=extraField.required,
                     validators=get_validators())