learning-credentials 0.5.1rc5__tar.gz → 0.5.3__tar.gz

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.
Files changed (58) hide show
  1. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/CHANGELOG.rst +23 -0
  2. {learning_credentials-0.5.1rc5/learning_credentials.egg-info → learning_credentials-0.5.3}/PKG-INFO +24 -1
  3. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/admin.py +3 -2
  4. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/v1/views.py +9 -2
  5. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/generators.py +1 -1
  6. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/models.py +16 -0
  7. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/processors.py +5 -5
  8. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3/learning_credentials.egg-info}/PKG-INFO +24 -1
  9. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/pyproject.toml +1 -1
  10. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_generators.py +1 -1
  11. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_models.py +30 -0
  12. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_views.py +35 -0
  13. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/LICENSE.txt +0 -0
  14. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/MANIFEST.in +0 -0
  15. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/README.rst +0 -0
  16. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/__init__.py +0 -0
  17. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/__init__.py +0 -0
  18. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/urls.py +0 -0
  19. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/v1/__init__.py +0 -0
  20. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/v1/permissions.py +0 -0
  21. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/v1/serializers.py +0 -0
  22. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/api/v1/urls.py +0 -0
  23. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/apps.py +0 -0
  24. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/compat.py +0 -0
  25. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/conf/locale/config.yaml +0 -0
  26. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/exceptions.py +0 -0
  27. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0001_initial.py +0 -0
  28. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0002_migrate_to_learning_credentials.py +0 -0
  29. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0003_rename_certificates_to_credentials.py +0 -0
  30. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0004_replace_course_keys_with_learning_context_keys.py +0 -0
  31. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0005_rename_processors_and_generators.py +0 -0
  32. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0006_cleanup_openedx_certificates_tables.py +0 -0
  33. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0007_migrate_to_text_elements_format.py +0 -0
  34. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0008_validation.py +0 -0
  35. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0009_credential_user_fk.py +0 -0
  36. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/0010_credential_configuration_fk.py +0 -0
  37. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/migrations/__init__.py +0 -0
  38. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/settings/__init__.py +0 -0
  39. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/settings/common.py +0 -0
  40. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/settings/production.py +0 -0
  41. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/tasks.py +0 -0
  42. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/base.html +0 -0
  43. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/body.html +0 -0
  44. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/body.txt +0 -0
  45. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/from_name.txt +0 -0
  46. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/head.html +0 -0
  47. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/templates/learning_credentials/edx_ace/certificate_generated/email/subject.txt +0 -0
  48. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials/urls.py +0 -0
  49. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials.egg-info/SOURCES.txt +0 -0
  50. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials.egg-info/dependency_links.txt +0 -0
  51. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials.egg-info/entry_points.txt +0 -0
  52. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials.egg-info/requires.txt +0 -0
  53. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/learning_credentials.egg-info/top_level.txt +0 -0
  54. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/setup.cfg +0 -0
  55. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_admin.py +0 -0
  56. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_migrations.py +0 -0
  57. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_processors.py +0 -0
  58. {learning_credentials-0.5.1rc5 → learning_credentials-0.5.3}/tests/test_tasks.py +0 -0
@@ -16,6 +16,29 @@ Unreleased
16
16
 
17
17
  *
18
18
 
19
+ 0.5.3 - 2026-08-11
20
+ ******************
21
+
22
+ Fixed
23
+ =====
24
+
25
+ * The ``is_generation_enabled`` field of the credential eligibility endpoint is now based on the ``expires`` field of
26
+ the periodic task, when it is set. The ``enabled`` flag is updated by Celery Beat (e.g., it disables expired and
27
+ already executed one-off tasks), so it does not reliably reflect the intended configuration.
28
+
29
+ 0.5.2 - 2026-08-11
30
+ ******************
31
+
32
+ Changed
33
+ =======
34
+
35
+ * The ``CredentialAdmin`` list view is now ordered by the ``created`` timestamp in descending order (most recent first).
36
+
37
+ Removed
38
+ =======
39
+
40
+ * ``CredentialAdmin`` and ``CredentialConfigurationAdmin`` list views no longer allow filtering by the ``learning_context_key``.
41
+
19
42
  0.5.1 - 2026-03-17
20
43
  ******************
21
44
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: learning-credentials
3
- Version: 0.5.1rc5
3
+ Version: 0.5.3
4
4
  Summary: A pluggable service for preparing Open edX credentials.
5
5
  Author-email: OpenCraft <help@opencraft.com>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -177,6 +177,29 @@ Unreleased
177
177
 
178
178
  *
179
179
 
180
+ 0.5.3 - 2026-08-11
181
+ ******************
182
+
183
+ Fixed
184
+ =====
185
+
186
+ * The ``is_generation_enabled`` field of the credential eligibility endpoint is now based on the ``expires`` field of
187
+ the periodic task, when it is set. The ``enabled`` flag is updated by Celery Beat (e.g., it disables expired and
188
+ already executed one-off tasks), so it does not reliably reflect the intended configuration.
189
+
190
+ 0.5.2 - 2026-08-11
191
+ ******************
192
+
193
+ Changed
194
+ =======
195
+
196
+ * The ``CredentialAdmin`` list view is now ordered by the ``created`` timestamp in descending order (most recent first).
197
+
198
+ Removed
199
+ =======
200
+
201
+ * ``CredentialAdmin`` and ``CredentialConfigurationAdmin`` list views no longer allow filtering by the ``learning_context_key``.
202
+
180
203
  0.5.1 - 2026-03-17
181
204
  ******************
182
205
 
@@ -177,7 +177,7 @@ class CredentialConfigurationAdmin(DjangoObjectActions, ReverseModelAdmin):
177
177
  ]
178
178
  list_display = ('learning_context_key', 'credential_type', 'enabled', 'interval')
179
179
  search_fields = ('learning_context_key', 'credential_type__name')
180
- list_filter = ('learning_context_key', 'credential_type', 'periodic_task__enabled')
180
+ list_filter = ('credential_type', 'periodic_task__enabled')
181
181
 
182
182
  def get_inline_instances(
183
183
  self,
@@ -260,7 +260,8 @@ class CredentialAdmin(DjangoObjectActions, admin.ModelAdmin): # noqa: D101
260
260
  "uuid",
261
261
  "verify_uuid",
262
262
  )
263
- list_filter = ("configuration__learning_context_key", "configuration__credential_type", "status")
263
+ list_filter = ("configuration__credential_type", "status")
264
+ ordering = ('-created',)
264
265
  change_actions = ('reissue_credential',)
265
266
 
266
267
  def get_change_actions(self, request: HttpRequest, object_id: str, form_url: str) -> list[str]:
@@ -151,7 +151,6 @@ class CredentialEligibilityView(APIView):
151
151
  API view for credential eligibility checking and generation.
152
152
 
153
153
  **GET**: Returns detailed eligibility info for all configured credentials in a learning context.
154
- **POST**: Triggers credential generation for an eligible user.
155
154
 
156
155
  Staff users can operate on behalf of other users via the ``username`` parameter.
157
156
  """
@@ -168,7 +167,7 @@ class CredentialEligibilityView(APIView):
168
167
  return {
169
168
  'credential_type_id': config.credential_type.pk,
170
169
  'name': config.credential_type.name,
171
- 'is_generation_enabled': config.periodic_task.enabled,
170
+ 'is_generation_enabled': config.is_generation_enabled,
172
171
  **progress_data,
173
172
  'existing_credential': existing_credential.uuid if existing_credential else None,
174
173
  'existing_credential_url': existing_credential.download_url if existing_credential else None,
@@ -192,6 +191,14 @@ class CredentialEligibilityView(APIView):
192
191
  "(e.g. learning_credentials.processors.retrieve_subsection_grades)."
193
192
  ),
194
193
  ),
194
+ apidocs.string_parameter(
195
+ "username",
196
+ ParameterLocation.QUERY,
197
+ description=(
198
+ "Operate on behalf of the specified user. "
199
+ "Staff users may specify any username; non-staff users are limited to their own."
200
+ ),
201
+ ),
195
202
  ],
196
203
  responses={
197
204
  200: CredentialEligibilityResponseSerializer,
@@ -236,7 +236,7 @@ def _render_text_element(
236
236
  pdf_canvas.drawString(line_x, line_y, line, charSpace=char_space)
237
237
 
238
238
 
239
- def _write_text_on_template( # noqa: PLR0913
239
+ def _write_text_on_template( # noqa: PLR0913,PLR0917
240
240
  template: PageObject,
241
241
  username: str,
242
242
  context_name: str,
@@ -148,6 +148,22 @@ class CredentialConfiguration(TimeStampedModel):
148
148
  self.periodic_task.args = json.dumps([self.id])
149
149
  self.periodic_task.save()
150
150
 
151
+ @property
152
+ def is_generation_enabled(self) -> bool:
153
+ """
154
+ Check whether credential generation is currently enabled for this configuration.
155
+
156
+ Celery Beat updates the `enabled` flag of the periodic task on its own (e.g., it disables one-off tasks once
157
+ they have run, and expired tasks), so it does not reliably reflect the intended configuration. When `expires`
158
+ is set, it defines the end of the generation window, so it takes precedence.
159
+
160
+ :return: True if credential generation is enabled, False otherwise.
161
+ """
162
+ if self.periodic_task.expires:
163
+ return self.periodic_task.expires > timezone.now()
164
+
165
+ return self.periodic_task.enabled
166
+
151
167
  @classmethod
152
168
  def get_enabled_configurations(cls) -> QuerySet[Self]:
153
169
  """
@@ -1,11 +1,11 @@
1
1
  """
2
2
  This module contains processors for credential criteria.
3
3
 
4
- The functions prefixed with `retrieve_` are automatically detected by the admin page and are used to retrieve the
5
- IDs of the users that meet the criteria for the credential type.
4
+ The functions prefixed with `retrieve_` are automatically detected by the admin page and are used to compute
5
+ per-user progress for the credential type, following the contract described below.
6
6
 
7
- All processors return ``dict[int, dict[str, Any]]`` — a mapping from user ID to detailed progress info.
8
- Each user's dict always includes an ``is_eligible`` boolean.
7
+ All processors return ``dict[int, dict[str, Any]]`` — a mapping from user ID to detailed progress info for all
8
+ relevant users, including those who are not eligible. Each user's dict always includes an ``is_eligible`` boolean.
9
9
 
10
10
  We will move this module to an external repository (a plugin).
11
11
  """
@@ -214,7 +214,7 @@ def _retrieve_course_subsection_grades(
214
214
  course_id: CourseKey, options: dict[str, Any], user_id: int | None = None
215
215
  ) -> dict[int, dict[str, Any]]:
216
216
  """Retrieve detailed grade progress for enrolled users in a course."""
217
- required_grades: dict[str, int] = options['required_grades']
217
+ required_grades: dict[str, float] = options['required_grades']
218
218
  required_grades = {key.lower(): value * 100 for key, value in required_grades.items()}
219
219
 
220
220
  users = get_course_enrollments(course_id, user_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: learning-credentials
3
- Version: 0.5.1rc5
3
+ Version: 0.5.3
4
4
  Summary: A pluggable service for preparing Open edX credentials.
5
5
  Author-email: OpenCraft <help@opencraft.com>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -177,6 +177,29 @@ Unreleased
177
177
 
178
178
  *
179
179
 
180
+ 0.5.3 - 2026-08-11
181
+ ******************
182
+
183
+ Fixed
184
+ =====
185
+
186
+ * The ``is_generation_enabled`` field of the credential eligibility endpoint is now based on the ``expires`` field of
187
+ the periodic task, when it is set. The ``enabled`` flag is updated by Celery Beat (e.g., it disables expired and
188
+ already executed one-off tasks), so it does not reliably reflect the intended configuration.
189
+
190
+ 0.5.2 - 2026-08-11
191
+ ******************
192
+
193
+ Changed
194
+ =======
195
+
196
+ * The ``CredentialAdmin`` list view is now ordered by the ``created`` timestamp in descending order (most recent first).
197
+
198
+ Removed
199
+ =======
200
+
201
+ * ``CredentialAdmin`` and ``CredentialConfigurationAdmin`` list views no longer allow filtering by the ``learning_context_key``.
202
+
180
203
  0.5.1 - 2026-03-17
181
204
  ******************
182
205
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "learning-credentials"
3
- version = "0.5.1rc5"
3
+ version = "0.5.3"
4
4
  description = "A pluggable service for preparing Open edX credentials."
5
5
  dynamic = ["readme"]
6
6
  requires-python = ">=3.11"
@@ -504,7 +504,7 @@ def test_save_credential(mock_contentfile: Mock, mock_token_hex: Mock, storage:
504
504
  return_value=Mock(getpdfdata=Mock(return_value=b'pdf_data')),
505
505
  )
506
506
  @patch('learning_credentials.generators._save_credential', return_value='credential_url')
507
- def test_generate_pdf_credential(
507
+ def test_generate_pdf_credential( # noqa: PLR0917
508
508
  mock_save_credential: Mock,
509
509
  mock_write_text_on_template: Mock,
510
510
  mock_pdf_writer: Mock,
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from datetime import timedelta
5
6
  from pathlib import Path
6
7
  from typing import TYPE_CHECKING
7
8
  from unittest.mock import Mock, patch
@@ -10,6 +11,7 @@ from uuid import uuid4
10
11
  import pytest
11
12
  from django.core.exceptions import ValidationError
12
13
  from django.core.files.base import ContentFile
14
+ from django.utils import timezone
13
15
  from django_celery_beat.models import PeriodicTask
14
16
 
15
17
  from learning_credentials.exceptions import AssetNotFoundError, CredentialGenerationError
@@ -371,6 +373,34 @@ class TestCredentialConfiguration:
371
373
  assert enabled_configs.count() == 1
372
374
  assert enabled_configs.first() == mock_credential_config
373
375
 
376
+ @pytest.mark.django_db
377
+ @pytest.mark.parametrize(
378
+ ('enabled', 'expires_offset', 'expected'),
379
+ [
380
+ # Without `expires`, the `enabled` flag of the periodic task is used.
381
+ (False, None, False),
382
+ (True, None, True),
383
+ # With `expires` set, it takes precedence over the `enabled` flag.
384
+ (False, timedelta(days=1), True),
385
+ (True, timedelta(days=-1), False),
386
+ (False, timedelta(days=-1), False),
387
+ (True, timedelta(days=1), True),
388
+ ],
389
+ )
390
+ def test_is_generation_enabled(
391
+ self,
392
+ mock_credential_config: CredentialConfiguration,
393
+ enabled: bool,
394
+ expires_offset: timedelta | None,
395
+ expected: bool,
396
+ ):
397
+ """Test that the `expires` field takes precedence over the `enabled` flag, which Celery Beat updates."""
398
+ mock_credential_config.periodic_task.enabled = enabled
399
+ mock_credential_config.periodic_task.expires = timezone.now() + expires_offset if expires_offset else None
400
+ mock_credential_config.periodic_task.save()
401
+
402
+ assert mock_credential_config.is_generation_enabled is expected
403
+
374
404
  @pytest.mark.django_db
375
405
  def test_save_updates_existing_periodic_task(self, mock_credential_config: CredentialConfiguration):
376
406
  """Test that saving an existing CredentialConfiguration updates the periodic task."""
@@ -2,11 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from datetime import timedelta
5
6
  from typing import TYPE_CHECKING
6
7
  from unittest.mock import Mock, patch
7
8
 
8
9
  import pytest
9
10
  from django.urls import reverse
11
+ from django.utils import timezone
10
12
  from learning_paths.models import LearningPathStep
11
13
  from rest_framework import status
12
14
  from rest_framework.test import APIClient
@@ -313,6 +315,39 @@ class TestCredentialEligibilityView:
313
315
  assert 'existing_credential' not in cred
314
316
  assert 'existing_credential_url' not in cred
315
317
 
318
+ @pytest.mark.parametrize(
319
+ ('enabled', 'expires_offset', 'expected'),
320
+ [
321
+ (False, None, False),
322
+ (True, None, True),
323
+ # Celery Beat disables expired tasks, so `expires` takes precedence over the `enabled` flag.
324
+ (False, timedelta(days=1), True),
325
+ (True, timedelta(days=-1), False),
326
+ ],
327
+ )
328
+ @patch('learning_credentials.api.v1.permissions.get_course_enrollments')
329
+ def test_get_is_generation_enabled( # noqa: PLR0917
330
+ self,
331
+ mock_enrollments: Mock,
332
+ user: User,
333
+ course_key: CourseKey,
334
+ mock_credential_config: CredentialConfiguration,
335
+ enabled: bool,
336
+ expires_offset: timedelta | None,
337
+ expected: bool,
338
+ ):
339
+ """Test that the generation status is based on the `expires` field of the periodic task, when it is set."""
340
+ mock_enrollments.return_value = [user]
341
+ mock_credential_config.periodic_task.enabled = enabled
342
+ mock_credential_config.periodic_task.expires = timezone.now() + expires_offset if expires_offset else None
343
+ mock_credential_config.periodic_task.save()
344
+
345
+ with patch.object(CredentialConfiguration, 'get_user_eligibility_details', return_value={'is_eligible': True}):
346
+ response = self._make_get_request(user, course_key)
347
+
348
+ assert response.status_code == status.HTTP_200_OK
349
+ assert response.data['credentials'][0]['is_generation_enabled'] is expected
350
+
316
351
  @patch('learning_credentials.api.v1.permissions.get_course_enrollments')
317
352
  def test_get_filters_by_retrieval_func(
318
353
  self,