{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/comments/59529962","id":59529962,"diff_hunk":"@@ -0,0 +1,264 @@\n+\"\"\"\n+    Helpers for accessing comprehensive theming related variables.\n+\"\"\"\n+import os\n+\n+from django.conf import settings, ImproperlyConfigured\n+from django.core.cache import cache\n+\n+from path import Path\n+from threadlocals.threadlocals import get_current_request\n+\n+\n+def get_current_site():\n+    \"\"\"\n+    Return current site.\n+\n+    Returns:\n+         (django.contrib.sites.models.Site): current site\n+    \"\"\"\n+    request = get_current_request()\n+    if not request:\n+        return None\n+    return getattr(request, 'site', None)\n+\n+\n+def is_comprehensive_theming_enabled():\n+    \"\"\"\n+    Returns boolean indicating whether comprehensive theming functionality is enabled or disabled.\n+    Example:\n+        >> is_comprehensive_theming_enabled()\n+        True\n+\n+    Returns:\n+         (bool): True if comprehensive theming is enabled else False\n+    \"\"\"\n+    return settings.ENABLE_COMPREHENSIVE_THEMING\n+\n+\n+def get_site_theme_cache_key(site):\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+\n+    Parameters:\n+        site (django.contrib.sites.models.Site): site where key needs to generated\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+    \"\"\"\n+    Cache site's theme directory.\n+\n+    Example:\n+        >> site = Site(domain='red-theme.org', name='Red Theme')\n+        >> cache_site_theme_dir(site, 'red-theme')\n+\n+    Parameters:\n+        site (django.contrib.sites.models.Site): site for to cache\n+        theme_dir (str): theme directory for the given site\n+    \"\"\"\n+    cache.set(get_site_theme_cache_key(site), theme_dir, settings.THEME_CACHE_TIMEOUT)\n+\n+\n+def get_current_theme_template_dirs():\n+    \"\"\"\n+    Returns template directories for the current theme.\n+\n+    Example:\n+        >> get_current_theme_template_dirs()\n+        [\n+            '/edx/app/ecommerce/ecommerce/themes/red-theme/templates/',\n+            '/edx/app/ecommerce/ecommerce/themes/red-theme/templates/oscar/',\n+        ]\n+\n+    Returns:\n+        (list): list of directories containing theme templates.\n+    \"\"\"\n+    site_theme_dir = get_theme_dir()\n+    if not site_theme_dir:\n+        return None\n+\n+    template_paths = [\n+        site_theme_dir / 'templates',\n+        site_theme_dir / 'templates' / 'oscar',\n+    ]\n+    return template_paths\n+\n+\n+def get_all_theme_template_dirs():\n+    \"\"\"\n+    Returns template directories for all the themes.\n+\n+    Example:\n+        >> get_all_theme_template_dirs()\n+        [\n+            '/edx/app/ecommerce/ecommerce/themes/red-theme/templates/',\n+            '/edx/app/ecommerce/ecommerce/themes/red-theme/templates/oscar/',\n+        ]\n+\n+    Returns:\n+        (list): list of directories containing theme templates.\n+    \"\"\"\n+    themes = get_themes()\n+    template_paths = list()\n+\n+    for theme in themes:\n+        template_paths.extend(\n+            [\n+                theme.path / 'templates',\n+                theme.path / 'templates' / 'oscar',\n+            ],\n+        )\n+    return template_paths\n+\n+\n+def get_theme_dir():\n+    \"\"\"\n+    Return absolute directory for the current theme.\n+\n+    Example:\n+        >> get_theme_dir()\n+        '/edx/app/ecommerce/ecommerce/themes/red-theme/'\n+\n+    Returns:\n+         (Path): absolute directory for the current theme\n+    \"\"\"\n+    site = get_current_site()\n+\n+    if not is_comprehensive_theming_enabled():\n+        return None\n+\n+    site_theme = site and site.themes.first()\n+    theme_dir = getattr(site_theme, \"theme_dir_name\") if site_theme else None\n+\n+    if theme_dir:\n+        themes_dir = get_base_themes_dir()\n+\n+        return Path(themes_dir) / theme_dir","path":"ecommerce/theming/helpers.py","position":148,"original_position":148,"commit_id":"3e2c5335ebff8d1317b7e1fab77158720a98a7cf","original_commit_id":"6538bd3b31e83ce1474df26724b49b32c98ca6aa","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":"Done","created_at":"2016-04-13T11:07:26Z","updated_at":"2016-04-13T11:07:26Z","html_url":"https://github.com/edx/ecommerce/pull/649#discussion_r59529962","pull_request_url":"https://api.github.com/repos/edx/ecommerce/pulls/649","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments/59529962"},"html":{"href":"https://github.com/edx/ecommerce/pull/649#discussion_r59529962"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/649"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/649","id":64941282,"html_url":"https://github.com/edx/ecommerce/pull/649","diff_url":"https://github.com/edx/ecommerce/pull/649.diff","patch_url":"https://github.com/edx/ecommerce/pull/649.patch","issue_url":"https://api.github.com/repos/edx/ecommerce/issues/649","number":649,"state":"open","locked":false,"title":"WL-330: Multi-Site Branding in Otto","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 \r\n\r\nI have completed changes related to WL-330, Kindly review these changes and share your thoughts on this.\r\n\r\n__Description of WL-330:__\r\nChanges included customization of\r\n* Static Files Finders and Static Storage\r\n* Sass compilation workflow\r\n* Template Loaders\r\n\r\nand helper functions for enabling comprehensive theming for Otto.\r\n","created_at":"2016-04-01T13:04:27Z","updated_at":"2016-04-13T11:07:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e031b1de02d4ce028a25343388b67450df4df33","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce/pulls/649/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce/pulls/649/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce/issues/649/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/3e2c5335ebff8d1317b7e1fab77158720a98a7cf","head":{"label":"edx:saleem-latif/WL-330","ref":"saleem-latif/WL-330","sha":"3e2c5335ebff8d1317b7e1fab77158720a98a7cf","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-04-08T10:19:34Z","pushed_at":"2016-04-13T11:06:22Z","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":10015,"stargazers_count":30,"watchers_count":30,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":9,"forks":31,"open_issues":9,"watchers":30,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"c17a6ea8a1acaf1e9aa92adf81193f142d649cb7","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-04-08T10:19:34Z","pushed_at":"2016-04-13T11:06:22Z","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":10015,"stargazers_count":30,"watchers_count":30,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":9,"forks":31,"open_issues":9,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/649"},"html":{"href":"https://github.com/edx/ecommerce/pull/649"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce/issues/649"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce/issues/649/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/649/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/649/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce/statuses/3e2c5335ebff8d1317b7e1fab77158720a98a7cf"}}}}