示例#1
0
    def clean(self):
        cleaned_data = super(InvestmentForm, self).clean()

        # investor validation
        current_investor = self.cleaned_data.pop("investor")
        anonymous_investor = self.cleaned_data.pop("anonymous_investor")
        investor_type = self.cleaned_data.pop("investor_type")
        investor_organization = self.cleaned_data.pop("investor_organization")
        investor_person = self.cleaned_data.pop("investor_person")
        if not anonymous_investor:
            self.validation('investor_organization', _("Invalid investor."),
                investor_type == "ORG" and not investor_organization)
            self.validation('investor_person', _("Invalid investor."),
                investor_type == "PER" and not investor_person)
        # investor coercing
        if anonymous_investor:
            investor = ""
        elif investor_type == 'ORG':
            investor = investor_organization
        elif investor_type == 'PER':
            investor = investor_person

        if investor != None:
            investor, created = Investor.get_or_create_for(investor,
                                    current=current_investor)
            self.cleaned_data['investor'] = investor
        else:
            created = False

        if created:
            investor.save()


        return cleaned_data
示例#2
0
    def clean(self):
        cleaned_data = super(InvestmentForm, self).clean()

        # investor validation
        current_investor = self.cleaned_data.pop("investor")
        anonymous_investor = self.cleaned_data.pop("anonymous_investor")
        investor_type = self.cleaned_data.pop("investor_type")
        investor_organization = self.cleaned_data.pop("investor_organization")
        investor_person = self.cleaned_data.pop("investor_person")
        if not anonymous_investor:
            self.validation(
                'investor_organization', _("Invalid investor."),
                investor_type == "ORG" and not investor_organization)
            self.validation('investor_person', _("Invalid investor."),
                            investor_type == "PER" and not investor_person)
        # investor coercing
        if anonymous_investor:
            investor = ""
        elif investor_type == 'ORG':
            investor = investor_organization
        elif investor_type == 'PER':
            investor = investor_person

        if investor != None:
            investor, created = Investor.get_or_create_for(
                investor, current=current_investor)
            self.cleaned_data['investor'] = investor
        else:
            created = False

        if created:
            investor.save()

        return cleaned_data
示例#3
0
 def as_investor(self):
     investor, created = Investor.get_or_create_for(self)
     return investor
示例#4
0
 def as_investor(self):
     investor, created = Investor.get_or_create_for(self)
     return investor