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)
order.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance}
return {'success': True, 'balance': request.user.userprofile.balance}
def bulkBuy(self, request):
"""Buy a :class:`Buyable <buyable.models.Buyable>` item.
@ -179,7 +179,7 @@ class BuyableItemHandler(BaseHandler):
p.save(saveOrder=False)
order.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance}
return {'success': True, 'balance': request.user.userprofile.balance}
class BuyableTypeHandler(BaseHandler):
@ -290,7 +290,7 @@ class TransactionTransactHandler(BaseHandler):
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.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance}
return {'success': True, 'balance': request.user.userprofile.balance}
class TransactionTypeHandler(BaseHandler):
"""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.")
trans = VirtualTransaction(user=request.user, recipient=recipient, amount=amount, comment=comment)
trans.save()
return {'success': True, 'balance': request.user.userprofile_set.get().balance}
return {'success': True, 'balance': request.user.userprofile.balance}
class AccountBalanceHandler(BaseHandler):
"""Handler for the user's account balance"""
@ -357,7 +357,7 @@ class AccountBalanceHandler(BaseHandler):
@manglePluginPerms
def read(self, request):
"""Returns the user's current account balance"""
balance = request.user.userprofile_set.get().balance
balance = request.user.userprofile.balance
return {'balance': balance}
class AuthBlobHandler(BaseHandler):

View File

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

View File

@ -45,7 +45,7 @@
{% if user.is_authenticated %}
<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">
<input placeholder="Suche und kaufe..." class="search-query autocomplete"
type="search" name="search_term" value="Lade Daten..."

View File

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