|
|
|
@ -9,6 +9,7 @@ from decorators import *
|
|
|
|
|
from collections import Iterable
|
|
|
|
|
from decimal import Decimal, InvalidOperation
|
|
|
|
|
from helper import *
|
|
|
|
|
from django.db.models import Q
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
class BuyableItemHandler(BaseHandler):
|
|
|
|
@ -221,7 +222,7 @@ class HistoryHandler(BaseHandler):
|
|
|
|
|
- num: Number of entries to return
|
|
|
|
|
"""
|
|
|
|
|
num = getInt(request.GET, 'num', 0)
|
|
|
|
|
qset = Order.objects.filter(user=request.user)
|
|
|
|
|
qset = Order.objects.filter(user=request.user).order_by("-dateTime")
|
|
|
|
|
if num > 0:
|
|
|
|
|
return qset[:num]
|
|
|
|
|
return qset
|
|
|
|
@ -248,7 +249,7 @@ class TransactionTransactHandler(BaseHandler):
|
|
|
|
|
if num < 0:
|
|
|
|
|
return rc.BAD_REQUEST
|
|
|
|
|
|
|
|
|
|
userTrans = Transaction.objects.filter(user=request.user)
|
|
|
|
|
userTrans = Transaction.objects.filter(user=request.user).order_by("-dateTime")
|
|
|
|
|
if num > 0:
|
|
|
|
|
return userTrans[:num]
|
|
|
|
|
return userTrans
|
|
|
|
@ -291,6 +292,62 @@ class TransactionTypeHandler(BaseHandler):
|
|
|
|
|
allowed_methods = ('GET',)
|
|
|
|
|
model = TransactionType
|
|
|
|
|
|
|
|
|
|
class TransactionVirtualHandler(BaseHandler):
|
|
|
|
|
""" Handler for :class:`Virtual Transaction <transaction.models.VirtualTransaction>`
|
|
|
|
|
Allows to make transactions between users. """
|
|
|
|
|
allowed_methods = ('GET', 'POST')
|
|
|
|
|
model = VirtualTransaction
|
|
|
|
|
fields = ('id', 'amount', 'dateTime', 'comment', ('user', ('id', 'username',)), ('recipient', ('id', 'username',)))
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
|
def read(self, request):
|
|
|
|
|
"""Return the user's last virtual transactions (inbound and outbound)
|
|
|
|
|
|
|
|
|
|
- num: Number of entries to return
|
|
|
|
|
"""
|
|
|
|
|
num = getInt(request.GET, 'num', 0)
|
|
|
|
|
if num < 0:
|
|
|
|
|
return rc.BAD_REQUEST
|
|
|
|
|
|
|
|
|
|
userTrans = VirtualTransaction.objects.filter(Q(user=request.user) | Q(recipient=request.user)).order_by("-dateTime")
|
|
|
|
|
if num > 0:
|
|
|
|
|
return userTrans[:num]
|
|
|
|
|
return userTrans
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
|
def create(self, request):
|
|
|
|
|
""" Transact money from the users to another users account.
|
|
|
|
|
|
|
|
|
|
- amount: [req] Amount to transact
|
|
|
|
|
- recipient: [req] User that will get the money
|
|
|
|
|
- comment: [req] Comment, why the money was transacted
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
amount = getDecimal(request.data, 'amount', Decimal(0))
|
|
|
|
|
|
|
|
|
|
if amount < Decimal("0.01"):
|
|
|
|
|
ret = rc.BAD_REQUEST
|
|
|
|
|
ret.write("\nYou can't transact negatives amount to another users account.\n")
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
comment = request.data.get('comment', None)
|
|
|
|
|
if not comment:
|
|
|
|
|
ret = rc.BAD_REQUEST
|
|
|
|
|
ret.write("\nPlease supply a comment for the transaction\n")
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
recipientStr = request.data.get('recipient', None)
|
|
|
|
|
recipient = None
|
|
|
|
|
try:
|
|
|
|
|
recipient = User.objects.get(username=recipientStr)
|
|
|
|
|
except User.DoesNotExist:
|
|
|
|
|
ret = rc.BAD_REQUEST
|
|
|
|
|
ret.write("\nThe recipient user does not exist.\n")
|
|
|
|
|
return ret
|
|
|
|
|
trans = VirtualTransaction(user=request.user, recipient=recipient, amount=amount, comment=comment)
|
|
|
|
|
trans.save()
|
|
|
|
|
return rc.ALL_OK
|
|
|
|
|
|
|
|
|
|
class AccountBalanceHandler(BaseHandler):
|
|
|
|
|
"""Handler for the user's account balance"""
|
|
|
|
|
allowed_methods = ('GET',)
|
|
|
|
|