Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: update static certificate with dynamic data #439

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions common/djangoapps/util/date_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,70 @@ def from_timestamp(timestamp):
DEFAULT_TIME_FORMAT = "%I:%M:%S %p"
DEFAULT_DATE_TIME_FORMAT = "%b %d, %Y at %H:%M"
DEFAULT_DAY_AND_TIME_FORMAT = "%A at %-I%P"
arabic_numbers = {
"0": "٠",
"1": "١",
"2": "٢",
"3": "٣",
"4": "٤",
"5": "٥",
"6": "٦",
"7": "٧",
"8": "٨",
"9": "٩",
}
comma_sign_arabic = "،"
english_months_list = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
]
urdu_months_list = [
"جنوری",
"فروری",
"مارچ",
"اپریل",
"مئی",
"جون",
"جولائی",
"اگست",
"ستمبر",
"اکتوبر",
"نومبر",
"دسمبر",
]


def convert_number_to_arabic(number):
if number.isnumeric():
for digit in number:
if digit.isnumeric():
number = number.replace(digit, arabic_numbers[digit])
return number


def convert_date_to_arabic(date):
for char in date:
if char.isnumeric():
date = date.replace(char, arabic_numbers[char])
elif char == ",":
date = date.replace(char, comma_sign_arabic)

for idx, month in enumerate(english_months_list):
if month in date:
date = date.replace(month, urdu_months_list[idx])
break

return date


def strftime_localized(dtime, format): # pylint: disable=redefined-builtin
Expand Down
11 changes: 7 additions & 4 deletions lms/djangoapps/certificates/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from common.djangoapps.edxmako.shortcuts import render_to_response
from common.djangoapps.edxmako.template import Template
from common.djangoapps.student.models import LinkedInAddToProfileConfiguration
from common.djangoapps.util.date_utils import strftime_localized
from common.djangoapps.util.date_utils import strftime_localized, convert_date_to_arabic, convert_number_to_arabic
from common.djangoapps.util.views import handle_500
from lms.djangoapps.badges.events.course_complete import get_completion_badge
from lms.djangoapps.badges.utils import badges_enabled
Expand Down Expand Up @@ -124,7 +124,8 @@ def _update_certificate_context(context, course, course_overview, user_certifica
else:
date = display_date_for_certificate(course, user_certificate)
# Translators: The format of the date includes the full name of the month
context['certificate_date_issued'] = strftime_localized(date, settings.CERTIFICATE_DATE_FORMAT)
date = strftime_localized(date, "%B %-d, %Y")
context['certificate_date_issued'] = convert_date_to_arabic(date)

# Translators: This text represents the verification of the certificate
context['document_meta_description'] = _('This is a valid {platform_name} certificate for {user_name}, '
Expand Down Expand Up @@ -243,10 +244,12 @@ def _update_context_with_basic_info(context, course_id, platform_name, configura
)


def _update_course_context(request, context, course, platform_name):
def _update_course_context(request, context, course, platform_name, course_overview):
"""
Updates context dictionary with course info.
"""
effort = course_overview and course_overview.effort or '8'
context['course_duration'] = convert_number_to_arabic(effort)
context['full_course_image_url'] = request.build_absolute_uri(course_image_url(course))
course_title_from_cert = context['certificate_data'].get('course_title', '')
accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name
Expand Down Expand Up @@ -616,7 +619,7 @@ def render_html_view(request, course_id, certificate=None): # pylint: disable=t
_update_organization_context(context, course)

# Append course info
_update_course_context(request, context, course, platform_name)
_update_course_context(request, context, course, platform_name, course_overview)

# Append course run info from discovery
context.update(catalog_data)
Expand Down
Binary file not shown.
2,693 changes: 2,693 additions & 0 deletions lms/static/sdaia_css/fonts/DIN-Next-LT-Arabic-Bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2,620 changes: 2,620 additions & 0 deletions lms/static/sdaia_css/fonts/DIN-Next-LT-Arabic-Medium.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 11 additions & 11 deletions lms/static/sdaia_css/styles.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
@font-face {
font-family: 'DIN Next LT Arabic';
src: url('../fonts/DIN-Next-LT-Arabic-Medium.woff2') format('woff2'),
url('../fonts/DIN-Next-LT-Arabic-Medium.woff') format('woff'),
url('../fonts/DIN-Next-LT-Arabic-Medium.ttf') format('truetype'),
url('../fonts/DIN-Next-LT-Arabic-Medium.eot') format('truetype'),
url('../fonts/DIN-Next-LT-Arabic-Medium.svg#din-next-lt-arabic-medium') format('svg');
src: url('./fonts/DIN-Next-LT-Arabic-Medium.woff2') format('woff2'),
url('./fonts/DIN-Next-LT-Arabic-Medium.woff') format('woff'),
url('./fonts/DIN-Next-LT-Arabic-Medium.ttf') format('truetype'),
url('./fonts/DIN-Next-LT-Arabic-Medium.eot') format('truetype'),
url('./fonts/DIN-Next-LT-Arabic-Medium.svg#din-next-lt-arabic-medium') format('svg');
font-weight: 500;
font-style: normal;
}

@font-face {
font-family: 'DIN Next LT Arabic';
src: url('../fonts/DIN-Next-LT-Arabic-Bold.woff2') format('woff2'),
url('../fonts/DIN-Next-LT-Arabic-Bold.woff') format('woff'),
url('../fonts/DIN-Next-LT-Arabic-Bold.ttf') format('truetype'),
url('../fonts/DIN-Next-LT-Arabic-Bold.eot') format('truetype'),
url('../fonts/DIN-Next-LT-Arabic-Bold.svg#din-next-lt-arabic-bold') format('svg');
src: url('./fonts/DIN-Next-LT-Arabic-Bold.woff2') format('woff2'),
url('./fonts/DIN-Next-LT-Arabic-Bold.woff') format('woff'),
url('./fonts/DIN-Next-LT-Arabic-Bold.ttf') format('truetype'),
url('./fonts/DIN-Next-LT-Arabic-Bold.eot') format('truetype'),
url('./fonts/DIN-Next-LT-Arabic-Bold.svg#din-next-lt-arabic-bold') format('svg');
font-weight: 700;
font-style: normal;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ body {
}

.certificate-main .main-title {
margin: 0 0 93px;
margin: 0 0 34px;
}

.certificate-main .sub-title {
Expand Down
5 changes: 3 additions & 2 deletions lms/templates/certificates/_accomplishment-rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ <h1>شهادة إتمام</h1>
</div>
<div class="certificate-main">
<h2 class="main-title">: الهيئة السعودية للبيانات والذكاء الاصطناعي ( سدايا ) تمنح</h2>
<p class="text-secondary">${accomplishment_copy_name}</p>
<h2 class="sub-title">هذه الشهادة وذلك لإتمام البرنامج التدريبي </h2>
<p class="text-secondary">سياسة حوكمة البيانات الوطنية </p>
<p class="limited-text"> ومدته<span class="text-secondary">8 ساعات تدريبية </span> بتاريخ</p>
<p class="text-secondary">${accomplishment_copy_course_name}</p>
<p class="limited-text"> ومدته<span class="text-secondary">${course_duration} ساعات تدريبية </span> بتاريخ <span class="text-secondary">${certificate_date_issued}</span></p>
<p>مع تمنياتنا بدوام التوفيق والنجاح</p>
<p>أكاديمية سدايا</p>
</div>
Expand Down
Loading