class GenericBestBuyForm(BestBuyForm): """ Easy Access, Notice Accounts, Over 50s """ monthly_deposit = CurrencyField( widget=CurrencyInput(attrs={'class': 'text'}), required=False, initial=Decimal('0.00')) tax_rate = forms.ChoiceField(choices=ACCOUNT_TYPE_CHOICES, required=False) def clean(self): """ At least the initial deposity or the monthly deposit have to have a value """ super(GenericBestBuyForm, self).clean() data = self.cleaned_data monthly = data.get('monthly_deposit', 0) initial = data.get('initial_deposit', 0) if monthly in EMPTY_VALUES: data['monthly_deposit'] = 0 if initial in EMPTY_VALUES: data['initial_deposit'] = 0 if monthly <= 0 and initial <= 0: self._errors["initial_deposit"] = self.error_class( ["Please enter a monthly or initial deposit"]) raise forms.ValidationError( "Please enter a value for the Best Buy Tool") return data
class AddFixedProductForm(forms.Form): formattrs = { 'required': '', 'class': 'email', 'placeholder': 'Enter your email address' } email = forms.EmailField( widget=Html5EmailInput(attrs=dict(formattrs, maxlength=75)), label="Email", required=True) fixed_provider = forms.ModelChoiceField( Provider.objects.all(), empty_label='Select provider', widget=forms.Select( attrs={'class': 'required number fixedproviderselect'}), label="Provider") account_type = forms.ChoiceField( choices=_get_fixed_bestbuys(), widget=forms.Select(attrs={'class': 'required number account-type'})) balance = CurrencyField( widget=CurrencyInput(attrs={'class': 'text commaNumber'}), initial=1) rate = forms.DecimalField( widget=CurrencyInput(attrs={'class': 'text commaNumber'}), initial=0, max_digits=3, decimal_places=2) maturity_date = forms.DateField(widget=MonthYearWidget( attrs={ 'class': 'number datefield', 'min': '1' }, years=_get_maturity_years()), required=True) def __init__(self, *args, **kwargs): super(AddFixedProductForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.field_class = 'col-lg-8' self.helper.label_class = 'col-lg-4' self.helper.form_class = 'form-horizontal' self.helper.form_tag = False self.helper.add_input(Submit(name='add_product', value='Add Product')) def clean(self): return self.cleaned_data
class AddFixedProductForm(forms.Form): fixed_provider = forms.ModelChoiceField( queryset=Provider.objects.all(), empty_label='Select provider', widget=ModelSelect2Widget(attrs={ 'class': 'required number fixedproviderselect', 'style': 'width:100%!important;' }, search_fields=['title']), label="Provider", required=True) account_type = forms.ChoiceField( choices=_get_fixed_bestbuys(), widget=forms.Select( attrs={ 'class': 'required number account-type form-control', 'min': '1', 'style': 'width:100%!important;', 'required': True }), required=True) balance = CurrencyField(widget=CurrencyInput( attrs={ 'class': 'text commaNumber form-control', 'style': 'width:100%!important;', 'required': True }), initial=1, required=True) rate = forms.DecimalField(widget=forms.NumberInput(attrs={ 'class': 'form-control', 'required': True }), max_digits=3, decimal_places=2, initial=0, required=True) maturity_date = forms.DateField(widget=MonthYearWidget( attrs={ 'class': 'number datestyle form-control', 'min': '1', 'required': True }, years=_get_maturity_years()), required=True) def clean(self): return self.cleaned_data def __init__(self, *args, **kwargs): super(AddFixedProductForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = False self.helper.layout = Layout( u'fixed_provider', u'account_type', PrependedText(u'balance', u'£', placeholder=1), u'rate', u'maturity_date')
class BestBuyForm(forms.Form): initial_deposit = CurrencyField( widget=CurrencyInput(attrs={'class': 'text'}), required=False, initial=Decimal('0.00')) def __init__(self, *args, **kwargs): super(BestBuyForm, self).__init__(*args, **kwargs) self.is_over_threshold = False def clean(self): data = self.cleaned_data initial_deposit = data.get('initial_deposit', 0) self.is_over_threshold = initial_deposit > BESTBUY_THRESHOLD return data
class HealthcheckSignUpForm(SignUpForm): first_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'required form-control', 'max_length': 100})) surname = forms.CharField(widget=forms.TextInput(attrs={'class': 'required form-control', 'max_length': 100})) password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'text required form-control'}), required=True) telephone = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'max_length': 100}), required=False) provider = forms.ModelChoiceField(queryset=Provider.objects.all(), empty_label='Select provider', required=False, widget=ModelSelect2Widget( attrs={'class': 'number providerselect', 'style': 'width:100%!important;'})) balance = CurrencyField(widget=CurrencyInput( attrs={'class': 'commaNumber balanceinput form-control', 'style': 'width:100%!important;'}), required=False, initial=1) product = forms.IntegerField( widget=Select2Widget(attrs={'class': 'text productselect', 'min': '1', 'style': 'width:100%!important;'}), required=False) opening_date = forms.DateField( widget=MonthYearWidget(attrs={'class': 'datestyle number', 'min': '1'}, years=_get_opening_years()), required=False) extra_field_count = forms.CharField(widget=forms.HiddenInput()) maturity_date = forms.DateField( widget=MonthYearWidget(attrs={'class': 'datestyle number', 'min': '1'}, years=_get_maturity_years()), required=False) account_type = forms.ChoiceField( widget=Select2Widget(attrs={'class': 'accounttype number', 'style': 'width:100%!important;'}), choices=_get_fixed_bestbuys(), required=False) is_fixed = forms.BooleanField(widget=forms.HiddenInput(attrs={'class': 'fixedindicator'}), required=False) def __init__(self, *args, **kwargs): extra_fields = kwargs.pop('extra', 0) super(HealthcheckSignUpForm, self).__init__(*args, **kwargs) self.fields['extra_field_count'].initial = extra_fields for index in xrange(int(extra_fields)): self.fields['provider_field_%i' % index] = forms.IntegerField(required=False) self.fields['balance_field_%i' % index] = CurrencyField( widget=CurrencyInput(attrs={'class': 'commaNumber balanceinput form-control'}), required=False, initial=1) self.fields['product_field_%i' % index] = forms.IntegerField(required=False) self.fields['opening_date_month_field_%i' % index] = forms.IntegerField(required=False) self.fields['opening_date_year_field_%i' % index] = forms.IntegerField(required=False) self.fields['maturity_date_month_field_%i' % index] = forms.IntegerField(required=False) self.fields['maturity_date_year_field_%i' % index] = forms.IntegerField(required=False) self.fields['account_type_field_%i' % index] = forms.IntegerField(required=False) self.fields['is_fixed_field_%i' % index] = forms.BooleanField(required=False) self.helper = FormHelper() def clean(self): return self.cleaned_data
def __init__(self, *args, **kwargs): extra_fields = kwargs.pop('extra', 0) super(HealthcheckSignUpForm, self).__init__(*args, **kwargs) self.fields['extra_field_count'].initial = extra_fields for index in xrange(int(extra_fields)): self.fields['provider_field_%i' % index] = forms.IntegerField(required=False) self.fields['balance_field_%i' % index] = CurrencyField( widget=CurrencyInput(attrs={'class': 'commaNumber balanceinput form-control'}), required=False, initial=1) self.fields['product_field_%i' % index] = forms.IntegerField(required=False) self.fields['opening_date_month_field_%i' % index] = forms.IntegerField(required=False) self.fields['opening_date_year_field_%i' % index] = forms.IntegerField(required=False) self.fields['maturity_date_month_field_%i' % index] = forms.IntegerField(required=False) self.fields['maturity_date_year_field_%i' % index] = forms.IntegerField(required=False) self.fields['account_type_field_%i' % index] = forms.IntegerField(required=False) self.fields['is_fixed_field_%i' % index] = forms.BooleanField(required=False) self.helper = FormHelper()
class PortfolioEditForm(forms.Form): id = forms.IntegerField( widget=forms.HiddenInput(attrs={'class': 'portfolioeditid'}), required=True) balance = CurrencyField(widget=CurrencyInput( attrs={ 'class': 'commaNumber minComma editbalance form-control', 'min': 1 })) def clean(self): balance = self.cleaned_data.get('balance', False) if balance < 1: return False return self.cleaned_data def __init__(self): super(PortfolioEditForm, self).__init__() self.form_helper = FormHelper() self.form_helper.form_tag = False self.form_helper.layout = Layout('id', PrependedText('balance', '£'))
class AddProductsForm(forms.Form): formattrs = { 'required': '', 'class': 'email', 'placeholder': 'Enter your email address' } email = forms.EmailField( widget=Html5EmailInput(attrs=dict(formattrs, maxlength=75)), label="Email") provider = forms.ModelChoiceField( Provider.objects.all(), empty_label='Select provider', widget=forms.Select(attrs={'class': 'required number providerselect'})) balance = CurrencyField( widget=CurrencyInput(attrs={'class': 'text commaNumber balanceinput'}), initial=1) product = forms.IntegerField(widget=forms.Select(attrs={ 'class': 'text productselect', 'min': '1' }), required=False) opening_date = forms.DateField(widget=MonthYearWidget( attrs={'class': 'number datefield'}, years=_get_years()), required=False) def __init__(self, *args, **kwargs): super(AddProductsForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.field_class = 'col-lg-8' self.helper.label_class = 'col-lg-4' self.helper.form_class = 'form-horizontal' self.helper.form_tag = False self.helper.add_input(Submit(name='add_product', value='Add Product')) def clean(self): return self.cleaned_data
class RateTrackerForm(forms.Form): """ When the user is searching if they specify a Fixed Rate Bond type, the Account Name is not applicable and not required. """ provider = forms.ModelChoiceField( Provider.objects.all().exclude( title="Kent Reliance Building Society").exclude( title="Sainsbury's Finance"), empty_label='Provider', widget=forms.Select(attrs={'class': 'required number'})) account_type = forms.ChoiceField( widget=forms.Select(attrs={'class': 'required number'}), choices=_get_rt_account_type_choices()) balance = CurrencyField( widget=CurrencyInput(attrs={'class': 'text required commaNumber'}), initial=Decimal('1')) product = forms.IntegerField( widget=forms.TextInput(attrs={'class': 'text required'}), required=False) maturity_date = forms.DateField(widget=MonthYearWidget( years=_get_maturity_years(), attrs={'min': '1'}), required=False) def __init__(self, *args, **kwargs): super(RateTrackerForm, self).__init__(*args, **kwargs) self.set_reminder = False self.high_balance = False def in_bestbuy_list(self, account_type): for val in get_maturity_based_bestbuys().values('id'): if account_type == val['id']: return True return False def clean(self): super(RateTrackerForm, self).clean() data = self.cleaned_data account_type = data.get('account_type', None) balance = data.get('balance', None) if account_type in EMPTY_VALUES: self.errors['account_type'] = 'Please enter an account type' return if self.in_bestbuy_list(int(account_type)): # Maturity date is a required field self.set_reminder = True maturity_date = data.get('maturity_date', None) if maturity_date in EMPTY_VALUES: self.errors['maturity_date'] = 'Please enter a maturity date' else: today = datetime.datetime.date(datetime.datetime.now()) if maturity_date < today: self.errors[ 'maturity_date'] = 'Please enter a maturity date in the future' else: # we need either product or maturity date to be populated product = data.get('product', None) if product in EMPTY_VALUES: self.errors['product'] = 'Please choose an Account Name' if balance in EMPTY_VALUES or balance <= 0: self.errors['balance'] = 'Please enter your balance' return data
class TIMFixedRegistrationForm(forms.Form): """ When the user is searching if they specify a Fixed Rate Bond type, the Account Name is not applicable and not required. """ attrs_dict = {'required': ''} provider = forms.ModelChoiceField( Provider.objects.all().exclude( title="Kent Reliance Building Society").exclude( title="Sainsbury's Finance"), empty_label='Provider', widget=forms.Select(attrs={'class': 'number'}), required=False) account_type = forms.ChoiceField( widget=forms.Select(attrs={'class': 'number'}), choices=_get_rt_account_type_choices(), required=False) balance = CurrencyField( widget=CurrencyInput(attrs={'class': 'text commaNumber'}), initial=Decimal('1'), required=False) maturity_date = forms.DateField(widget=MonthYearWidget( years=_get_maturity_years(), attrs={'min': '1'}), required=False) email = forms.EmailField( widget=forms.TextInput(attrs={'class': 'required email'}), required=True) password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label="Password") first_name = forms.CharField( widget=forms.TextInput(attrs={'class': 'required'}), max_length=100) surname = forms.CharField( widget=forms.TextInput(attrs={'class': 'required'}), max_length=100) newsletter = forms.BooleanField( label="I would like to receive the Savings Champion newsletter", required=False, initial=True) ratealerts = forms.BooleanField( label="I would like to receive the Savings Champion Rate Alerts email", required=False, initial=True) source = forms.CharField(required=False, widget=forms.HiddenInput()) username = forms.CharField(label="Username", max_length=30, min_length=6, widget=forms.HiddenInput(), required=False) helper = FormHelper() helper.add_input( Submit('Submit', 'Submit', src=static('img/register.png'), type='image')) def __init__(self, *args, **kwargs): super(TIMFixedRegistrationForm, self).__init__(*args, **kwargs) self.helper.form_action = reverse('tim_fixed_register') def clean_username(self): return MakeUsername() def save(self, request): email = self.cleaned_data('email') user, user_created, record_stats = create_stage_one_profile( request, email=email, source=self.cleaned_data.get('source')) tim_signup, _ = TiMSignups.objects.get_or_create(email=user.email) user.profile.newsletter = self.cleaned_data.get('newsletter', False) user.profile.ratealerts = self.cleaned_data.get('ratealerts', False) if RateAlertsSignup.objects.filter(email=user.email).exists(): user.profile.ratealerts = True if NewsletterSignup.objects.filter(email=user.email).exists(): user.profile.newsletter = True user.profile.is_synched = False user.profile.skeleton_user = False user.profile.save() # add the fixed rate product provider = request.POST['provider'] balance = request.POST['balance'] account_type = request.POST['account_type'] if account_type != '' and provider != '' and balance != '': bestbuy = BestBuy.objects.get(id=account_type) reminder = RatetrackerReminder() reminder.user = user reminder.account_type = bestbuy reminder.balance = balance reminder.provider = Provider.objects.get(id=provider) if 'maturity_date_month' not in request.POST and 'maturity_date_year' not in request.POST: product = Product.objects.get(pk=request.POST['product']) product_term = product.term if product.term is not None else 0 month = int(request.POST['opening_date_month']) year = int(request.POST['opening_date_year']) maturity_date = datetime.date( day=1, month=month, year=year) + datetime.timedelta(days=product_term) else: month = int(request.POST['maturity_date_month']) year = int(request.POST['maturity_date_year']) maturity_date = datetime.date(day=1, month=month, year=year) reminder.maturity_date = maturity_date reminder.is_synched = False reminder.save() return user
class RegularSavingsAccountForm(forms.Form): monthly_deposit = CurrencyField( widget=CurrencyInput(attrs={'class': 'text'}), required=True, initial=Decimal('0.00')) tax_rate = forms.ChoiceField(choices=ACCOUNT_TYPE_CHOICES, required=False)
class ChildrensAccountForm(BestBuyForm): monthly_deposit = CurrencyField( widget=CurrencyInput(attrs={'class': 'text'}), required=False, initial=Decimal('0.00'))
class VariableCashISABestBuyForm(BestBuyForm): monthly_deposit = CurrencyField( widget=CurrencyInput(attrs={'class': 'text'}), required=False, initial=Decimal('0.00'))