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 = self.field_key(field) gfield_key = self.form.slug + "." + field_key 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() if field.remember and self.session: if not isinstance(value, str): self.session[gfield_key] = value.__str__() else: self.session[gfield_key] = value 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
def clean_pricing_option(self): pricing_pk = int(self.cleaned_data['pricing_option']) pricing_option = self.form.pricing_set.get(pk=pricing_pk) custom_price = self.data.get('custom_price_%s' % pricing_pk) # if not price set if not pricing_option.price: # then price is custom if not custom_price: # custom price has a value raise forms.ValidationError(_("Please set your price.")) try: # custom price is valid amount custom_price = currency_check(custom_price) except: raise forms.ValidationError(_("Price must be a valid amount")) self.cleaned_data['custom_price'] = custom_price return pricing_option
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
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
def get_discounted_prices(self): prices = self.cleaned_data['prices'] price_list = [currency_check(price) for price in prices.split(';')] return assign_discount(price_list, self.discount)