From ac45850d15285adc21d3845eec528376ee189cc0 Mon Sep 17 00:00:00 2001 From: Aamish Baloch Date: Wed, 5 Jul 2017 18:50:01 +0500 Subject: [PATCH] YONK-691: Configurable profile image sizes --- cms/envs/aws.py | 7 +++++++ cms/envs/common.py | 9 +++++++++ lms/envs/aws.py | 7 +++++++ lms/envs/common.py | 9 +++++++++ .../djangoapps/user_api/accounts/image_helpers.py | 11 +++-------- .../djangoapps/user_api/accounts/tests/test_api.py | 2 +- .../user_api/accounts/tests/test_image_helpers.py | 2 +- .../djangoapps/user_api/accounts/tests/test_views.py | 4 ++-- 8 files changed, 39 insertions(+), 12 deletions(-) diff --git a/cms/envs/aws.py b/cms/envs/aws.py index fdf08b2e48..1474eca80a 100644 --- a/cms/envs/aws.py +++ b/cms/envs/aws.py @@ -501,3 +501,10 @@ HELP_TOKENS_BOOKS = ENV_TOKENS.get('HELP_TOKENS_BOOKS', HELP_TOKENS_BOOKS) ############## Settings for CourseGraph ############################ COURSEGRAPH_JOB_QUEUE = ENV_TOKENS.get('COURSEGRAPH_JOB_QUEUE', LOW_PRIORITY_QUEUE) + +############## Settings for Profile Image Size ###################### + +PROFILE_IMAGE_SIZES_MAP = ENV_TOKENS.get( + 'PROFILE_IMAGE_SIZES_MAP', + PROFILE_IMAGE_SIZES_MAP +) diff --git a/cms/envs/common.py b/cms/envs/common.py index 30a341e09f..47cc327272 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1335,3 +1335,12 @@ RECALCULATE_GRADES_ROUTING_KEY = LOW_PRIORITY_QUEUE ############## Settings for CourseGraph ############################ COURSEGRAPH_JOB_QUEUE = LOW_PRIORITY_QUEUE + +############## Settings for Profile Image Size ###################### + +PROFILE_IMAGE_SIZES_MAP = { + 'full': 500, + 'large': 120, + 'medium': 50, + 'small': 30 +} diff --git a/lms/envs/aws.py b/lms/envs/aws.py index e9ea2bd435..50ff933df8 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -1005,3 +1005,10 @@ ICP_LICENSE = ENV_TOKENS.get('ICP_LICENSE', None) ############## Settings for CourseGraph ############################ COURSEGRAPH_JOB_QUEUE = ENV_TOKENS.get('COURSEGRAPH_JOB_QUEUE', LOW_PRIORITY_QUEUE) + +############## Settings for Profile Image Size ###################### + +PROFILE_IMAGE_SIZES_MAP = ENV_TOKENS.get( + 'PROFILE_IMAGE_SIZES_MAP', + PROFILE_IMAGE_SIZES_MAP +) diff --git a/lms/envs/common.py b/lms/envs/common.py index 03bec41bbb..18f7dd9401 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3202,3 +3202,12 @@ COURSES_API_CACHE_TIMEOUT = 3600 # Value is in seconds ############## Settings for CourseGraph ############################ COURSEGRAPH_JOB_QUEUE = LOW_PRIORITY_QUEUE + +############## Settings for Profile Image Size ###################### + +PROFILE_IMAGE_SIZES_MAP = { + 'full': 500, + 'large': 120, + 'medium': 50, + 'small': 30 +} diff --git a/openedx/core/djangoapps/user_api/accounts/image_helpers.py b/openedx/core/djangoapps/user_api/accounts/image_helpers.py index 71f8f6be56..648e6e3dd1 100644 --- a/openedx/core/djangoapps/user_api/accounts/image_helpers.py +++ b/openedx/core/djangoapps/user_api/accounts/image_helpers.py @@ -14,13 +14,8 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_ PROFILE_IMAGE_FILE_EXTENSION = 'jpg' # All processed profile images are converted to JPEGs -PROFILE_IMAGE_SIZES_MAP = { - 'full': 500, - 'large': 120, - 'medium': 50, - 'small': 30 -} -_PROFILE_IMAGE_SIZES = PROFILE_IMAGE_SIZES_MAP.values() + +_PROFILE_IMAGE_SIZES = settings.PROFILE_IMAGE_SIZES_MAP.values() def get_profile_image_storage(): @@ -60,7 +55,7 @@ def _get_profile_image_urls(name, storage, file_extension=PROFILE_IMAGE_FILE_EXT ) return '{}?v={}'.format(url, version) if version is not None else url - return {size_display_name: _make_url(size) for size_display_name, size in PROFILE_IMAGE_SIZES_MAP.items()} + return {size_display_name: _make_url(size) for size_display_name, size in settings.PROFILE_IMAGE_SIZES_MAP.items()} def get_profile_image_names(username): diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py index 1fe87bc528..129cf9883e 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py @@ -246,7 +246,7 @@ class TestAccountApi(UserSettingsEventTestMixin, TestCase): @attr(shard=2) @patch('openedx.core.djangoapps.user_api.accounts.image_helpers._PROFILE_IMAGE_SIZES', [50, 10]) @patch.dict( - 'openedx.core.djangoapps.user_api.accounts.image_helpers.PROFILE_IMAGE_SIZES_MAP', + 'django.conf.settings.PROFILE_IMAGE_SIZES_MAP', {'full': 50, 'small': 10}, clear=True ) diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py b/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py index 41014691b5..ddd9f961e5 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py @@ -18,7 +18,7 @@ TEST_PROFILE_IMAGE_UPLOAD_DT = datetime.datetime(2002, 1, 9, 15, 43, 01, tzinfo= @attr(shard=2) -@patch.dict('openedx.core.djangoapps.user_api.accounts.image_helpers.PROFILE_IMAGE_SIZES_MAP', TEST_SIZES, clear=True) +@patch.dict('django.conf.settings.PROFILE_IMAGE_SIZES_MAP', TEST_SIZES, clear=True) @skip_unless_lms class ProfileImageUrlTestCase(TestCase): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py index 7bd4b79a10..16d36e6401 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py @@ -200,7 +200,7 @@ class TestOwnUsernameAPI(CacheIsolationTestCase, UserAPITestCase): @skip_unless_lms @patch('openedx.core.djangoapps.user_api.accounts.image_helpers._PROFILE_IMAGE_SIZES', [50, 10]) @patch.dict( - 'openedx.core.djangoapps.user_api.accounts.image_helpers.PROFILE_IMAGE_SIZES_MAP', + 'django.conf.settings.PROFILE_IMAGE_SIZES_MAP', {'full': 50, 'small': 10}, clear=True ) @@ -608,7 +608,7 @@ class TestAccountsAPI(CacheIsolationTestCase, UserAPITestCase): verify_change_info(name_change_info[1], "Mickey Mouse", self.user.username, "Donald Duck") @patch.dict( - 'openedx.core.djangoapps.user_api.accounts.image_helpers.PROFILE_IMAGE_SIZES_MAP', + 'django.conf.settings.PROFILE_IMAGE_SIZES_MAP', {'full': 50, 'medium': 30, 'small': 10}, clear=True )