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))