Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Refactor the account avatars path from a relative to absolute

NyanKiyoshic0bad034a633
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8bba28b1a3..d64439b735 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Drop support for Django 2.1 and Django 1.11 (previous LTS)
- Fix variants for juices in example data - #3926 by @michaljelonek
- Fix logo in docs - #3928 by @michaljelonek
+- Refactor the account avatars path from a relative to absolute - #3938 by @NyanKiyoshi
## 2.4.0
diff --git a/saleor/account/utils.py b/saleor/account/utils.py
index 273afca405..f3e69220f1 100644
--- a/saleor/account/utils.py
+++ b/saleor/account/utils.py
@@ -1,10 +1,15 @@
import os
+import os.path
import random
+from django.conf import settings
from django.core.files import File
from ..checkout import AddressType
+AVATARS_PATH = os.path.join(
+ settings.PROJECT_ROOT, 'saleor', 'static', 'images', 'avatars')
+
def store_user_address(user, address, address_type):
"""Add address to user address book and set as default one."""
@@ -61,7 +66,6 @@ def get_user_last_name(user):
def get_random_avatar():
"""Return random avatar picked from a pool of static avatars."""
- avatars_dir = 'saleor/static/images/avatars/'
- avatar_name = random.choice(os.listdir(avatars_dir))
- avatar_path = os.path.join(avatars_dir, avatar_name)
+ avatar_name = random.choice(os.listdir(AVATARS_PATH))
+ avatar_path = os.path.join(AVATARS_PATH, avatar_name)
return File(open(avatar_path, 'rb'), name=avatar_name)