parent
4317bde253
commit
442665fbfd
|
@ -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 <Transaction>` 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()
|
||||
|
|
|
@ -30,7 +30,11 @@
|
|||
{% if error %}
|
||||
<h4 class="alert-heading">Beim Aufladen ist ein Fehler aufgetreten.</h4>
|
||||
{% else %}
|
||||
<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
|
||||
{% if payout %}
|
||||
<h4 class="alert-heading">Du hast Geld abgehoben.</h4>
|
||||
{% else %}
|
||||
<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -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'),
|
||||
)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue