-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create django admin for default enrollments
- Loading branch information
1 parent
a274850
commit fa7ec13
Showing
6 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Your project description goes here. | ||
""" | ||
|
||
__version__ = "4.28.0" | ||
__version__ = "4.28.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Utils for interacting with cache interfaces. | ||
""" | ||
import hashlib | ||
|
||
from edx_django_utils.cache import TieredCache | ||
|
||
from django.conf import settings | ||
|
||
from enterprise import __version__ as code_version | ||
|
||
CACHE_KEY_SEP = ':' | ||
DEFAULT_NAMESPACE = 'edx-enterprise-default' | ||
|
||
|
||
def versioned_cache_key(*args): | ||
""" | ||
Utility to produce a versioned cache key, which includes | ||
an optional settings variable and the current code version, | ||
so that we can perform key-based cache invalidation. | ||
""" | ||
components = [str(arg) for arg in args] | ||
components.append(code_version) | ||
if stamp_from_settings := getattr(settings, 'CACHE_KEY_VERSION_STAMP', None): | ||
components.append(stamp_from_settings) | ||
decoded_cache_key = CACHE_KEY_SEP.join(components) | ||
return hashlib.sha512(decoded_cache_key.encode()).hexdigest() | ||
|
||
|
||
def request_cache(namespace=DEFAULT_NAMESPACE): | ||
""" | ||
Helper that returns a namespaced RequestCache instance. | ||
""" | ||
return TieredCache(namespace=namespace) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Python API for interacting with content metadata. | ||
TODO: refactor subsidy_access_policy/content_metadata_api.py | ||
into this module. | ||
""" | ||
import logging | ||
|
||
from requests.exceptions import HTTPError | ||
|
||
from django.conf import settings | ||
from django.core.cache import cache | ||
|
||
from edx_django_utils.cache import TieredCache | ||
from enterprise.api_client.enterprise_catalog import EnterpriseCatalogApiClient | ||
from enterprise.cache_utils import versioned_cache_key | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
DEFAULT_CACHE_TIMEOUT = getattr(settings, 'CONTENT_METADATA_CACHE_TIMEOUT', 60 * 5) | ||
|
||
|
||
def get_and_cache_catalog_content_metadata(enterprise_customer_uuid, content_key, timeout=None): | ||
""" | ||
Returns the metadata corresponding to the requested | ||
``content_key`` within catalogs associated to the provided ``enterprise_customer``. | ||
The response is cached in a ``TieredCache`` (meaning in both the RequestCache, | ||
_and_ the django cache for the configured expiration period). | ||
Returns: A dict with content metadata for the given key. | ||
Raises: An HTTPError if there's a problem getting the content metadata | ||
via the enterprise-catalog service. | ||
""" | ||
cache_key = versioned_cache_key('contains_content_key', enterprise_customer_uuid, content_key) | ||
cached_response = TieredCache.get_cached_response(cache_key) | ||
if cached_response.is_found: | ||
logger.info(f'cache hit for enterprise customer {enterprise_customer_uuid} and content {content_key}') | ||
return cached_response.value | ||
|
||
try: | ||
result = EnterpriseCatalogApiClient().get_content_metadata_content_identifier( | ||
enterprise_uuid=enterprise_customer_uuid, | ||
content_id=content_key, | ||
) | ||
except HTTPError as exc: | ||
raise exc | ||
|
||
logger.info( | ||
'Fetched catalog for customer %s and content_key %s. Result = %s', | ||
enterprise_customer_uuid, | ||
content_key, | ||
result, | ||
) | ||
TieredCache.set_all_tiers(cache_key, result, timeout or DEFAULT_CACHE_TIMEOUT) | ||
return result | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters