|
|
@ -2,11 +2,12 @@ from piston.handler import BaseHandler
|
|
|
|
from piston.utils import rc
|
|
|
|
from piston.utils import rc
|
|
|
|
from k4ever.buyable.models import *
|
|
|
|
from k4ever.buyable.models import *
|
|
|
|
from k4ever.transaction.models import *
|
|
|
|
from k4ever.transaction.models import *
|
|
|
|
from decorators import changeUserOnPlugin
|
|
|
|
from django.contrib.auth.decorators import user_passes_test
|
|
|
|
|
|
|
|
from django.contrib.auth.models import Group
|
|
|
|
|
|
|
|
from decorators import *
|
|
|
|
from decimal import Decimal, InvalidOperation
|
|
|
|
from decimal import Decimal, InvalidOperation
|
|
|
|
import datetime
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getInt(d, key, default):
|
|
|
|
def getInt(d, key, default):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return int(d.get(key, default))
|
|
|
|
return int(d.get(key, default))
|
|
|
@ -39,6 +40,7 @@ class BuyableItemHandler(BaseHandler):
|
|
|
|
error.write("This buyable does not exist in our database")
|
|
|
|
error.write("This buyable does not exist in our database")
|
|
|
|
return error
|
|
|
|
return error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
def create(self, request, itemId=None):
|
|
|
|
def create(self, request, itemId=None):
|
|
|
|
if not request.content_type:
|
|
|
|
if not request.content_type:
|
|
|
|
request.data = request.POST
|
|
|
|
request.data = request.POST
|
|
|
@ -81,6 +83,7 @@ class TransactionTransactHandler(BaseHandler):
|
|
|
|
model = Transaction
|
|
|
|
model = Transaction
|
|
|
|
fields = ('amount', 'dateTime', 'checked', ('transactionType', ('id', 'name')))
|
|
|
|
fields = ('amount', 'dateTime', 'checked', ('transactionType', ('id', 'name')))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
def read(self, request):
|
|
|
|
def read(self, request):
|
|
|
|
num = getInt(request.GET, 'num', 0)
|
|
|
|
num = getInt(request.GET, 'num', 0)
|
|
|
|
if num < 0:
|
|
|
|
if num < 0:
|
|
|
@ -91,6 +94,7 @@ class TransactionTransactHandler(BaseHandler):
|
|
|
|
return userTrans[:num]
|
|
|
|
return userTrans[:num]
|
|
|
|
return userTrans
|
|
|
|
return userTrans
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
def create(self, request):
|
|
|
|
def create(self, request):
|
|
|
|
amount = getDecimal(request.POST, 'amount', Decimal(0))
|
|
|
|
amount = getDecimal(request.POST, 'amount', Decimal(0))
|
|
|
|
tTypeId = getInt(request.POST, 'type', -1)
|
|
|
|
tTypeId = getInt(request.POST, 'type', -1)
|
|
|
@ -121,6 +125,8 @@ class TransactionTypeHandler(BaseHandler):
|
|
|
|
|
|
|
|
|
|
|
|
class AccountBalanceHandler(BaseHandler):
|
|
|
|
class AccountBalanceHandler(BaseHandler):
|
|
|
|
allowed_methods = ('GET',)
|
|
|
|
allowed_methods = ('GET',)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manglePluginPerms
|
|
|
|
def read(self, request):
|
|
|
|
def read(self, request):
|
|
|
|
balance = request.user.get_profile().balance
|
|
|
|
balance = request.user.get_profile().balance
|
|
|
|
return {'balance': balance}
|
|
|
|
return {'balance': balance}
|
|
|
|