{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/comments/65925348","id":65925348,"diff_hunk":"@@ -2,119 +2,113 @@\n     Helpers for accessing comprehensive theming related variables.\n \"\"\"\n import os\n+import logging\n \n from django.conf import settings, ImproperlyConfigured\n-from django.core.cache import cache\n \n import waffle\n from path import Path\n from threadlocals.threadlocals import get_current_request\n \n-from ecommerce.theming.models import SiteTheme\n+logger = logging.getLogger(__name__)\n \n \n-def get_current_site():\n+def get_current_site_theme():\n     \"\"\"\n-    Return current site.\n+    Return current site theme object. Returns None if theming is disabled.\n \n     Returns:\n-         (django.contrib.sites.models.Site): current site\n+         (ecommerce.theming.models.SiteTheme): site theme object for the current site.\n     \"\"\"\n+    # Return None if theming is disabled\n+    if not is_comprehensive_theming_enabled():\n+        return None\n+\n     request = get_current_request()\n     if not request:\n         return None\n-    return getattr(request, 'site', None)\n+    return getattr(request, 'site_theme', None)\n \n \n-def is_comprehensive_theming_enabled():\n+def get_current_theme():\n     \"\"\"\n-    Returns boolean indicating whether comprehensive theming functionality is enabled or disabled.\n-\n-    Example:\n-        >> is_comprehensive_theming_enabled()\n-        True\n+    Return current theme object. Returns None if theming is disabled.\n \n     Returns:\n-         (bool): True if comprehensive theming is enabled else False\n+         (ecommerce.theming.helpers.Theme): theme object for the current theme.\n     \"\"\"\n-    if not settings.ENABLE_COMPREHENSIVE_THEMING:\n-        # Return False if theming is disabled\n-        return False\n-\n-    # return False if theming is disabled on runtime and function is called during request processing\n-    if bool(get_current_request()):\n-        # check if theming is disabled on runtime\n-        if waffle.switch_is_active(settings.DISABLE_THEMING_ON_RUNTIME_SWITCH):\n-            # function called in request processing and theming is disabled on runtime\n-            return False\n+    # Return None if theming is disabled\n+    if not is_comprehensive_theming_enabled():\n+        return None\n \n-    # Theming is enabled\n-    return True\n+    site_theme = get_current_site_theme()\n+    if not site_theme:\n+        return None\n+    try:\n+        return Theme(\n+            name=site_theme.theme_dir_name,\n+            theme_dir_name=site_theme.theme_dir_name,\n+            themes_base_dir=get_theme_base_dir(site_theme.theme_dir_name),\n+        )\n+    except ValueError as e:\n+        # Log exception message and return None, so that open source theme is used instead\n+        logger.exception('Theme not found in any of the themes dirs. [%s]', e)\n+        return None\n \n \n-def get_site_theme_cache_key(site):\n+def get_theme_base_dir(theme_dir_name, suppress_error=False):\n     \"\"\"\n-    Return cache key for the given site.\n-\n-    Example:\n-        >> site = Site(domain='red-theme.org', name='Red Theme')\n-        >> get_site_theme_cache_key(site)\n-        'theming.site.red-theme.org'\n+    Returns absolute path to the directory that contains the given theme.\n \n-    Parameters:\n-        site (django.contrib.sites.models.Site): site where key needs to generated\n+    Args:\n+        theme_dir_name (str): theme directory name to get base path for\n+        suppress_error (bool): if True function will return None if theme is not found instead of raising an error\n     Returns:\n-        (str): a key to be used as cache key\n-    \"\"\"\n-    cache_key = \"theming.site.{domain}\".format(\n-        domain=site.domain\n-    )\n-    return cache_key\n-\n-\n-def cache_site_theme_dir(site, theme_dir):\n+        (str): Base directory that contains the given theme\n     \"\"\"\n-    Cache site's theme directory.\n+    for themes_dir in get_theme_base_dirs():\n+        if theme_dir_name in (_dir for _dir in os.listdir(themes_dir) if is_theme_dir(themes_dir / _dir)):\n+            return themes_dir\n \n-    Example:\n-        >> site = Site(domain='red-theme.org', name='Red Theme')\n-        >> cache_site_theme_dir(site, 'red-theme')\n+    if suppress_error:","path":"ecommerce/theming/helpers.py","position":119,"original_position":119,"commit_id":"36637cbaf30511047e18e34dd45b39dac39f0340","original_commit_id":"36637cbaf30511047e18e34dd45b39dac39f0340","user":{"login":"mattdrayer","id":4520595,"avatar_url":"https://avatars.githubusercontent.com/u/4520595?v=3","gravatar_id":"","url":"https://api.github.com/users/mattdrayer","html_url":"https://github.com/mattdrayer","followers_url":"https://api.github.com/users/mattdrayer/followers","following_url":"https://api.github.com/users/mattdrayer/following{/other_user}","gists_url":"https://api.github.com/users/mattdrayer/gists{/gist_id}","starred_url":"https://api.github.com/users/mattdrayer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattdrayer/subscriptions","organizations_url":"https://api.github.com/users/mattdrayer/orgs","repos_url":"https://api.github.com/users/mattdrayer/repos","events_url":"https://api.github.com/users/mattdrayer/events{/privacy}","received_events_url":"https://api.github.com/users/mattdrayer/received_events","type":"User","site_admin":false},"body":"Does it make sense to write a log entry here if we are suppressing the error?  I don't want to create additional noise if it's not useful information.","created_at":"2016-06-06T16:47:30Z","updated_at":"2016-06-06T16:47:30Z","html_url":"https://github.com/edx/ecommerce/pull/749#discussion_r65925348","pull_request_url":"https://api.github.com/repos/edx/ecommerce/pulls/749","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments/65925348"},"html":{"href":"https://github.com/edx/ecommerce/pull/749#discussion_r65925348"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/749"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/749","id":70676515,"html_url":"https://github.com/edx/ecommerce/pull/749","diff_url":"https://github.com/edx/ecommerce/pull/749.diff","patch_url":"https://github.com/edx/ecommerce/pull/749.patch","issue_url":"https://api.github.com/repos/edx/ecommerce/issues/749","number":749,"state":"open","locked":false,"title":"MAYN-234: Update Otto Theming app so that COMPREHENSIVE_THEME_DIRS is a list of  directories","user":{"login":"saleem-latif","id":7114956,"avatar_url":"https://avatars.githubusercontent.com/u/7114956?v=3","gravatar_id":"","url":"https://api.github.com/users/saleem-latif","html_url":"https://github.com/saleem-latif","followers_url":"https://api.github.com/users/saleem-latif/followers","following_url":"https://api.github.com/users/saleem-latif/following{/other_user}","gists_url":"https://api.github.com/users/saleem-latif/gists{/gist_id}","starred_url":"https://api.github.com/users/saleem-latif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saleem-latif/subscriptions","organizations_url":"https://api.github.com/users/saleem-latif/orgs","repos_url":"https://api.github.com/users/saleem-latif/repos","events_url":"https://api.github.com/users/saleem-latif/events{/privacy}","received_events_url":"https://api.github.com/users/saleem-latif/received_events","type":"User","site_admin":false},"body":"Hi @mattdrayer , @clintonb  \r\n\r\nKindly review this PR, it contains changes for MAYN-234.\r\n\r\n__Description of MAYN-234:__\r\n`COMPREHENSIVE_THEME_DIR` setting is used by theming app to figure out where themes are placed, currently we can specify only one theme directory and all themes must be placed inside this directory. This restriction reduces flexibility during theme setup via configuration. \r\nConvert `COMPREHENSIVE_THEME_DIR` to a list of directories so that multiple themes directories can be used with one or more theme in each directory.\r\nUpdating `COMPREHENSIVE_THEME_DIR` to list will require changes in \r\n\r\n1. Rename `COMPREHENSIVE_THEME_DIR` to `COMPREHENSIVE_THEME_DIRS`\r\n2. Static files finders and storage\r\n3. template loaders\r\n4. template compressors\r\n5. theming helpers\r\n6. management commands for compiling theme sass\r\n\r\n__NOTE:__\r\nThis PR is dependent on configuration [PR#3065](https://github.com/edx/configuration/pull/3065) (related to [MAYN-281](https://openedx.atlassian.net/browse/MAYN-281)) and should only be merged after configuration changes.\r\n\r\n","created_at":"2016-05-19T11:16:34Z","updated_at":"2016-06-06T16:47:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a0d058e483c79723759a25209cbdf04e45c70357","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce/pulls/749/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce/pulls/749/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce/issues/749/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/36637cbaf30511047e18e34dd45b39dac39f0340","head":{"label":"edx:saleem-latif/MAYN-234","ref":"saleem-latif/MAYN-234","sha":"36637cbaf30511047e18e34dd45b39dac39f0340","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":30175039,"name":"ecommerce","full_name":"edx/ecommerce","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products.","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce/deployments","created_at":"2015-02-02T06:55:15Z","updated_at":"2016-05-28T15:05:35Z","pushed_at":"2016-06-06T15:08:10Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"","size":10539,"stargazers_count":34,"watchers_count":34,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":13,"forks":34,"open_issues":13,"watchers":34,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"8a514a638a3f90a68a89eba059a3c9b8735b30c0","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":30175039,"name":"ecommerce","full_name":"edx/ecommerce","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products.","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce/deployments","created_at":"2015-02-02T06:55:15Z","updated_at":"2016-05-28T15:05:35Z","pushed_at":"2016-06-06T15:08:10Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"","size":10539,"stargazers_count":34,"watchers_count":34,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":13,"forks":34,"open_issues":13,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/749"},"html":{"href":"https://github.com/edx/ecommerce/pull/749"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce/issues/749"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce/issues/749/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/749/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/749/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce/statuses/36637cbaf30511047e18e34dd45b39dac39f0340"}}}}
{"actor":{"display_login":"mattdrayer"}}