No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # This file is part of k4ever, a point-of-sale system
  2. # Contact............ <k4ever@lists.someserver.de>
  3. # Website............ http://k4ever.someserver.de/
  4. # Bug tracker........ http://k4ever.someserver.de/report
  5. #
  6. # Licensed under GNU Affero General Public License v3 or later
  7. from django.shortcuts import render_to_response
  8. from django.template import RequestContext
  9. from django.contrib.auth.decorators import login_required
  10. from django.db.models import Q
  11. from django.http import HttpResponseRedirect
  12. from models import Transaction, TransactionType, VirtualTransaction
  13. from forms import TransactionForm, VirtualTransactionForm
  14. import datetime
  15. @login_required
  16. def overview(request):
  17. """ Creates an overview over the users transactions, also handles adding and transfering money. """
  18. # create history
  19. history = Transaction.objects.filter(user=request.user).order_by("-dateTime")
  20. vhistory = VirtualTransaction.objects.filter(Q(user=request.user) | Q(recipient=request.user)).order_by("-dateTime")
  21. # create forms
  22. form = TransactionForm()
  23. vform = VirtualTransactionForm()
  24. transacted = vtransacted = False
  25. error = verror = False
  26. if request.method == 'POST' and request.POST.has_key('_formtype'):
  27. if request.POST['_formtype'] == "normal":
  28. transacted = True
  29. transaction = Transaction(user=request.user)
  30. form = TransactionForm(request.POST, instance=transaction)
  31. if form.is_valid():
  32. form.save()
  33. form = TransactionForm()
  34. transacted = True
  35. else:
  36. error = True
  37. form = TransactionForm()
  38. elif request.POST['_formtype'] == "virtual":
  39. vtransacted = True
  40. vtransaction = VirtualTransaction(user=request.user)
  41. vform = VirtualTransactionForm(request.POST, instance=vtransaction)
  42. if vform.is_valid():
  43. vform.save()
  44. vform = VirtualTransactionForm()
  45. vtransacted = True
  46. else:
  47. error = True
  48. 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))