Files
edx-platform/cms/lib/ai_aside_summary_config.py
German 3f20c75043 feat: [ACADEMIC-16209] Unit summary settings (#32855)
* feat: [ACADEMIC-16209] Unit summary settings

[https://jira.2u.com/browse/ACADEMIC-16209](https://jira.2u.com/browse/ACADEMIC-16209)

1. Add unit xpert unit summaries settings behind flag `summaryhook_summaries_configuration` added [here](https://github.com/edx/ai-aside/pull/45/files)
2. Only show the checkbox when the value is a `boolean` otherwise the feature is considerer `disabled` by the flag.
3. Update block handler to update this value via `api` exposed [here](https://github.com/edx/ai-aside/pull/43)
4. Create `AiAsideSummary` configuration class to provide access to the `ai_aside.api` endpoints.
2023-08-21 14:55:22 -03:00

57 lines
1.8 KiB
Python

"""
This file contains AiAsideSummaryConfig class that take a `course_key` and return if:
* the waffle flag is enabled in ai_aside
* is the summary is enabled for a given unit_key
* change the settings for a given unit_key
"""
class AiAsideSummaryConfig:
"""
Configuration for the AI Aside summary configuration.
"""
def __init__(self, course_key):
self.course_key = course_key
def __str__(self):
"""
Return user-friendly string.
"""
return f"AIAside summary configuration for {self.course_key} course"
def is_enabled(self):
"""
Define if the waffle flag is enabled for the current course_key
"""
try:
from ai_aside.config_api.api import is_summary_config_enabled
return is_summary_config_enabled(self.course_key)
except (ModuleNotFoundError, ImportError):
return False
def is_summary_enabled(self, unit_key=None):
"""
Define if the summary configuration is enabled in ai_aside
"""
try:
from ai_aside.config_api.api import is_course_settings_present, is_summary_enabled
if not is_course_settings_present(self.course_key):
return None
return is_summary_enabled(self.course_key, unit_key)
except (ModuleNotFoundError, ImportError):
return None
def set_summary_settings(self, unit_key, settings=None):
"""
Define the settings for a given unit_key in ai_aside
"""
if settings is None:
return None
try:
from ai_aside.config_api.api import set_unit_settings
return set_unit_settings(self.course_key, unit_key, settings)
except (ModuleNotFoundError, ImportError):
return None