parent
4317bde253
commit
442665fbfd
|
@ -12,16 +12,12 @@ from main.fields import CurrencyField
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class TransactionForm(forms.ModelForm):
|
class TransactionForm(forms.ModelForm):
|
||||||
""" ModelForm for :class:`Transactions <Transaction>` with a currency field. """
|
""" ModelForm for :class:`Transactions <Transaction>` with a currency field. """
|
||||||
amount = CurrencyField(label='Betrag')
|
amount = CurrencyField(label='Betrag')
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
exclude = ('user', 'dateTime', 'checked')
|
exclude = ('user', 'dateTime', 'checked')
|
||||||
def clean_amount(self):
|
|
||||||
data = self.cleaned_data['amount']
|
|
||||||
return data
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# needed to enforce TransactionTypes needsCheck "default value"
|
# needed to enforce TransactionTypes needsCheck "default value"
|
||||||
cleaned_data = super(TransactionForm, self).clean()
|
cleaned_data = super(TransactionForm, self).clean()
|
||||||
|
|
|
@ -29,9 +29,13 @@
|
||||||
<div class="alert {% if error %}alert-error{% else %}alert-success{% endif %}">
|
<div class="alert {% if error %}alert-error{% else %}alert-success{% endif %}">
|
||||||
{% if error %}
|
{% if error %}
|
||||||
<h4 class="alert-heading">Beim Aufladen ist ein Fehler aufgetreten.</h4>
|
<h4 class="alert-heading">Beim Aufladen ist ein Fehler aufgetreten.</h4>
|
||||||
|
{% else %}
|
||||||
|
{% if payout %}
|
||||||
|
<h4 class="alert-heading">Du hast Geld abgehoben.</h4>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
|
<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form method="post" action="/transaction/#payments" class="form-horizontal">
|
<form method="post" action="/transaction/#payments" class="form-horizontal">
|
||||||
|
|
|
@ -10,5 +10,5 @@ from django.conf.urls.defaults import *
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^$', 'transaction.views.overview'),
|
(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'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,11 +24,14 @@ def overview(request):
|
||||||
form = TransactionForm()
|
form = TransactionForm()
|
||||||
vform = VirtualTransactionForm()
|
vform = VirtualTransactionForm()
|
||||||
state =None
|
state =None
|
||||||
|
payway = "payin"
|
||||||
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":
|
||||||
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():
|
||||||
|
if form.cleaned_data['amount'] < 0:
|
||||||
|
payway = "payout"
|
||||||
form.save()
|
form.save()
|
||||||
form = TransactionForm()
|
form = TransactionForm()
|
||||||
state = "success"
|
state = "success"
|
||||||
|
@ -44,12 +47,12 @@ def overview(request):
|
||||||
state = "vsuccess"
|
state = "vsuccess"
|
||||||
else:
|
else:
|
||||||
state = "verror"
|
state = "verror"
|
||||||
return HttpResponseRedirect("state/%s/" % state)
|
return HttpResponseRedirect("state/%s/%s/" % (state,payway))
|
||||||
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 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
|
@login_required
|
||||||
def state(request, state=""):
|
def state(request, state="", payway=""):
|
||||||
""" View which shows the state/return-msg of a transaction."""
|
""" View which shows the state/return-msg of a transaction."""
|
||||||
# create history
|
# create history
|
||||||
history = Transaction.objects.filter(user=request.user).order_by("-dateTime")
|
history = Transaction.objects.filter(user=request.user).order_by("-dateTime")
|
||||||
|
@ -60,6 +63,7 @@ def state(request, state=""):
|
||||||
|
|
||||||
error = verror = False
|
error = verror = False
|
||||||
transacted = vtransacted = False
|
transacted = vtransacted = False
|
||||||
|
payout = False
|
||||||
if state == "" or state == "error":
|
if state == "" or state == "error":
|
||||||
error = True
|
error = True
|
||||||
elif state == "success":
|
elif state == "success":
|
||||||
|
@ -68,4 +72,7 @@ def state(request, state=""):
|
||||||
verror = true
|
verror = true
|
||||||
elif state == "vsuccess":
|
elif state == "vsuccess":
|
||||||
vtransacted = True
|
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))
|
||||||
|
|
Loading…
Reference in New Issue