def __init__(self, *args, **kwargs): self.request = kwargs.pop("request", None) self.account_type = kwargs.pop("account_type", None) super(CFHAccountForm, self).__init__(*args, **kwargs) if not self.account_type: return if self.account_type.leverage_choices: available_leverages = calculate_available_leverages( group=self.account_type, user=self.request and self.request.user.is_authenticated() and self.request.user, ) leverage_default = getattr(self.account_type, "leverage_default", None) if leverage_default not in available_leverages: leverage_default = available_leverages[0] leverage_choices = [(idx, '1:%i' % idx) for idx in available_leverages] self.fields["leverage"].choices = leverage_choices self.fields["leverage"].initial = leverage_default else: del self.fields["leverage"] if self.account_type.available_options & HAS_EXECUTION_OPTIONS: self.fields["execution_system"] = forms.ChoiceField( label=_("Execution system"), choices=execution_system_choices(self.account_type), widget=forms.RadioSelect(), initial=MARKET_EXECUTION, required=False) if self.account_type.available_options & HAS_CURRENCY_OPTIONS: self.fields["currency"] = forms.ChoiceField( label=_("Currency"), initial=currencies.USD, choices=default_currencies_from_type(self.account_type), required=False, ) # Initializing deposit fields, if account type requires deposit, # or removing it otherwise. if self.account_type.deposit is not None: self.fields["deposit"].initial = self.account_type.deposit else: del self.fields["deposit"] self.fields.update( get_accept_fields(self.request, self.account_type.agreements)) self.fields["account_type"] = make_hidden(self.account_type.slug)
def mutate(self): log.debug("Mutating form") assert hasattr(self, "instance") # Getting current active language, and falling back to # english version if native isn't available. language = get_language().upper() if language == "ZH-CN": language = "CN" if language not in \ "EN DE ES FR IT PL GR RO RU TR CN CZ NL DA SV FI".split(): language = "EN" log.info("Language: {}".format(language)) data = { "pay_to_email": settings.MONEYBOOKERS_TO[self.cleaned_data['currency']], "account": self.cleaned_data["account"].mt4_id, "status_url": build_absolute_uri( self.request, reverse("payments_operation_result", args=[self.instance.pk])), "return_url": build_absolute_uri( self.request, reverse("payments_operation_status", args=["deposit", self.instance.pk, "success"])), "cancel_url": build_absolute_uri( self.request, reverse("payments_operation_status", args=["deposit", self.instance.pk, "fail"])), "language": language, "detail1_description": "Account:", "logo_url": "https://arumcapital.eu/static/img/marketing-site/etc/logo-arum--word.png", "detail1_text": self.cleaned_data["account"] } data.update(self.additional_parameters) log.debug("Data is {}".format(data)) for field, value in data.iteritems(): self.fields[field] = base.make_hidden(value) return super(DepositForm, self).mutate()
def mutate(self): assert hasattr(self, "instance") fail_url = build_absolute_uri( self.request, reverse("payments_operation_status", args=["deposit", self.instance.pk, "fail"])) success_url = build_absolute_uri( self.request, reverse("payments_operation_status", args=["deposit", self.instance.pk, "success"])) data = { "site_id": settings.ACCENTPAY_ACCOUNT, "external_id": unicode(self.instance.pk), "currency": "RUB" if self.cleaned_data['currency'] == "RUR" else self.cleaned_data['currency'], "amount": unicode(int(self.instance.amount * 100)), "description": "Payment to account %s" % self.instance.account, "language": settings.LANGUAGE_CODE.lower(), "success_url": success_url, "decline_url": fail_url, "callback_method": "2", # GET "followup": "1", "payment_group_id": "1" } data.update(self.get_additional_params()) data["signature"] = self.get_signature(data) for field, value in data.iteritems(): self.fields[field] = base.make_hidden(value) super(DepositForm, self).mutate() self.is_bound = False self.fields.pop('account') return self
def __init__(self, *args, **kwargs): self.request = kwargs.pop("request", None) self.account_type = kwargs.pop("account_type", None) super(Mt4AccountForm, self).__init__(*args, **kwargs) if not self.account_type: return # Adding leverage choices and initial value (which defaults # to the first leverege choices item, if not set explicitly # in account type definition). if self.account_type.leverage_choices: available_leverages = calculate_available_leverages( group=self.account_type, user=self.request and self.request.user.is_authenticated() and self.request.user, ) leverage_default = getattr(self.account_type, "leverage_default", None) if leverage_default not in available_leverages: leverage_default = available_leverages[0] leverage_choices = [(idx, '1:%i' % idx) for idx in available_leverages] self.fields["leverage"].choices = leverage_choices self.fields["leverage"].initial = leverage_default if len(self.account_type.leverage_choices) == 1: self.fields["leverage"].widget = forms.HiddenInput() else: del self.fields["leverage"] if self.account_type.available_options & HAS_EXECUTION_OPTIONS: self.fields["execution_system"] = forms.ChoiceField( label=_("Execution system"), choices=execution_system_choices(self.account_type), widget=forms.RadioSelect(), initial=MARKET_EXECUTION, required=False) if self.account_type.available_options & HAS_CURRENCY_OPTIONS: self.fields["currency"] = forms.ChoiceField( label=_("Currency"), initial=currencies.USD, choices=default_currencies_from_type(self.account_type), required=False, ) if self.account_type.available_options & HAS_BINARY_OPTIONS_TYPE_OPTIONS: self.fields["binary_options_type"] = forms.ChoiceField( label=_("Binary options style"), initial=EUROPEAN_OPTIONS, choices=BINARY_OPTIONS_TYPE_CHOICES, widget=forms.RadioSelect(), required=False, help_text=_( "American-style options can be closed before expiration date, but have much lower " "reward rate than European-style options"), ) # Initializing deposit fields, if account type requires deposit, # or removing it otherwise. if self.account_type.deposit is not None: self.fields["deposit"].initial = self.account_type.deposit else: del self.fields["deposit"] self.fields.update( get_accept_fields(self.request, self.account_type.agreements)) self.fields["account_type"] = make_hidden(self.account_type.slug)