Commit 28fd39f7 by sanfordstudent Committed by GitHub

Merge pull request #15975 from edx/sstudent/EDUCATOR-1317

common function for cert display date
parents e6f807b0 4f977fb2
......@@ -39,6 +39,7 @@ from lms.djangoapps.badges.tests.factories import (
CourseCompleteImageConfigurationFactory
)
from lms.djangoapps.grades.tests.utils import mock_passing_grade
from openedx.core.djangoapps.certificates.config import waffle
from openedx.core.lib.tests.assertions.events import assert_event_matches
from student.roles import CourseStaffRole
from student.tests.factories import CourseEnrollmentFactory, UserFactory
......@@ -819,7 +820,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
expected_date = datetime.datetime.today()
else:
expected_date = self.course.certificate_available_date
response = self.client.get(test_url)
with waffle.waffle().override(waffle.SELF_PACED_ONLY, active=True):
with waffle.waffle().override(waffle.INSTRUCTOR_PACED_ONLY, active=True):
response = self.client.get(test_url)
date = '{month} {day}, {year}'.format(
month=strftime_localized(expected_date, "%B"),
day=expected_date.day,
......
......@@ -41,6 +41,7 @@ from edxmako.shortcuts import render_to_response
from edxmako.template import Template
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.courses import course_image_url
from openedx.core.djangoapps.certificates.api import display_date_for_certificate
from student.models import LinkedInAddToProfileConfiguration
from util import organizations_helpers as organization_api
from util.date_utils import strftime_localized
......@@ -100,15 +101,7 @@ def _update_certificate_context(context, user_certificate, platform_name):
# Translators: The format of the date includes the full name of the month
course = get_course_by_id(user_certificate.course_id) if user_certificate.course_id else None
if (
course and
not course.self_paced and
course.certificate_available_date and
course.certificate_available_date < datetime.now(pytz.UTC)
):
date = course.certificate_available_date
else:
date = user_certificate.modified_date
date = display_date_for_certificate(course, user_certificate)
context['certificate_date_issued'] = _('{month} {day}, {year}').format(
month=strftime_localized(date, "%B"),
day=date.day,
......
"""
The public API for certificates.
"""
from datetime import datetime
from pytz import UTC
from openedx.core.djangoapps.certificates.config import waffle
......@@ -37,3 +38,15 @@ def _enabled_and_self_paced(course):
def can_show_certificate_available_date_field(course):
return _enabled_and_self_paced(course)
def display_date_for_certificate(course, certificate):
if (
auto_certificate_generation_enabled_for_course(course) and
not course.self_paced and
course.certificate_available_date and
course.certificate_available_date < datetime.now(UTC)
):
return course.certificate_available_date
return certificate.modified_date
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment