Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
219af640b2
3 changed files with 21 additions and 7 deletions
|
|
@ -215,10 +215,11 @@ class Transaction(models.Model):
|
|||
def update_details(self, force_update=False):
|
||||
if not isinstance(self.details, dict):
|
||||
self.details = {}
|
||||
self.save()
|
||||
self.save()
|
||||
# detail = {'payer_name', 'payee_name', 'application_name', 'payer_avatar_url', 'payee_avatar_url', 'application_avatar_url'}
|
||||
is_updated = False
|
||||
if not self.details.get('payer_name'):
|
||||
print('update payer')
|
||||
if self.payer_type == TypeChoices.USER.value:
|
||||
payer_details: PublicUser = get_user_details(self.payer_id)
|
||||
self.details['payer_name'] = payer_details.first_name + payer_details.last_name
|
||||
|
|
@ -227,10 +228,12 @@ class Transaction(models.Model):
|
|||
payer_details = get_application_details(self.payer_id)
|
||||
self.details['payer_name'] = payer_details.name
|
||||
#TODO: get avatar from details
|
||||
|
||||
is_updated = True
|
||||
print("payer_details:", payer_details)
|
||||
print("is_updated:", is_updated)
|
||||
|
||||
if not self.details.get('payee_name'):
|
||||
print('update payee')
|
||||
if self.payee_type == TypeChoices.USER.value:
|
||||
payee_details: PublicUser = get_user_details(self.payee_id)
|
||||
self.details['payee_name'] = payee_details.first_name + payee_details.last_name
|
||||
|
|
@ -241,18 +244,24 @@ class Transaction(models.Model):
|
|||
#TODO: get avatar from details
|
||||
|
||||
is_updated = True
|
||||
print("payee_details:", payee_details)
|
||||
print("is_updated:", is_updated)
|
||||
|
||||
if not self.details.get('application_name'):
|
||||
print('update application')
|
||||
application_details = get_application_details(self.application_id)
|
||||
print('application_details:', application_details)
|
||||
try:
|
||||
self.details['application_name'] = application_details.name
|
||||
# TODO: get avatar from details
|
||||
|
||||
is_updated = True
|
||||
except Exception as e:
|
||||
pass
|
||||
print("something went wrong")
|
||||
print(e)
|
||||
|
||||
if is_updated:
|
||||
print('update details')
|
||||
self.save()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from apps.users.models import User
|
|||
from apps.wallet.constans import TypeChoices, StateChoices
|
||||
from apps.wallet.models import Transaction
|
||||
from apps.wallet.serializers import ApplicationDepositSerializer, ApplicationWithdrawSerializer, \
|
||||
ApplicationTransactionSerializer, ApplicationBalanceSerializer
|
||||
ApplicationTransactionSerializer, ApplicationBalanceSerializer, MyWalletSerializer
|
||||
|
||||
|
||||
def get_application(request):
|
||||
|
|
@ -37,12 +37,13 @@ class UserBalanceAPIView(generics.RetrieveAPIView):
|
|||
API for getting specified user or application balance.
|
||||
'''
|
||||
permission_classes = [IsAuthenticatedOrTokenHasScope]
|
||||
serializer_class = ApplicationBalanceSerializer
|
||||
serializer_class = MyWalletSerializer
|
||||
required_scopes = ['wallet.application:get_user_balance']
|
||||
|
||||
def get_object(self):
|
||||
user_uuid = self.kwargs.get('uuid')
|
||||
user = get_object_or_404(User.objects.all(), uuid=user_uuid)
|
||||
user, created = User.objects.get_or_create(uuid=user_uuid)
|
||||
# user = get_object_or_404(User.objects.all(), uuid=user_uuid)
|
||||
|
||||
return user
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ def login_as_client_credentials():
|
|||
auth=auth)
|
||||
|
||||
auth_data = response.json()
|
||||
|
||||
print(auth_data)
|
||||
|
||||
if 'access_token' in auth_data:
|
||||
auth_data['created_at'] = time.time()
|
||||
cache.set('wallet_access_token', auth_data, timeout=auth_data.get('expires_in')-5)
|
||||
|
|
@ -43,7 +46,8 @@ def login_as_client_credentials():
|
|||
|
||||
def get_client():
|
||||
access_token = login_as_client_credentials()['access_token']
|
||||
client = AuthenticatedClient(base_url="https://accounts.gooyal.com", token=access_token)
|
||||
# TODO: url
|
||||
client = AuthenticatedClient(base_url="http://accounts:8000", token=access_token)
|
||||
return client
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue