コード例 #1
0
ファイル: forms.py プロジェクト: Thames1990/BadBatBets
    def save(self, request):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        end_date = self.cleaned_data.get('end_date')
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = ChoiceBet(owner=request.user.profile,
                            name=name,
                            description=description,
                            end_bets_date=end_bets_date,
                            end_date=end_date,
                            account=account)
        try:
            choices = create_choices(request, new_bet)
        except ValidationError:
            raise

        new_bet.save()
        for choice in choices:
            choice.save()

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
コード例 #2
0
ファイル: forms.py プロジェクト: Thames1990/BadBatBets
    def save(self, user):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        time_period_start = self.cleaned_data['time_period_start']
        time_period_end = self.cleaned_data['time_period_end']
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = DateBet.objects.create(owner=user,
                                         name=name,
                                         description=description,
                                         end_bets_date=end_bets_date,
                                         time_period_start=time_period_start,
                                         time_period_end=time_period_end,
                                         account=account)

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
コード例 #3
0
    def save(self, commit=True):
        user = super(SignupForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        if commit:
            user.save()

        account = Account(name=user.username, type='p')
        account.save(commit)
        profile = Profile(user=user, account=account)
        profile.save(commit)
        return user