Skip to content

Commit 503dc73

Browse files
annagavpre-commit-ci[bot]cp-at-mit
authored
Adding issue date to CertificateBase (#3025)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: CP <[email protected]>
1 parent 7e66a08 commit 503dc73

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

cms/models.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import re
66
import uuid
7-
from datetime import datetime, timedelta
7+
from datetime import datetime
88
from json import dumps
99
from urllib.parse import quote_plus
1010

@@ -459,16 +459,7 @@ def get_context(self, request, *args, **kwargs):
459459
"uuid": "fake-uuid",
460460
"learner_name": "Anthony M. Stark",
461461
"product_name": product_name,
462-
"start_date": (
463-
self.parent.product.first_unexpired_run.start_date
464-
if self.parent.product.first_unexpired_run
465-
else datetime.now() # noqa: DTZ005
466-
),
467-
"end_date": (
468-
self.parent.product.first_unexpired_run.end_date
469-
if self.parent.product.first_unexpired_run
470-
else datetime.now() + timedelta(days=45) # noqa: DTZ005
471-
),
462+
"issue_date": self.issue_date,
472463
"CEUs": self.CEUs,
473464
"is_program_certificate": is_program_certificate,
474465
}

cms/templates/certificate_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h2>Congratulations, {{ learner_name }}!</h2>
7373
{% endif %}
7474
<span class="award-text">
7575
{% if page.CEUs %} Awarded {{ CEUs }} Continuing Education Units (CEUs) <br> {% endif %}
76-
{{ start_date|date }} - {{ end_date|date }}
76+
Issued: {{ end_date|date }}
7777
</span>
7878
<div class="row justify-content-center certify-by-row">
7979
{% for signatory in page.signatory_pages %}

courses/migrations/0020_courseruncertificate_certificate_page_revision.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ def set_current_certificate_revision(apps, schema_editor):
88
"""
99
Fetch all CourseRunCertificates and update certificate_page_revision to latest revision
1010
"""
11-
from cms.models import CertificatePage
12-
from courses.models import CourseRunCertificate
13-
14-
course_run_certificates = CourseRunCertificate.objects.all()
11+
CourseRunCertificate = apps.get_model("courses", "CourseRunCertificate")
12+
CertificatePage = apps.get_model("cms", "CertificatePage")
13+
course_run_certificates = CourseRunCertificate.objects.only(
14+
"id", "course_run", "certificate_page_revision"
15+
).all()
1516
for cert in course_run_certificates:
1617
certificate_page = (
1718
cert.course_run.course.page.get_children()
@@ -34,6 +35,10 @@ class Migration(migrations.Migration):
3435
dependencies = [
3536
("wagtailcore", "0070_rename_pagerevision_revision"),
3637
("courses", "0019_add_is_self_paced_course_run"),
38+
(
39+
"cms",
40+
"0023_certificateindexpage_certificatepage_signatoryindexpage_signatorypage",
41+
),
3742
]
3843

3944
operations = [
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.25 on 2025-10-21 14:55
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("courses", "0072_alter_programcollectionitem_sort_order"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="courseruncertificate",
14+
name="issue_date",
15+
field=models.DateTimeField(blank=True, db_index=True, null=True),
16+
),
17+
migrations.AddField(
18+
model_name="programcertificate",
19+
name="issue_date",
20+
field=models.DateTimeField(blank=True, db_index=True, null=True),
21+
),
22+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 4.2.25 on 2025-10-21 14:59
2+
3+
from django.db import migrations
4+
5+
6+
def populate_issue_date(apps, schema):
7+
CourseRunCertificate = apps.get_model("courses", "CourseRunCertificate")
8+
for certificate in CourseRunCertificate.objects.all():
9+
if certificate.issue_date is None:
10+
certificate.issue_date = certificate.created_on
11+
certificate.save(update_fields=["issue_date"])
12+
13+
ProgramCertificate = apps.get_model("courses", "ProgramCertificate")
14+
for certificate in ProgramCertificate.objects.all():
15+
if certificate.issue_date is None:
16+
certificate.issue_date = certificate.created_on
17+
certificate.save(update_fields=["issue_date"])
18+
19+
20+
class Migration(migrations.Migration):
21+
dependencies = [
22+
("courses", "0073_courseruncertificate_issue_date_and_more"),
23+
]
24+
25+
operations = [
26+
migrations.RunPython(
27+
populate_issue_date, reverse_code=migrations.RunPython.noop
28+
),
29+
]

courses/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ class BaseCertificate(models.Model):
12861286
help_text="Indicates whether or not the certificate is revoked",
12871287
verbose_name="revoked",
12881288
)
1289+
issue_date = models.DateTimeField(null=True, blank=True, db_index=True)
12891290

12901291
class Meta:
12911292
abstract = True

0 commit comments

Comments
 (0)