From 442665fbfd6da0f52ed315adb5377464b71d56ab Mon Sep 17 00:00:00 2001 From: tkroenert Date: Thu, 5 Apr 2012 23:31:03 +0200 Subject: [PATCH] transaction/ - cleanup transaction/ * fix ticket Ticket #25 --- k4ever/transaction/forms.py | 4 ---- .../templates/transaction/overview.html | 6 +++++- k4ever/transaction/urls.py | 2 +- k4ever/transaction/views.py | 17 ++++++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/k4ever/transaction/forms.py b/k4ever/transaction/forms.py index 50759bd..0526ce4 100644 --- a/k4ever/transaction/forms.py +++ b/k4ever/transaction/forms.py @@ -12,16 +12,12 @@ from main.fields import CurrencyField from django.contrib.auth.models import User from django.core.exceptions import ValidationError - class TransactionForm(forms.ModelForm): """ ModelForm for :class:`Transactions ` with a currency field. """ amount = CurrencyField(label='Betrag') class Meta: model = Transaction exclude = ('user', 'dateTime', 'checked') - def clean_amount(self): - data = self.cleaned_data['amount'] - return data def clean(self): # needed to enforce TransactionTypes needsCheck "default value" cleaned_data = super(TransactionForm, self).clean() diff --git a/k4ever/transaction/templates/transaction/overview.html b/k4ever/transaction/templates/transaction/overview.html index 595c63f..ca40655 100644 --- a/k4ever/transaction/templates/transaction/overview.html +++ b/k4ever/transaction/templates/transaction/overview.html @@ -30,7 +30,11 @@ {% if error %}

Beim Aufladen ist ein Fehler aufgetreten.

{% else %} -

Du hast Geld aufgeladen.

+ {% if payout %} +

Du hast Geld abgehoben.

+ {% else %} +

Du hast Geld aufgeladen.

+ {% endif %} {% endif %} {% endif %} diff --git a/k4ever/transaction/urls.py b/k4ever/transaction/urls.py index f199ab7..f898434 100644 --- a/k4ever/transaction/urls.py +++ b/k4ever/transaction/urls.py @@ -10,5 +10,5 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^$', 'transaction.views.overview'), - url(r'^state/(success|error|vsuccess|verror)/$', 'transaction.views.state'), + url(r'^state/(success|error|vsuccess|verror)/(payin|payout)/$', 'transaction.views.state'), ) diff --git a/k4ever/transaction/views.py b/k4ever/transaction/views.py index 2fd7276..ccc4aa4 100644 --- a/k4ever/transaction/views.py +++ b/k4ever/transaction/views.py @@ -23,12 +23,15 @@ def overview(request): # create forms form = TransactionForm() vform = VirtualTransactionForm() - state = None + state =None + payway = "payin" if request.method == 'POST' and request.POST.has_key('_formtype'): if request.POST['_formtype'] == "normal": transaction = Transaction(user=request.user) form = TransactionForm(request.POST, instance=transaction) if form.is_valid(): + if form.cleaned_data['amount'] < 0: + payway = "payout" form.save() form = TransactionForm() state = "success" @@ -44,12 +47,12 @@ def overview(request): state = "vsuccess" else: state = "verror" - return HttpResponseRedirect("state/%s/" % state) - return render_to_response("transaction/overview.html", {'history': history, 'vhistory': vhistory, 'form': form, 'transacted': False, 'error': False, 'vform': vform, 'vtransacted': False, 'verror': False}, RequestContext(request)) + return HttpResponseRedirect("state/%s/%s/" % (state,payway)) + return render_to_response("transaction/overview.html", {'history': history, 'vhistory': vhistory, 'form': form, 'transacted': False, 'payout': payout, 'error': False, 'vform': vform, 'vtransacted': False, 'verror': False}, RequestContext(request)) @login_required -def state(request, state=""): +def state(request, state="", payway=""): """ View which shows the state/return-msg of a transaction.""" # create history history = Transaction.objects.filter(user=request.user).order_by("-dateTime") @@ -60,6 +63,7 @@ def state(request, state=""): error = verror = False transacted = vtransacted = False + payout = False if state == "" or state == "error": error = True elif state == "success": @@ -68,4 +72,7 @@ def state(request, state=""): verror = true elif state == "vsuccess": vtransacted = True - return render_to_response("transaction/overview.html", {'history': history, 'vhistory': vhistory, 'form': form, 'transacted': transacted, 'error': error, 'vform': vform, 'vtransacted': vtransacted, 'verror': verror}, RequestContext(request)) + + if payway == "payout": + payout = True + return render_to_response("transaction/overview.html", {'history': history, 'vhistory': vhistory, 'form': form, 'transacted': transacted, 'payout': payout, 'error': error, 'vform': vform, 'vtransacted': vtransacted, 'verror': verror}, RequestContext(request))