Skip to content

Commit

Permalink
Merge pull request #1700 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
feat(profile):Added profile pic url to models
  • Loading branch information
Aashish Vinu authored Dec 2, 2023
2 parents 943c71c + d4cc3ca commit 54b9ce2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 1 addition & 12 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,10 @@ def get_percentile(self, obj):
try:
user_count = Wallet.objects.filter(karma__lt=obj.wallet_user.karma).count()
usr_count = User.objects.all().count()
if usr_count == 0:
return 0
return (user_count * 100) / usr_count
return 0 if usr_count == 0 else (user_count * 100) / usr_count
except Exception as e:
return 0

def get_profile_pic(self, obj):
fs = FileSystemStorage()
path = f'user/profile/{obj.id}.png'
if fs.exists(path):
profile_pic = f"{BE_DOMAIN_NAME}{fs.url(path)}"
else:
profile_pic = obj.profile_pic
return profile_pic

def get_roles(self, obj):
return list({link.role.title for link in obj.user_role_link_user.filter(verified=True)})

Expand Down
11 changes: 9 additions & 2 deletions db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from django.db import models
from .managers import user_manager

from django.core.files.storage import FileSystemStorage
from decouple import config as decouple_config
# fmt: off
# noinspection PyPep8

Expand All @@ -19,7 +20,6 @@ class User(models.Model):
dob = models.DateField(blank=True, null=True)
admin = models.BooleanField(default=False)
exist_in_guild = models.BooleanField(default=False)
profile_pic = models.CharField(max_length=200, blank=True, null=True)
district = models.ForeignKey("District", on_delete=models.CASCADE, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
suspended_at = models.DateTimeField(blank=True, null=True)
Expand All @@ -40,6 +40,13 @@ def fullname(self):

return f"{self.first_name} {self.last_name}"

@property
def profile_pic(self):
fs = FileSystemStorage()
path = f'user/profile/{self.id}.png'
if fs.exists(path):
return f"{decouple_config('BE_DOMAIN_NAME')}{fs.url(path)}"


class UserReferralLink(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4)
Expand Down

0 comments on commit 54b9ce2

Please sign in to comment.