From 91f549b69e55e992fd5106ade424961af2526a4c Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Wed, 20 Nov 2019 00:21:50 +0100 Subject: [PATCH] Use userprofile directly instead of userprofile_set --- k4ever/api2/handlers.py | 10 +++++----- k4ever/buyable/models.py | 10 +++++----- k4ever/main/templates/main/navbar-content.html | 2 +- k4ever/transaction/models.py | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py index 2d0664a..95a0ea0 100644 --- a/k4ever/api2/handlers.py +++ b/k4ever/api2/handlers.py @@ -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 ` 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 ` @@ -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): diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index 427ed8c..be9f15f 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -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() diff --git a/k4ever/main/templates/main/navbar-content.html b/k4ever/main/templates/main/navbar-content.html index 681132f..70daf23 100644 --- a/k4ever/main/templates/main/navbar-content.html +++ b/k4ever/main/templates/main/navbar-content.html @@ -45,7 +45,7 @@ {% if user.is_authenticated %}
- Kontostand: {{ user.userprofile_set.get.balance|floatformat:2 }} € + Kontostand: {{ user.userprofile.balance|floatformat:2 }} €