Use userprofile directly instead of userprofile_set

This commit is contained in:
Sebastian Lohff 2019-11-20 00:21:50 +01:00
parent 63b3f71141
commit 91f549b69e
4 changed files with 17 additions and 17 deletions

View File

@ -116,7 +116,7 @@ class BuyableItemHandler(BaseHandler):
p.save(saveOrder=False) p.save(saveOrder=False)
order.save() order.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance} return {'success': True, 'balance': request.user.userprofile.balance}
def bulkBuy(self, request): def bulkBuy(self, request):
"""Buy a :class:`Buyable <buyable.models.Buyable>` item. """Buy a :class:`Buyable <buyable.models.Buyable>` item.
@ -179,7 +179,7 @@ class BuyableItemHandler(BaseHandler):
p.save(saveOrder=False) p.save(saveOrder=False)
order.save() order.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance} return {'success': True, 'balance': request.user.userprofile.balance}
class BuyableTypeHandler(BaseHandler): class BuyableTypeHandler(BaseHandler):
@ -290,7 +290,7 @@ class TransactionTransactHandler(BaseHandler):
return getError(rc.BAD_REQUEST, "Your TransactionType could not be found") return getError(rc.BAD_REQUEST, "Your TransactionType could not be found")
trans = Transaction(user=request.user, transactionType=tType, amount=amount, checked=not tType.needsCheck) trans = Transaction(user=request.user, transactionType=tType, amount=amount, checked=not tType.needsCheck)
trans.save() trans.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance} return {'success': True, 'balance': request.user.userprofile.balance}
class TransactionTypeHandler(BaseHandler): class TransactionTypeHandler(BaseHandler):
"""Handler for :class:`Transaction Types <transaction.models.TransactionType>` """Handler for :class:`Transaction Types <transaction.models.TransactionType>`
@ -348,7 +348,7 @@ class TransactionVirtualHandler(BaseHandler):
return getError(rc.BAD_REQUEST, "The recipient user does not exist.") return getError(rc.BAD_REQUEST, "The recipient user does not exist.")
trans = VirtualTransaction(user=request.user, recipient=recipient, amount=amount, comment=comment) trans = VirtualTransaction(user=request.user, recipient=recipient, amount=amount, comment=comment)
trans.save() trans.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance} return {'success': True, 'balance': request.user.userprofile.balance}
class AccountBalanceHandler(BaseHandler): class AccountBalanceHandler(BaseHandler):
"""Handler for the user's account balance""" """Handler for the user's account balance"""
@ -357,7 +357,7 @@ class AccountBalanceHandler(BaseHandler):
@manglePluginPerms @manglePluginPerms
def read(self, request): def read(self, request):
"""Returns the user's current account balance""" """Returns the user's current account balance"""
balance = request.user.userprofile_set.get().balance balance = request.user.userprofile.balance
return {'balance': balance} return {'balance': balance}
class AuthBlobHandler(BaseHandler): class AuthBlobHandler(BaseHandler):

View File

@ -79,7 +79,7 @@ class Order(models.Model):
return l.rstrip(u", ") return l.rstrip(u", ")
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
profile = self.user.userprofile_set.get() profile = self.user.userprofile
if self.id == None: if self.id == None:
# new item, get it! # new item, get it!
profile.balance -= self.price profile.balance -= self.price
@ -88,12 +88,12 @@ class Order(models.Model):
# get old # get old
oldobj = Order.objects.get(id=self.id) oldobj = Order.objects.get(id=self.id)
if oldobj.user == self.user: if oldobj.user == self.user:
profile = self.user.userprofile_set.get() profile = self.user.userprofile
profile.balance -= (self.price - oldobj.price) profile.balance -= (self.price - oldobj.price)
profile.save() profile.save()
else: else:
oldProfile = oldobj.user.userprofile_set.get() oldProfile = oldobj.user.userprofile
newProfile = self.user.userprofile_set.get() newProfile = self.user.userprofile
oldProfile.balance += oldobj.price oldProfile.balance += oldobj.price
oldProfile.save() oldProfile.save()
newprofile.balance -= self.price newprofile.balance -= self.price
@ -111,7 +111,7 @@ class Order(models.Model):
# where all the buyables have not updated the price # where all the buyables have not updated the price
updOrder = Order.objects.get(id=instance.id) updOrder = Order.objects.get(id=instance.id)
if updOrder.price != Decimal("0"): if updOrder.price != Decimal("0"):
profile = updOrder.user.userprofile_set.get() profile = updOrder.user.userprofile
profile.balance += updOrder.price profile.balance += updOrder.price
profile.save() profile.save()

View File

@ -45,7 +45,7 @@
{% if user.is_authenticated %} {% if user.is_authenticated %}
<div class="pull-right"> <div class="pull-right">
<span class="brand balance">Kontostand: {{ user.userprofile_set.get.balance|floatformat:2 }} €</span> <span class="brand balance">Kontostand: {{ user.userprofile.balance|floatformat:2 }} €</span>
<form class="navbar-search"> <form class="navbar-search">
<input placeholder="Suche und kaufe..." class="search-query autocomplete" <input placeholder="Suche und kaufe..." class="search-query autocomplete"
type="search" name="search_term" value="Lade Daten..." type="search" name="search_term" value="Lade Daten..."

View File

@ -43,7 +43,7 @@ class Transaction(models.Model):
(self.checked and " " or " not ")) (self.checked and " " or " not "))
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
profile = self.user.userprofile_set.get() profile = self.user.userprofile
if self.id == None: if self.id == None:
# insert # insert
profile.balance += self.amount profile.balance += self.amount
@ -51,11 +51,11 @@ class Transaction(models.Model):
# update # update
oldobj = Transaction.objects.get(id=self.id) oldobj = Transaction.objects.get(id=self.id)
if oldobj.user != self.user: if oldobj.user != self.user:
oldprofile = oldobj.user.userprofile_set.get() oldprofile = oldobj.user.userprofile
oldprofile.balance -= oldobj.amount oldprofile.balance -= oldobj.amount
oldprofile.save() oldprofile.save()
# just to be save, reget profile # just to be save, reget profile
profile = self.user.userprofile_set.get() profile = self.user.userprofile
profile.balance += self.amount profile.balance += self.amount
else: else:
profile.balance += (self.amount-oldobj.amount) profile.balance += (self.amount-oldobj.amount)
@ -64,7 +64,7 @@ class Transaction(models.Model):
@staticmethod @staticmethod
def pre_delete_signal(sender, instance, **kwargs): def pre_delete_signal(sender, instance, **kwargs):
profile = instance.user.userprofile_set.get() profile = instance.user.userprofile
profile.balance -= instance.amount profile.balance -= instance.amount
profile.save() profile.save()
@ -87,8 +87,8 @@ class VirtualTransaction(models.Model):
@staticmethod @staticmethod
def moveMoney(fromUser, toUser, amount, commit=True): def moveMoney(fromUser, toUser, amount, commit=True):
if not (fromUser == toUser): if not (fromUser == toUser):
fromProfile = fromUser.userprofile_set.get() fromProfile = fromUser.userprofile
toProfile = toUser.userprofile_set.get() toProfile = toUser.userprofile
fromProfile.balance -= amount fromProfile.balance -= amount
toProfile.balance += amount toProfile.balance += amount
if commit: if commit: