Beispiel #1
0
    def save(self, **kwargs):
        """
        Create a FormEntry instance and related FieldEntry instances for each
        form field.
        """
        entry = super(FormForForm, self).save(commit=False)
        entry.form = self.form
        entry.entry_time = datetime.now()
        entry.save()
        for field in self.form_fields:
            field_key = "field_%s" % field.id
            value = self.cleaned_data[field_key]
            if value and self.fields[field_key].widget.needs_multipart_form:
                value = default_storage.save(join("forms", str(uuid4()), value.name), value)
            # if the value is a list convert is to a comma delimited string
            if isinstance(value,list):
                value = ','.join(value)
            if not value: value=''
            field_entry = FieldEntry(field_id = field.id, entry=entry, value = value)
            field_entry.save()

        # save selected pricing and payment method if any
        if (self.form.custom_payment or self.form.recurring_payment) and self.form.pricing_set.all():
            entry.payment_method = self.cleaned_data['payment_option']
            entry.pricing = self.cleaned_data['pricing_option']
            entry.save()

        return entry
Beispiel #2
0
    def save(self, **kwargs):
        """
        Create a FormEntry instance and related FieldEntry instances for each
        form field.
        """
        entry = super(FormForForm, self).save(commit=False)
        entry.form = self.form
        entry.entry_time = datetime.now()
        entry.save()
        for field in self.form_fields:
            field_key = "field_%s" % field.id
            value = self.cleaned_data[field_key]
            if value and self.fields[field_key].widget.needs_multipart_form:
                value = default_storage.save(
                    join("forms", str(uuid4()), value.name), value)
            # if the value is a list convert is to a comma delimited string
            if isinstance(value, list):
                value = ','.join(value)
            if not value: value = ''
            field_entry = FieldEntry(field_id=field.id,
                                     entry=entry,
                                     value=value)
            field_entry.save()

        for field in self.auto_fields:
            value = field.choices
            field_entry = FieldEntry(field_id=field.id,
                                     entry=entry,
                                     value=value)
            field_entry.save()

        # save selected pricing and payment method if any
        if (self.form.custom_payment or
                self.form.recurring_payment) and self.form.pricing_set.all():
            entry.payment_method = self.cleaned_data['payment_option']
            entry.pricing = self.cleaned_data['pricing_option']
            custom_price = self.data.get('custom_price_%s' % entry.pricing.id)
            if custom_price:
                entry.custom_price = currency_check(custom_price)
            entry.save()

        return entry
Beispiel #3
0
    def save(self, **kwargs):
        """
        Create a FormEntry instance and related FieldEntry instances for each
        form field.
        """
        entry = super(FormForForm, self).save(commit=False)
        entry.form = self.form
        entry.entry_time = datetime.now()
        entry.save()
        for field in self.form_fields:
            field_key = "field_%s" % field.id
            value = self.cleaned_data[field_key]
            if value and self.fields[field_key].widget.needs_multipart_form:
                value = default_storage.save(join("forms", str(uuid4()), value.name), value)
            # if the value is a list convert is to a comma delimited string
            if isinstance(value,list):
                value = ','.join(value)
            if not value: value=''
            
            # make links not clickable if submitted by non-interactive user
            if isinstance(value, str) and (self.user.is_anonymous or not self.user.is_active):
                p = re.compile(r'(http[s]?)://([^\.]+)\.([^\./]+)')
                value = re.subn(p, r'\1 : // \2 . \3 ', value)[0][:FIELD_MAX_LENGTH]
            field_entry = FieldEntry(field_id = field.id, entry=entry, value = value)
            field_entry.save()

        for field in self.auto_fields:
            value = field.choices
            field_entry = FieldEntry(field_id = field.id, entry=entry, value=value)
            field_entry.save()

        # save selected pricing and payment method if any
        if (self.form.custom_payment or self.form.recurring_payment) and self.form.pricing_set.all():
            entry.payment_method = self.cleaned_data['payment_option']
            entry.pricing = self.cleaned_data['pricing_option']
            custom_price = self.data.get('custom_price_%s' % entry.pricing.id)
            if custom_price:
                entry.custom_price = currency_check(custom_price)
            entry.save()

        return entry