Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
[Fixes #7] Users Avatar and Groups Logo appear as broken img
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Feb 10, 2020
1 parent 0e29d4b commit 486d4e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions avatar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import io
import hashlib
from shutil import copyfile

from django.db import models
from django.conf import settings
Expand Down Expand Up @@ -111,6 +112,16 @@ def create_thumbnail(self, size, quality=None):
thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)

def avatar_url(self, size):
try:
_base_path = os.path.split(self.avatar_name(size))[0]
_upload_path = os.path.split(
self.avatar.storage.url(self.avatar_name(size)))[1]
_upload_path = os.path.join(_base_path, _upload_path)
if not self.avatar.storage.exists(_upload_path):
copyfile(self.avatar.storage.path(self.avatar_name(size)),
self.avatar.storage.path(_upload_path))
except BaseException:
pass
return self.avatar.storage.url(self.avatar_name(size))

def avatar_name(self, size):
Expand Down

0 comments on commit 486d4e2

Please sign in to comment.