Beispiel #1
0
    def post(self, request, *args, **kwargs):
        self.context = {}
        form = withdrawForm(request.POST)
        if form.is_valid():
            mpin = form.cleaned_data.get("mpin")
            amount = form.cleaned_data.get("amount")
            # date=form.cleaned_data.get("date")

            try:
                object = AccountInfoModel.objects.get(
                    username=self.request.user, mpin=mpin)
                bal = object.balance + amount
                object.balance = bal
                object.save()
                self.context["amount"] = amount

            except Exception:
                self.context["form"] = form
                return render(request, self.template_name, self.context)

            # code for not null :assigning to another variable
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()

            # form.save()
            return render(request, "profiles/depositsucces.html", self.context)

            # return redirect("home")
        else:
            self.context["form"] = form
            return render(request, self.template_name, self.context)
Beispiel #2
0
class withdrawView(LoginRequiredMixin, View):
    # model = TransferModel
    form = withdrawForm()
    fields = ["amount", "mpin", "user"]

    def get_initial(self):
        return {'user': self.request.user}

    template_name = "profiles/withdraw.html"
    context = {}

    def get(self, request, *args, **kwargs):
        form = withdrawForm()
        self.context["form"] = form
        return render(request, self.template_name, self.context)

    def post(self, request, *args, **kwargs):
        self.context = {}
        form = withdrawForm(request.POST)
        if form.is_valid():
            mpin = form.cleaned_data.get("mpin")
            amount = form.cleaned_data.get("amount")
            try:
                object = AccountInfoModel.objects.get(
                    username=self.request.user, mpin=mpin)
                bal = object.balance - amount
                object.balance = bal
                object.save()
                self.context["amount"] = amount

            except Exception:
                self.context["form"] = form
                return render(request, self.template_name, self.context)

            # not null error
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()
            # form.save()
            return render(request, "profiles/withdrawsuccess.html",
                          self.context)

            # return redirect("home")
        else:
            self.context["form"] = form
            return render(request, self.template_name, self.context)
Beispiel #3
0
 def get(self, request, *args, **kwargs):
     form = withdrawForm()
     self.context["form"] = form
     return render(request, self.template_name, self.context)