*fix: Ticket #88 (use RPG for transactions)

This commit is contained in:
tkroenert 2012-04-05 22:25:44 +02:00
parent 3df2c2e122
commit 4317bde253
2 changed files with 30 additions and 12 deletions

View File

@ -10,7 +10,5 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^$', 'transaction.views.overview'), (r'^$', 'transaction.views.overview'),
#(r'^transact/$', 'transaction.views.transact'), url(r'^state/(success|error|vsuccess|verror)/$', 'transaction.views.state'),
#(r'^transfer/$', 'transaction.views.transfer'),
#(r'^checkTransfers/$', 'transaction.views.checkTransfers'),
) )

View File

@ -23,29 +23,49 @@ def overview(request):
# create forms # create forms
form = TransactionForm() form = TransactionForm()
vform = VirtualTransactionForm() vform = VirtualTransactionForm()
transacted = vtransacted = False state = None
error = verror = False
if request.method == 'POST' and request.POST.has_key('_formtype'): if request.method == 'POST' and request.POST.has_key('_formtype'):
if request.POST['_formtype'] == "normal": if request.POST['_formtype'] == "normal":
transacted = True
transaction = Transaction(user=request.user) transaction = Transaction(user=request.user)
form = TransactionForm(request.POST, instance=transaction) form = TransactionForm(request.POST, instance=transaction)
if form.is_valid(): if form.is_valid():
form.save() form.save()
form = TransactionForm() form = TransactionForm()
transacted = True state = "success"
else: else:
error = True state = "error"
form = TransactionForm() form = TransactionForm()
elif request.POST['_formtype'] == "virtual": elif request.POST['_formtype'] == "virtual":
vtransacted = True
vtransaction = VirtualTransaction(user=request.user) vtransaction = VirtualTransaction(user=request.user)
vform = VirtualTransactionForm(request.POST, instance=vtransaction) vform = VirtualTransactionForm(request.POST, instance=vtransaction)
if vform.is_valid(): if vform.is_valid():
vform.save() vform.save()
vform = VirtualTransactionForm() vform = VirtualTransactionForm()
vtransacted = True state = "vsuccess"
else: else:
error = True state = "verror"
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)) 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))