learning-credentials 0.4.0rc2__py3-none-any.whl → 0.4.0rc3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- learning_credentials/generators.py +34 -10
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/METADATA +1 -1
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/RECORD +7 -7
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/WHEEL +0 -0
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/entry_points.txt +0 -0
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/licenses/LICENSE.txt +0 -0
- {learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/top_level.txt +0 -0
|
@@ -95,6 +95,9 @@ def _write_text_on_template(template: PageObject, username: str, context_name: s
|
|
|
95
95
|
font = _register_font(options.get('font')) or 'Helvetica'
|
|
96
96
|
|
|
97
97
|
# Write the learner name.
|
|
98
|
+
if options.get('name_uppercase', getattr(settings, 'LEARNING_CREDENTIALS_NAME_UPPERCASE', False)):
|
|
99
|
+
username = username.upper()
|
|
100
|
+
|
|
98
101
|
name_font = _register_font(options.get('name_font')) or font
|
|
99
102
|
pdf_canvas.setFont(name_font, options.get('name_size', 32))
|
|
100
103
|
name_color = options.get('name_color', '#000')
|
|
@@ -102,6 +105,7 @@ def _write_text_on_template(template: PageObject, username: str, context_name: s
|
|
|
102
105
|
|
|
103
106
|
name_x = (template_width - pdf_canvas.stringWidth(username)) / 2
|
|
104
107
|
name_y = options.get('name_y', 290)
|
|
108
|
+
|
|
105
109
|
pdf_canvas.drawString(name_x, name_y, username)
|
|
106
110
|
|
|
107
111
|
# Write the learning context name.
|
|
@@ -121,6 +125,9 @@ def _write_text_on_template(template: PageObject, username: str, context_name: s
|
|
|
121
125
|
|
|
122
126
|
# Write the issue date.
|
|
123
127
|
issue_date = get_localized_credential_date()
|
|
128
|
+
if options.get('issue_date_uppercase', getattr(settings, 'LEARNING_CREDENTIALS_ISSUE_DATE_UPPERCASE', False)):
|
|
129
|
+
issue_date = issue_date.upper()
|
|
130
|
+
|
|
124
131
|
issue_date_font = _register_font(options.get('issue_date_font')) or font
|
|
125
132
|
pdf_canvas.setFont(issue_date_font, options.get('issue_date_size', 12))
|
|
126
133
|
issue_date_color = options.get('issue_date_color', '#000')
|
|
@@ -128,7 +135,12 @@ def _write_text_on_template(template: PageObject, username: str, context_name: s
|
|
|
128
135
|
|
|
129
136
|
issue_date_x = (template_width - pdf_canvas.stringWidth(issue_date)) / 2
|
|
130
137
|
issue_date_y = options.get('issue_date_y', 120)
|
|
131
|
-
|
|
138
|
+
|
|
139
|
+
issue_date_char_space = options.get(
|
|
140
|
+
'issue_date_char_space', getattr(settings, 'LEARNING_CREDENTIALS_ISSUE_DATE_CHAR_SPACE', 0)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
pdf_canvas.drawString(issue_date_x, issue_date_y, issue_date, charSpace=issue_date_char_space)
|
|
132
144
|
|
|
133
145
|
return pdf_canvas
|
|
134
146
|
|
|
@@ -177,7 +189,7 @@ def generate_pdf_credential(
|
|
|
177
189
|
credential_uuid: UUID,
|
|
178
190
|
options: dict[str, Any],
|
|
179
191
|
) -> str:
|
|
180
|
-
"""
|
|
192
|
+
r"""
|
|
181
193
|
Generate a PDF credential.
|
|
182
194
|
|
|
183
195
|
:param learning_context_key: The ID of the course or learning path the credential is for.
|
|
@@ -188,13 +200,15 @@ def generate_pdf_credential(
|
|
|
188
200
|
|
|
189
201
|
Options:
|
|
190
202
|
- template: The path to the PDF template file.
|
|
191
|
-
-
|
|
192
|
-
A
|
|
203
|
+
- template_multiline: The path to the PDF template file for multiline context names.
|
|
204
|
+
A multiline context name is specified by using '\n' or ';' as a separator.
|
|
193
205
|
- font: The name of the font to use. The default font is Helvetica.
|
|
194
206
|
- name_y: The Y coordinate of the name on the credential (vertical position on the template).
|
|
195
207
|
- name_color: The color of the name on the credential (hexadecimal color code).
|
|
196
208
|
- name_size: The font size of the name on the credential. The default value is 32.
|
|
197
209
|
- name_font: The font of the name on the credential. It overrides the `font` option.
|
|
210
|
+
- name_uppercase: If set to true (without quotes), the name will be converted to uppercase.
|
|
211
|
+
The default value is False, unless specified otherwise in the instance settings.
|
|
198
212
|
- context_name: Specify the custom course or Learning Path name. If not provided, it will be retrieved
|
|
199
213
|
automatically from the "cert_name_long" or "display_name" fields for courses, or from the Learning Path model.
|
|
200
214
|
- context_name_y: The Y coordinate of the context name on the credential (vertical position on the template).
|
|
@@ -205,19 +219,29 @@ def generate_pdf_credential(
|
|
|
205
219
|
- issue_date_color: The color of the issue date on the credential (hexadecimal color code).
|
|
206
220
|
- issue_date_size: The font size of the issue date on the credential. The default value is 12.
|
|
207
221
|
- issue_date_font: The font of the issue date on the credential. It overrides the `font` option.
|
|
222
|
+
- issue_date_char_space: The character spacing of the issue date on the credential
|
|
223
|
+
(default is 0.0, unless specified otherwise in the instance settings).
|
|
224
|
+
- issue_date_uppercase: If set to true (without quotes), the issue date will be converted to uppercase.
|
|
225
|
+
The default value is False, unless specified otherwise in the instance settings.
|
|
208
226
|
"""
|
|
209
227
|
log.info("Starting credential generation for user %s", user.id)
|
|
210
228
|
|
|
211
229
|
username = _get_user_name(user)
|
|
212
230
|
context_name = options.get('context_name') or get_learning_context_name(learning_context_key)
|
|
231
|
+
template_path = options.get('template')
|
|
232
|
+
|
|
233
|
+
# Handle multiline context name (we support semicolon as a separator to preserve backward compatibility).
|
|
234
|
+
context_name = context_name.replace(';', '\n').replace(r'\n', '\n')
|
|
235
|
+
if '\n' in context_name:
|
|
236
|
+
# `template_two_lines` is kept for backward compatibility.
|
|
237
|
+
template_path = options.get('template_multiline', options.get('template_two_lines', template_path))
|
|
238
|
+
|
|
239
|
+
if not template_path:
|
|
240
|
+
msg = "Template path must be specified in options."
|
|
241
|
+
raise ValueError(msg)
|
|
213
242
|
|
|
214
243
|
# Get template from the CredentialAsset.
|
|
215
|
-
|
|
216
|
-
if ';' in context_name and (template_path := options.get('template_two_lines')):
|
|
217
|
-
template_file = CredentialAsset.get_asset_by_slug(template_path)
|
|
218
|
-
context_name = context_name.replace(';', '\n')
|
|
219
|
-
else:
|
|
220
|
-
template_file = CredentialAsset.get_asset_by_slug(options['template'])
|
|
244
|
+
template_file = CredentialAsset.get_asset_by_slug(template_path)
|
|
221
245
|
|
|
222
246
|
# Load the PDF template.
|
|
223
247
|
with template_file.open('rb') as template_file:
|
|
@@ -3,7 +3,7 @@ learning_credentials/admin.py,sha256=gLVpCn5oOHLL3u-wnx4R1yJXfar1Z32vk8zcTVjtBFY
|
|
|
3
3
|
learning_credentials/apps.py,sha256=trdQxe-JRhUdUaOQoQWiGL1sn6I1sfDiTvdCwy8yGuw,1037
|
|
4
4
|
learning_credentials/compat.py,sha256=bTAB6bTh99ZyhUqOsDtM_BuIPzFxCjySFtfvc-_fCd4,4731
|
|
5
5
|
learning_credentials/exceptions.py,sha256=UaqBVXFMWR2Iob7_LMb3j4NNVmWQFAgLi_MNMRUvGsI,290
|
|
6
|
-
learning_credentials/generators.py,sha256=
|
|
6
|
+
learning_credentials/generators.py,sha256=GhKrBuPSXOkw4k1ejPTYZBJm78m-sou6ffpUNCGLm28,11492
|
|
7
7
|
learning_credentials/models.py,sha256=DncnadwVrmVcbrka9LBmKvTMqLq8os_wHXmWc3Zet6s,17949
|
|
8
8
|
learning_credentials/processors.py,sha256=LkdjmkLBnXc9qeMcksB1T8AQ5ZhYaECyQO__KfHB_aU,15212
|
|
9
9
|
learning_credentials/tasks.py,sha256=byoFEUvN_ayVaU5K5SlEiA7vu9BRPaSSmKnB9g5toec,1927
|
|
@@ -34,9 +34,9 @@ learning_credentials/templates/learning_credentials/edx_ace/certificate_generate
|
|
|
34
34
|
learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/from_name.txt,sha256=-n8tjPSwfwAfeOSZ1WhcCTrpOah4VswzMZ5mh63Pxow,20
|
|
35
35
|
learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/head.html,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/subject.txt,sha256=S7Hc5T_sZSsSBXm5_H5HBNNv16Ohl0oZn0nVqqeWL0g,132
|
|
37
|
-
learning_credentials-0.4.
|
|
38
|
-
learning_credentials-0.4.
|
|
39
|
-
learning_credentials-0.4.
|
|
40
|
-
learning_credentials-0.4.
|
|
41
|
-
learning_credentials-0.4.
|
|
42
|
-
learning_credentials-0.4.
|
|
37
|
+
learning_credentials-0.4.0rc3.dist-info/licenses/LICENSE.txt,sha256=GDpsPnW_1NKhPvZpZL9imz25P2nIpbwJPEhrlq4vPAU,34523
|
|
38
|
+
learning_credentials-0.4.0rc3.dist-info/METADATA,sha256=nD_YCmP9I0V83xVmX6aBzTSXu_kpYth4kmX1KNjrUVo,7468
|
|
39
|
+
learning_credentials-0.4.0rc3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
40
|
+
learning_credentials-0.4.0rc3.dist-info/entry_points.txt,sha256=hHqqLUEdzAN24v5OGBX9Fr-wh3ATDPjQjByKz03eC2Y,91
|
|
41
|
+
learning_credentials-0.4.0rc3.dist-info/top_level.txt,sha256=Ce-4_leZe_nny7CpmkeRiemcDV6jIHpIvLjlcQBuf18,21
|
|
42
|
+
learning_credentials-0.4.0rc3.dist-info/RECORD,,
|
|
File without changes
|
{learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{learning_credentials-0.4.0rc2.dist-info → learning_credentials-0.4.0rc3.dist-info}/top_level.txt
RENAMED
|
File without changes
|