Skip to content

Commit 4d840f1

Browse files
Fetch student photo from Google account using email in QRVerifyUpdateView
1 parent 0d8ea7c commit 4d840f1

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

api/views.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from .utils.rebate_checker import is_student_on_rebate
1717
from allauth.socialaccount.models import SocialAccount
18+
from django.contrib.auth.models import User
1819

1920
class LogoutView(APIView):
2021
"""
@@ -173,11 +174,15 @@ def post(self, request):
173174
try:
174175
card = MessCard.objects.get(id=card_id)
175176
card_return_data = QRVerifySerializer(card).data
176-
if not card_return_data.get('student').get('photo'):
177-
socialaccount_obj = SocialAccount.objects.filter(
178-
provider="google", user_id=card_return_data['student']['id']
179-
)
180-
card_return_data['student']['photo'] = socialaccount_obj[0].extra_data.get('picture')
177+
try:
178+
if not card_return_data.get('student').get('photo'):
179+
user = User.objects.get(email=card.student.email)
180+
socialaccount_obj = SocialAccount.objects.filter(
181+
provider="google", user_id=user.id
182+
)
183+
card_return_data['student']['photo'] = socialaccount_obj[0].extra_data.get('picture')
184+
except:
185+
pass
181186
date = timezone.localtime().date()
182187
time = timezone.localtime().time()
183188
meal, _ = Meal.objects.get_or_create(mess_card=card, date=date)

0 commit comments

Comments
 (0)