From 4317bde25351ab789ad527081fb620c99c05343c Mon Sep 17 00:00:00 2001 From: tkroenert Date: Thu, 5 Apr 2012 22:25:44 +0200 Subject: [PATCH] *fix: Ticket #88 (use RPG for transactions) --- k4ever/transaction/urls.py | 4 +--- k4ever/transaction/views.py | 38 ++++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/k4ever/transaction/urls.py b/k4ever/transaction/urls.py index 6d63538..f199ab7 100644 --- a/k4ever/transaction/urls.py +++ b/k4ever/transaction/urls.py @@ -10,7 +10,5 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^$', 'transaction.views.overview'), - #(r'^transact/$', 'transaction.views.transact'), - #(r'^transfer/$', 'transaction.views.transfer'), - #(r'^checkTransfers/$', 'transaction.views.checkTransfers'), + url(r'^state/(success|error|vsuccess|verror)/$', 'transaction.views.state'), ) diff --git a/k4ever/transaction/views.py b/k4ever/transaction/views.py index f2df5f6..2fd7276 100644 --- a/k4ever/transaction/views.py +++ b/k4ever/transaction/views.py @@ -23,29 +23,49 @@ def overview(request): # create forms form = TransactionForm() vform = VirtualTransactionForm() - transacted = vtransacted = False - error = verror = False + state = None if request.method == 'POST' and request.POST.has_key('_formtype'): if request.POST['_formtype'] == "normal": - transacted = True transaction = Transaction(user=request.user) form = TransactionForm(request.POST, instance=transaction) if form.is_valid(): form.save() form = TransactionForm() - transacted = True + state = "success" else: - error = True + state = "error" form = TransactionForm() elif request.POST['_formtype'] == "virtual": - vtransacted = True vtransaction = VirtualTransaction(user=request.user) vform = VirtualTransactionForm(request.POST, instance=vtransaction) if vform.is_valid(): vform.save() vform = VirtualTransactionForm() - vtransacted = True + state = "vsuccess" else: - error = 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)) + 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)) + +@login_required +def state(request, state=""): + """ View which shows the state/return-msg of a transaction.""" + # create history + history = Transaction.objects.filter(user=request.user).order_by("-dateTime") + vhistory = VirtualTransaction.objects.filter(Q(user=request.user) | Q(recipient=request.user)).order_by("-dateTime") + # create forms + form = TransactionForm() + vform = VirtualTransactionForm() + + error = verror = False + transacted = vtransacted = False + if state == "" or state == "error": + error = True + elif state == "success": + transacted = True + elif state == "verror": + 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))