diff --git a/lms/envs/common.py b/lms/envs/common.py index a481acd33423..ed8d520660c9 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1342,7 +1342,12 @@ def _make_mako_template_dirs(settings): 'openedx.core.djangoapps.site_configuration.context_processors.configuration_context', # Mobile App processor (Detects if request is from the mobile app) - 'lms.djangoapps.mobile_api.context_processor.is_from_mobile_app' + 'lms.djangoapps.mobile_api.context_processor.is_from_mobile_app', + + # Context processor necesarry for the survey report message appear on the admin site + 'openedx.features.survey_report.context_processors.admin_extra_context' + + ] # Django templating diff --git a/lms/envs/production.py b/lms/envs/production.py index 45accf0c4ae1..72329b5a59f5 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1131,6 +1131,8 @@ def get_env_setting(setting): 'https://hooks.zapier.com/hooks/catch/11595998/3ouwv7m/') ANONYMOUS_SURVEY_REPORT = False +SURVEY_REPORT_CHECK_THRESHOLD = ENV_TOKENS.get('SURVEY_REPORT_CHECK_THRESHOLD', 6) + AVAILABLE_DISCUSSION_TOURS = ENV_TOKENS.get('AVAILABLE_DISCUSSION_TOURS', []) ############## NOTIFICATIONS EXPIRY ############## diff --git a/lms/envs/test.py b/lms/envs/test.py index 39996e857ac5..6d87a05848a1 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -663,6 +663,7 @@ ############## Settings for survey report ############## SURVEY_REPORT_EXTRA_DATA = {} SURVEY_REPORT_ENDPOINT = "https://example.com/survey_report" +SURVEY_REPORT_CHECK_THRESHOLD = 6 ANONYMOUS_SURVEY_REPORT = False ######################## Subscriptions API SETTINGS ######################## diff --git a/lms/templates/admin/base_site.html b/lms/templates/admin/base_site.html index 4ea86307696e..fa93f9c3e84a 100644 --- a/lms/templates/admin/base_site.html +++ b/lms/templates/admin/base_site.html @@ -20,3 +20,7 @@

{{ site_header|default:_('D {% endblock %} + +{% block header %}{{ block.super }} + {% include "survey_report/admin_banner.html" %} +{% endblock %} \ No newline at end of file diff --git a/openedx/features/survey_report/api.py b/openedx/features/survey_report/api.py index bce26b19b0b8..bb46959337c0 100644 --- a/openedx/features/survey_report/api.py +++ b/openedx/features/survey_report/api.py @@ -53,6 +53,7 @@ def generate_report() -> None: data = get_report_data() data["state"] = SURVEY_REPORT_GENERATED update_report(survey_report.id, data) + send_report_to_external_api(survey_report.id) except (Exception, ) as update_report_error: update_report(survey_report.id, {"state": SURVEY_REPORT_ERROR}) raise Exception(update_report_error) from update_report_error diff --git a/openedx/features/survey_report/context_processors.py b/openedx/features/survey_report/context_processors.py new file mode 100644 index 000000000000..967291d969a8 --- /dev/null +++ b/openedx/features/survey_report/context_processors.py @@ -0,0 +1,34 @@ +""" +This is the survey report contex_processor modules + +This is meant to determine the visibility of the survey report banner +across all admin pages in case a survey report has not been generated + +""" + +from datetime import datetime +from dateutil.relativedelta import relativedelta # for months test +from .models import SurveyReport +from django.urls import reverse +from django.conf import settings + + +def admin_extra_context(request): + """ + This function sends extra context to every admin site + + The current treshhold to show the banner is one month but this can be redefined in the future + + """ + months = settings.SURVEY_REPORT_CHECK_THRESHOLD + if not request.path.startswith(reverse('admin:index')): + return {'show_survey_report_banner': False, } + + try: + latest_report = SurveyReport.objects.latest('created_at') + months_treshhold = datetime.today().date() - relativedelta(months=months) # Calculate date one month ago + show_survey_report_banner = latest_report.created_at.date() <= months_treshhold + except SurveyReport.DoesNotExist: + show_survey_report_banner = True + + return {'show_survey_report_banner': show_survey_report_banner, } diff --git a/openedx/features/survey_report/management/commands/tests/test_generate_report.py b/openedx/features/survey_report/management/commands/tests/test_generate_report.py index 74204981d520..a1afddabe3f3 100644 --- a/openedx/features/survey_report/management/commands/tests/test_generate_report.py +++ b/openedx/features/survey_report/management/commands/tests/test_generate_report.py @@ -16,8 +16,9 @@ class GenerateReportTest(TestCase): Test for generate_report command. """ + @mock.patch('openedx.features.survey_report.api.send_report_to_external_api') @mock.patch('openedx.features.survey_report.api.get_report_data') - def test_generate_report(self, mock_get_report_data): + def test_generate_report(self, mock_get_report_data, mock_send_report): """ Test that generate_report command creates a survey report. """ @@ -30,6 +31,7 @@ def test_generate_report(self, mock_get_report_data): 'extra_data': {'extra': 'data'}, } mock_get_report_data.return_value = report_test_data + mock_send_report.return_value = None out = StringIO() call_command('generate_report', no_send=True, stdout=out) diff --git a/openedx/features/survey_report/templates/survey_report/admin_banner.html b/openedx/features/survey_report/templates/survey_report/admin_banner.html new file mode 100644 index 000000000000..6a8e2ea92e8c --- /dev/null +++ b/openedx/features/survey_report/templates/survey_report/admin_banner.html @@ -0,0 +1,74 @@ +{% block survey_report_banner %} +{% if show_survey_report_banner %} +
+
+

Join the Open edX Data Sharing Initiative and shape the future of learning

+
+
+

The Open edX Project relies on the collective strength of its community to be a thriving platform for online education.

+

Open edX is a dynamic ecosystem and it is used in diverse learning environments. By sharing anonymized reports of aggregated data, you can contribute to the collective knowledge of the community. This data can help us all understand the reach of our project, make better decisions and ultimately support innovation in lifelong learning and advance next generation learning experience platforms.

+

We invite you to join the Open edX Data Sharing Initiative by sharing an anonymized reports of aggregated data from your institution's usage of the platform. The report data will be sent to Axim Collaborative, the non-profit behind the Open edX project.

+

If you agree and want to send a report you can click the button below. You can always send reports and see the status of reports you have sent in the past at admin/survey_report/surveyreport/ .

+
+
+ +
+ {% csrf_token %} + +
+
+
+ +{% endif %} + + + + +{% endblock %}