openedx-learning 0.11.2__tar.gz → 0.11.4__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 (123) hide show
  1. {openedx_learning-0.11.2/openedx_learning.egg-info → openedx_learning-0.11.4}/PKG-INFO +6 -6
  2. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/__init__.py +1 -1
  3. openedx_learning-0.11.4/openedx_learning/apps/authoring/collections/api.py +168 -0
  4. openedx_learning-0.11.4/openedx_learning/apps/authoring/collections/migrations/0003_collection_entities.py +38 -0
  5. openedx_learning-0.11.4/openedx_learning/apps/authoring/collections/migrations/0004_collection_key.py +57 -0
  6. openedx_learning-0.11.4/openedx_learning/apps/authoring/collections/models.py +237 -0
  7. {openedx_learning-0.11.2 → openedx_learning-0.11.4/openedx_learning.egg-info}/PKG-INFO +6 -6
  8. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning.egg-info/SOURCES.txt +2 -0
  9. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/setup.py +1 -1
  10. openedx_learning-0.11.2/openedx_learning/apps/authoring/collections/api.py +0 -92
  11. openedx_learning-0.11.2/openedx_learning/apps/authoring/collections/models.py +0 -98
  12. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/CHANGELOG.rst +0 -0
  13. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/LICENSE.txt +0 -0
  14. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/MANIFEST.in +0 -0
  15. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/README.rst +0 -0
  16. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/api/__init__.py +0 -0
  17. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/api/authoring.py +0 -0
  18. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/api/authoring_models.py +0 -0
  19. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/__init__.py +0 -0
  20. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/__init__.py +0 -0
  21. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/collections/__init__.py +0 -0
  22. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/collections/apps.py +0 -0
  23. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/collections/migrations/0001_initial.py +0 -0
  24. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/collections/migrations/0002_remove_collection_name_collection_created_by_and_more.py +0 -0
  25. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/collections/migrations/__init__.py +0 -0
  26. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/__init__.py +0 -0
  27. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/admin.py +0 -0
  28. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/api.py +0 -0
  29. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/apps.py +0 -0
  30. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/migrations/0001_initial.py +0 -0
  31. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/migrations/0002_alter_componentversioncontent_key.py +0 -0
  32. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/migrations/__init__.py +0 -0
  33. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/components/models.py +0 -0
  34. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/__init__.py +0 -0
  35. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/admin.py +0 -0
  36. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/api.py +0 -0
  37. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/apps.py +0 -0
  38. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/migrations/0001_initial.py +0 -0
  39. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/migrations/__init__.py +0 -0
  40. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/contents/models.py +0 -0
  41. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/__init__.py +0 -0
  42. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/admin.py +0 -0
  43. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/api.py +0 -0
  44. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/apps.py +0 -0
  45. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/migrations/0001_initial.py +0 -0
  46. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/migrations/0002_alter_learningpackage_key_and_more.py +0 -0
  47. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/migrations/__init__.py +0 -0
  48. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/model_mixins.py +0 -0
  49. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/apps/authoring/publishing/models.py +0 -0
  50. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/contrib/__init__.py +0 -0
  51. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/contrib/media_server/__init__.py +0 -0
  52. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/contrib/media_server/apps.py +0 -0
  53. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/contrib/media_server/urls.py +0 -0
  54. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/contrib/media_server/views.py +0 -0
  55. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/__init__.py +0 -0
  56. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/admin_utils.py +0 -0
  57. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/cache.py +0 -0
  58. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/collations.py +0 -0
  59. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/fields.py +0 -0
  60. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/managers.py +0 -0
  61. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/test_utils.py +0 -0
  62. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/lib/validators.py +0 -0
  63. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning/py.typed +0 -0
  64. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning.egg-info/dependency_links.txt +0 -0
  65. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning.egg-info/not-zip-safe +0 -0
  66. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning.egg-info/requires.txt +4 -4
  67. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_learning.egg-info/top_level.txt +0 -0
  68. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/__init__.py +0 -0
  69. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/__init__.py +0 -0
  70. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/__init__.py +0 -0
  71. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/admin.py +0 -0
  72. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/api.py +0 -0
  73. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/apps.py +0 -0
  74. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/data.py +0 -0
  75. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/__init__.py +0 -0
  76. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/actions.py +0 -0
  77. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/api.py +0 -0
  78. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/exceptions.py +0 -0
  79. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/import_plan.py +0 -0
  80. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/parsers.py +0 -0
  81. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/tasks.py +0 -0
  82. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/template.csv +0 -0
  83. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/import_export/template.json +0 -0
  84. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0001_initial.py +0 -0
  85. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0001_squashed.py +0 -0
  86. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0002_auto_20230718_2026.py +0 -0
  87. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0003_auto_20230721_1238.py +0 -0
  88. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0004_auto_20230723_2001.py +0 -0
  89. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0005_language_taxonomy.py +0 -0
  90. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0006_alter_objecttag_unique_together.py +0 -0
  91. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0006_auto_20230802_1631.py +0 -0
  92. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0007_tag_import_task_log_null_fix.py +0 -0
  93. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0008_taxonomy_description_not_null.py +0 -0
  94. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0009_alter_objecttag_object_id.py +0 -0
  95. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0010_cleanups.py +0 -0
  96. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0011_remove_required.py +0 -0
  97. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0012_language_taxonomy.py +0 -0
  98. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0013_tag_parent_blank.py +0 -0
  99. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0014_minor_fixes.py +0 -0
  100. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0015_taxonomy_export_id.py +0 -0
  101. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0016_object_tag_export_id.py +0 -0
  102. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/0017_alter_tagimporttask_status.py +0 -0
  103. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/migrations/__init__.py +0 -0
  104. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/models/__init__.py +0 -0
  105. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/models/base.py +0 -0
  106. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/models/import_export.py +0 -0
  107. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/models/system_defined.py +0 -0
  108. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/models/utils.py +0 -0
  109. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/__init__.py +0 -0
  110. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/paginators.py +0 -0
  111. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/urls.py +0 -0
  112. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/utils.py +0 -0
  113. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/__init__.py +0 -0
  114. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/permissions.py +0 -0
  115. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/serializers.py +0 -0
  116. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/urls.py +0 -0
  117. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/views.py +0 -0
  118. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rest_api/v1/views_import.py +0 -0
  119. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/rules.py +0 -0
  120. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/core/tagging/urls.py +0 -0
  121. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/openedx_tagging/py.typed +0 -0
  122. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/requirements/base.in +0 -0
  123. {openedx_learning-0.11.2 → openedx_learning-0.11.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openedx-learning
3
- Version: 0.11.2
3
+ Version: 0.11.4
4
4
  Summary: Open edX Learning Core and Tagging.
5
5
  Home-page: https://github.com/openedx/openedx-learning
6
6
  Author: David Ormsbee
@@ -9,7 +9,7 @@ License: AGPL 3.0
9
9
  Keywords: Python edx
10
10
  Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Framework :: Django
12
- Classifier: Framework :: Django :: 3.2
12
+ Classifier: Framework :: Django :: 4.2
13
13
  Classifier: Intended Audience :: Developers
14
14
  Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
15
15
  Classifier: Natural Language :: English
@@ -18,12 +18,12 @@ Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
19
  Requires-Python: >=3.11
20
20
  License-File: LICENSE.txt
21
- Requires-Dist: Django<5.0
22
- Requires-Dist: rules<4.0
23
21
  Requires-Dist: edx-drf-extensions
24
- Requires-Dist: djangorestframework<4.0
25
- Requires-Dist: attrs
26
22
  Requires-Dist: celery
23
+ Requires-Dist: rules<4.0
24
+ Requires-Dist: attrs
25
+ Requires-Dist: Django<5.0
26
+ Requires-Dist: djangorestframework<4.0
27
27
 
28
28
  Open edX Learning Core (and Tagging)
29
29
  ====================================
@@ -1,4 +1,4 @@
1
1
  """
2
2
  Open edX Learning ("Learning Core").
3
3
  """
4
- __version__ = "0.11.2"
4
+ __version__ = "0.11.4"
@@ -0,0 +1,168 @@
1
+ """
2
+ Collections API (warning: UNSTABLE, in progress API)
3
+ """
4
+ from __future__ import annotations
5
+
6
+ from datetime import datetime, timezone
7
+
8
+ from django.core.exceptions import ValidationError
9
+ from django.db.models import QuerySet
10
+
11
+ from ..publishing import api as publishing_api
12
+ from ..publishing.models import PublishableEntity
13
+ from .models import Collection
14
+
15
+ # The public API that will be re-exported by openedx_learning.apps.authoring.api
16
+ # is listed in the __all__ entries below. Internal helper functions that are
17
+ # private to this module should start with an underscore. If a function does not
18
+ # start with an underscore AND it is not in __all__, that function is considered
19
+ # to be callable only by other apps in the authoring package.
20
+ __all__ = [
21
+ "add_to_collection",
22
+ "create_collection",
23
+ "get_collection",
24
+ "get_collections",
25
+ "get_entity_collections",
26
+ "remove_from_collection",
27
+ "update_collection",
28
+ ]
29
+
30
+
31
+ def create_collection(
32
+ learning_package_id: int,
33
+ key: str,
34
+ *,
35
+ title: str,
36
+ created_by: int | None,
37
+ description: str = "",
38
+ enabled: bool = True,
39
+ ) -> Collection:
40
+ """
41
+ Create a new Collection
42
+ """
43
+ collection = Collection.objects.create(
44
+ learning_package_id=learning_package_id,
45
+ key=key,
46
+ title=title,
47
+ created_by_id=created_by,
48
+ description=description,
49
+ enabled=enabled,
50
+ )
51
+ return collection
52
+
53
+
54
+ def get_collection(learning_package_id: int, collection_key: str) -> Collection:
55
+ """
56
+ Get a Collection by ID
57
+ """
58
+ return Collection.objects.get_by_key(learning_package_id, collection_key)
59
+
60
+
61
+ def update_collection(
62
+ learning_package_id: int,
63
+ key: str,
64
+ *,
65
+ title: str | None = None,
66
+ description: str | None = None,
67
+ ) -> Collection:
68
+ """
69
+ Update a Collection identified by the learning_package_id + key.
70
+ """
71
+ collection = get_collection(learning_package_id, key)
72
+
73
+ # If no changes were requested, there's nothing to update, so just return
74
+ # the Collection as-is
75
+ if all(field is None for field in [title, description]):
76
+ return collection
77
+
78
+ if title is not None:
79
+ collection.title = title
80
+ if description is not None:
81
+ collection.description = description
82
+
83
+ collection.save()
84
+ return collection
85
+
86
+
87
+ def add_to_collection(
88
+ learning_package_id: int,
89
+ key: str,
90
+ entities_qset: QuerySet[PublishableEntity],
91
+ created_by: int | None = None,
92
+ ) -> Collection:
93
+ """
94
+ Adds a QuerySet of PublishableEntities to a Collection.
95
+
96
+ These Entities must belong to the same LearningPackage as the Collection, or a ValidationError will be raised.
97
+
98
+ PublishableEntities already in the Collection are silently ignored.
99
+
100
+ The Collection object's modified date is updated.
101
+
102
+ Returns the updated Collection object.
103
+ """
104
+ # Disallow adding entities outside the collection's learning package
105
+ invalid_entity = entities_qset.exclude(learning_package_id=learning_package_id).first()
106
+ if invalid_entity:
107
+ raise ValidationError(
108
+ f"Cannot add entity {invalid_entity.pk} in learning package {invalid_entity.learning_package_id} "
109
+ f"to collection {key} in learning package {learning_package_id}."
110
+ )
111
+
112
+ collection = get_collection(learning_package_id, key)
113
+ collection.entities.add(
114
+ *entities_qset.all(),
115
+ through_defaults={"created_by_id": created_by},
116
+ )
117
+ collection.modified = datetime.now(tz=timezone.utc)
118
+ collection.save()
119
+
120
+ return collection
121
+
122
+
123
+ def remove_from_collection(
124
+ learning_package_id: int,
125
+ key: str,
126
+ entities_qset: QuerySet[PublishableEntity],
127
+ ) -> Collection:
128
+ """
129
+ Removes a QuerySet of PublishableEntities from a Collection.
130
+
131
+ PublishableEntities are deleted (in bulk).
132
+
133
+ The Collection's modified date is updated (even if nothing was removed).
134
+
135
+ Returns the updated Collection.
136
+ """
137
+ collection = get_collection(learning_package_id, key)
138
+
139
+ collection.entities.remove(*entities_qset.all())
140
+ collection.modified = datetime.now(tz=timezone.utc)
141
+ collection.save()
142
+
143
+ return collection
144
+
145
+
146
+ def get_entity_collections(learning_package_id: int, entity_key: str) -> QuerySet[Collection]:
147
+ """
148
+ Get all collections in the given learning package which contain this entity.
149
+
150
+ Only enabled collections are returned.
151
+ """
152
+ entity = publishing_api.get_publishable_entity_by_key(
153
+ learning_package_id,
154
+ key=entity_key,
155
+ )
156
+ return entity.collections.filter(enabled=True).order_by("pk")
157
+
158
+
159
+ def get_collections(learning_package_id: int, enabled: bool | None = True) -> QuerySet[Collection]:
160
+ """
161
+ Get all collections for a given learning package
162
+
163
+ Enabled collections are returned by default.
164
+ """
165
+ qs = Collection.objects.filter(learning_package_id=learning_package_id)
166
+ if enabled is not None:
167
+ qs = qs.filter(enabled=enabled)
168
+ return qs.select_related("learning_package").order_by('pk')
@@ -0,0 +1,38 @@
1
+ # Generated by Django 4.2.15 on 2024-08-29 00:05
2
+
3
+ import django.db.models.deletion
4
+ from django.conf import settings
5
+ from django.db import migrations, models
6
+
7
+ import openedx_learning.lib.validators
8
+
9
+
10
+ class Migration(migrations.Migration):
11
+
12
+ dependencies = [
13
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14
+ ('oel_publishing', '0002_alter_learningpackage_key_and_more'),
15
+ ('oel_collections', '0002_remove_collection_name_collection_created_by_and_more'),
16
+ ]
17
+
18
+ operations = [
19
+ migrations.CreateModel(
20
+ name='CollectionPublishableEntity',
21
+ fields=[
22
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23
+ ('created', models.DateTimeField(auto_now_add=True, validators=[openedx_learning.lib.validators.validate_utc_datetime])),
24
+ ('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='oel_collections.collection')),
25
+ ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
26
+ ('entity', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='oel_publishing.publishableentity')),
27
+ ],
28
+ ),
29
+ migrations.AddField(
30
+ model_name='collection',
31
+ name='entities',
32
+ field=models.ManyToManyField(related_name='collections', through='oel_collections.CollectionPublishableEntity', to='oel_publishing.publishableentity'),
33
+ ),
34
+ migrations.AddConstraint(
35
+ model_name='collectionpublishableentity',
36
+ constraint=models.UniqueConstraint(fields=('collection', 'entity'), name='oel_collections_cpe_uniq_col_ent'),
37
+ ),
38
+ ]
@@ -0,0 +1,57 @@
1
+ # Generated by Django 4.2.15 on 2024-09-04 23:15
2
+
3
+ from django.db import migrations, models
4
+ from django.utils.crypto import get_random_string
5
+
6
+ import openedx_learning.lib.fields
7
+
8
+
9
+ def generate_keys(apps, schema_editor):
10
+ """
11
+ Generates a random strings to initialize the key field where NULL.
12
+ """
13
+ length = 50
14
+ Collection = apps.get_model("oel_collections", "Collection")
15
+ for collection in Collection.objects.filter(key=None):
16
+ # Keep generating keys until we get a unique one
17
+ key = get_random_string(length)
18
+ while Collection.objects.filter(key=key).exists():
19
+ key = get_random_string(length)
20
+
21
+ collection.key = key
22
+ collection.save()
23
+
24
+
25
+ class Migration(migrations.Migration):
26
+
27
+ dependencies = [
28
+ ('oel_collections', '0003_collection_entities'),
29
+ ]
30
+
31
+ operations = [
32
+ # 1. Temporarily add this field with null=True, blank=True
33
+ migrations.AddField(
34
+ model_name='collection',
35
+ name='key',
36
+ field=openedx_learning.lib.fields.MultiCollationCharField(
37
+ db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
38
+ db_column='_key', max_length=500, null=True, blank=True),
39
+ preserve_default=False,
40
+ ),
41
+ # 2. Populate the null keys
42
+ migrations.RunPython(generate_keys),
43
+ # 3. Add null=False, blank=False to disallow NULL values
44
+ migrations.AlterField(
45
+ model_name='collection',
46
+ name='key',
47
+ field=openedx_learning.lib.fields.MultiCollationCharField(
48
+ db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
49
+ db_column='_key', max_length=500, null=False, blank=False),
50
+ preserve_default=False,
51
+ ),
52
+ # 4. Enforce unique constraint
53
+ migrations.AddConstraint(
54
+ model_name='collection',
55
+ constraint=models.UniqueConstraint(fields=('learning_package', 'key'), name='oel_coll_uniq_lp_key'),
56
+ ),
57
+ ]
@@ -0,0 +1,237 @@
1
+ """
2
+ Core models for Collections
3
+
4
+ TLDR Guidelines:
5
+ 1. DO NOT modify these models to store full version snapshots.
6
+ 2. DO NOT use these models to try to reconstruct historical versions of
7
+ Collections for fast querying.
8
+
9
+ If you're trying to do either of these things, you probably want a new model or
10
+ app. For more details, read on.
11
+
12
+ The goal of these models is to provide a lightweight method of organizing
13
+ PublishableEntities. The first use case for this is modeling the structure of a
14
+ v1 Content Library within a LearningPackage. This is what we'll use the
15
+ Collection model for.
16
+
17
+ An important thing to note here is that Collections are *NOT* publishable
18
+ entities themselves. They have no "Draft" or "Published" versions. Collections
19
+ are never "published", though the things inside of them are.
20
+
21
+ When a LibraryContentBlock makes use of a Content Library, it copies all of
22
+ the items it will use into the Course itself. It will also store a version
23
+ on the LibraryContentBlock -- this is a MongoDB ObjectID in v1 and an integer in
24
+ v2 Libraries. Later on, the LibraryContentBlock will want to check back to see
25
+ if any updates have been made, using its version as a key. If a new version
26
+ exists, the course team has the option of re-copying data from the Library.
27
+
28
+ ModuleStore based v1 Libraries and Blockstore-based v2 libraries both version
29
+ the entire library in a series of snapshots. This makes it difficult to have
30
+ very large libraries, which is an explicit goal for Modular Learning. In
31
+ Learning Core, we've moved to tracking the versions of individual Components to
32
+ address this issue. But that means we no longer have a single version indicator
33
+ for "has anything here changed"?
34
+
35
+ We *could* have put that version in the ``publishing`` app's PublishLog, but
36
+ that would make it too broad. We want the ability to eventually collapse many v1
37
+ Libraries into a single Learning Core backed v2 Library. If we tracked the
38
+ versioning in only a central location, then we'd have many false positives where
39
+ the version was bumped because something else in the Learning Package changed.
40
+ So instead, we're creating a new Collection model inside the LearningPackage to
41
+ track that concept.
42
+
43
+ A critical takeaway is that we don't have to store snapshots of every version of
44
+ a Collection, because that data has been copied over by the LibraryContentBlock.
45
+ We only need to store the current state of the Collection, and increment the
46
+ version numbers when changes happen. This will allow the LibraryContentBlock to
47
+ check in and re-copy over the latest version if the course team desires.
48
+
49
+ That's why these models only store the current state of a Collection. Unlike the
50
+ ``components`` app, ``collections`` does not store fully materialized snapshots
51
+ of past versions. This is done intentionally in order to save space and reduce
52
+ the cost of writes. Collections may grow to be very large, and we don't want to
53
+ be writing N rows with every version, where N is the number of
54
+ PublishableEntities in a Collection.
55
+
56
+ MVP of these models does not store changesets, but we can add this when there's a
57
+ use case for it. The number of rows in these changesets would grow in proportion
58
+ to the number of things that are actually changing (instead of copying over
59
+ everything on every version). This is could be used to make it easier to figure out
60
+ what changed between two given versions of a Collection. A LibraryContentBlock
61
+ in a course would have stored the version number of the last time it copied data
62
+ from the Collection, and we can eventually surface this data to the user. Note that
63
+ while it may be possible to reconstruct past versions of Collections based off of
64
+ this changeset data, it's going to be a very slow process to do so, and it is
65
+ strongly discouraged.
66
+ """
67
+ from __future__ import annotations
68
+
69
+ from django.conf import settings
70
+ from django.db import models
71
+ from django.utils.translation import gettext_lazy as _
72
+
73
+ from openedx_learning.lib.fields import MultiCollationTextField, case_insensitive_char_field, key_field
74
+ from openedx_learning.lib.validators import validate_utc_datetime
75
+
76
+ from ..publishing.models import LearningPackage, PublishableEntity
77
+
78
+ __all__ = [
79
+ "Collection",
80
+ "CollectionPublishableEntity",
81
+ ]
82
+
83
+
84
+ class CollectionManager(models.Manager):
85
+ """
86
+ Custom manager for Collection class.
87
+ """
88
+ def get_by_key(self, learning_package_id: int, key: str):
89
+ """
90
+ Get the Collection for the given Learning Package + key.
91
+ """
92
+ return self.select_related('learning_package') \
93
+ .get(learning_package_id=learning_package_id, key=key)
94
+
95
+
96
+ class Collection(models.Model):
97
+ """
98
+ Represents a collection of library components
99
+ """
100
+ objects: CollectionManager[Collection] = CollectionManager()
101
+
102
+ id = models.AutoField(primary_key=True)
103
+
104
+ # Each collection belongs to a learning package
105
+ learning_package = models.ForeignKey(LearningPackage, on_delete=models.CASCADE)
106
+
107
+ # Every collection is uniquely and permanently identified within its learning package
108
+ # by a 'key' that is set during creation. Both will appear in the
109
+ # collection's opaque key:
110
+ # e.g. "lib-collection:lib:key" is the opaque key for a library collection.
111
+ key = key_field(db_column='_key')
112
+
113
+ title = case_insensitive_char_field(
114
+ null=False,
115
+ blank=False,
116
+ max_length=500,
117
+ help_text=_(
118
+ "The title of the collection."
119
+ ),
120
+ )
121
+
122
+ description = MultiCollationTextField(
123
+ blank=True,
124
+ null=False,
125
+ default="",
126
+ max_length=10_000,
127
+ help_text=_(
128
+ "Provides extra information for the user about this collection."
129
+ ),
130
+ db_collations={
131
+ "sqlite": "NOCASE",
132
+ "mysql": "utf8mb4_unicode_ci",
133
+ }
134
+ )
135
+
136
+ # We don't have api functions to handle the enabled field. This is a placeholder for future use and
137
+ # a way to "soft delete" collections.
138
+ enabled = models.BooleanField(
139
+ default=True,
140
+ help_text=_(
141
+ "Whether the collection is enabled or not."
142
+ ),
143
+ )
144
+
145
+ created_by = models.ForeignKey(
146
+ settings.AUTH_USER_MODEL,
147
+ on_delete=models.SET_NULL,
148
+ null=True,
149
+ blank=True,
150
+ )
151
+
152
+ created = models.DateTimeField(
153
+ auto_now_add=True,
154
+ validators=[
155
+ validate_utc_datetime,
156
+ ],
157
+ )
158
+
159
+ modified = models.DateTimeField(
160
+ auto_now=True,
161
+ validators=[
162
+ validate_utc_datetime,
163
+ ],
164
+ )
165
+
166
+ entities: models.ManyToManyField[PublishableEntity, "CollectionPublishableEntity"] = models.ManyToManyField(
167
+ PublishableEntity,
168
+ through="CollectionPublishableEntity",
169
+ related_name="collections",
170
+ )
171
+
172
+ class Meta:
173
+ verbose_name_plural = "Collections"
174
+ constraints = [
175
+ # Keys are unique within a given LearningPackage.
176
+ models.UniqueConstraint(
177
+ fields=[
178
+ "learning_package",
179
+ "key",
180
+ ],
181
+ name="oel_coll_uniq_lp_key",
182
+ ),
183
+ ]
184
+ indexes = [
185
+ models.Index(fields=["learning_package", "title"]),
186
+ ]
187
+
188
+ def __repr__(self) -> str:
189
+ """
190
+ Developer-facing representation of a Collection.
191
+ """
192
+ return str(self)
193
+
194
+ def __str__(self) -> str:
195
+ """
196
+ User-facing string representation of a Collection.
197
+ """
198
+ return f"<{self.__class__.__name__}> (lp:{self.learning_package_id} {self.key}:{self.title})"
199
+
200
+
201
+ class CollectionPublishableEntity(models.Model):
202
+ """
203
+ Collection -> PublishableEntity association.
204
+ """
205
+ collection = models.ForeignKey(
206
+ Collection,
207
+ on_delete=models.CASCADE,
208
+ )
209
+ entity = models.ForeignKey(
210
+ PublishableEntity,
211
+ on_delete=models.RESTRICT,
212
+ )
213
+ created_by = models.ForeignKey(
214
+ settings.AUTH_USER_MODEL,
215
+ on_delete=models.SET_NULL,
216
+ null=True,
217
+ blank=True,
218
+ )
219
+ created = models.DateTimeField(
220
+ auto_now_add=True,
221
+ validators=[
222
+ validate_utc_datetime,
223
+ ],
224
+ )
225
+
226
+ class Meta:
227
+ constraints = [
228
+ # Prevent race conditions from making multiple rows associating the
229
+ # same Collection to the same Entity.
230
+ models.UniqueConstraint(
231
+ fields=[
232
+ "collection",
233
+ "entity",
234
+ ],
235
+ name="oel_collections_cpe_uniq_col_ent",
236
+ )
237
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openedx-learning
3
- Version: 0.11.2
3
+ Version: 0.11.4
4
4
  Summary: Open edX Learning Core and Tagging.
5
5
  Home-page: https://github.com/openedx/openedx-learning
6
6
  Author: David Ormsbee
@@ -9,7 +9,7 @@ License: AGPL 3.0
9
9
  Keywords: Python edx
10
10
  Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Framework :: Django
12
- Classifier: Framework :: Django :: 3.2
12
+ Classifier: Framework :: Django :: 4.2
13
13
  Classifier: Intended Audience :: Developers
14
14
  Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
15
15
  Classifier: Natural Language :: English
@@ -18,12 +18,12 @@ Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
19
  Requires-Python: >=3.11
20
20
  License-File: LICENSE.txt
21
- Requires-Dist: Django<5.0
22
- Requires-Dist: rules<4.0
23
21
  Requires-Dist: edx-drf-extensions
24
- Requires-Dist: djangorestframework<4.0
25
- Requires-Dist: attrs
26
22
  Requires-Dist: celery
23
+ Requires-Dist: rules<4.0
24
+ Requires-Dist: attrs
25
+ Requires-Dist: Django<5.0
26
+ Requires-Dist: djangorestframework<4.0
27
27
 
28
28
  Open edX Learning Core (and Tagging)
29
29
  ====================================
@@ -23,6 +23,8 @@ openedx_learning/apps/authoring/collections/apps.py
23
23
  openedx_learning/apps/authoring/collections/models.py
24
24
  openedx_learning/apps/authoring/collections/migrations/0001_initial.py
25
25
  openedx_learning/apps/authoring/collections/migrations/0002_remove_collection_name_collection_created_by_and_more.py
26
+ openedx_learning/apps/authoring/collections/migrations/0003_collection_entities.py
27
+ openedx_learning/apps/authoring/collections/migrations/0004_collection_key.py
26
28
  openedx_learning/apps/authoring/collections/migrations/__init__.py
27
29
  openedx_learning/apps/authoring/components/__init__.py
28
30
  openedx_learning/apps/authoring/components/admin.py
@@ -85,7 +85,7 @@ setup(
85
85
  classifiers=[
86
86
  'Development Status :: 3 - Alpha',
87
87
  'Framework :: Django',
88
- 'Framework :: Django :: 3.2',
88
+ 'Framework :: Django :: 4.2',
89
89
  'Intended Audience :: Developers',
90
90
  'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
91
91
  'Natural Language :: English',
@@ -1,92 +0,0 @@
1
- """
2
- Collections API (warning: UNSTABLE, in progress API)
3
- """
4
- from __future__ import annotations
5
-
6
- from django.db.models import QuerySet
7
-
8
- from .models import Collection
9
-
10
- # The public API that will be re-exported by openedx_learning.apps.authoring.api
11
- # is listed in the __all__ entries below. Internal helper functions that are
12
- # private to this module should start with an underscore. If a function does not
13
- # start with an underscore AND it is not in __all__, that function is considered
14
- # to be callable only by other apps in the authoring package.
15
- __all__ = [
16
- "create_collection",
17
- "get_collection",
18
- "get_collections",
19
- "get_learning_package_collections",
20
- "update_collection",
21
- ]
22
-
23
-
24
- def create_collection(
25
- learning_package_id: int,
26
- title: str,
27
- created_by: int | None,
28
- description: str = "",
29
- ) -> Collection:
30
- """
31
- Create a new Collection
32
- """
33
- collection = Collection.objects.create(
34
- learning_package_id=learning_package_id,
35
- title=title,
36
- created_by_id=created_by,
37
- description=description,
38
- )
39
- return collection
40
-
41
-
42
- def get_collection(collection_id: int) -> Collection:
43
- """
44
- Get a Collection by ID
45
- """
46
- return Collection.objects.get(id=collection_id)
47
-
48
-
49
- def update_collection(
50
- collection_id: int,
51
- title: str | None = None,
52
- description: str | None = None,
53
- ) -> Collection:
54
- """
55
- Update a Collection
56
- """
57
- collection = Collection.objects.get(id=collection_id)
58
-
59
- # If no changes were requested, there's nothing to update, so just return
60
- # the Collection as-is
61
- if all(field is None for field in [title, description]):
62
- return collection
63
-
64
- if title is not None:
65
- collection.title = title
66
- if description is not None:
67
- collection.description = description
68
-
69
- collection.save()
70
- return collection
71
-
72
-
73
- def get_learning_package_collections(learning_package_id: int) -> QuerySet[Collection]:
74
- """
75
- Get all collections for a given learning package
76
-
77
- Only enabled collections are returned
78
- """
79
- return Collection.objects \
80
- .filter(learning_package_id=learning_package_id, enabled=True) \
81
- .select_related("learning_package") \
82
- .order_by('pk')
83
-
84
-
85
- def get_collections(enabled: bool | None = None) -> QuerySet[Collection]:
86
- """
87
- Get all collections, optionally caller can filter by enabled flag
88
- """
89
- qs = Collection.objects.all()
90
- if enabled is not None:
91
- qs = qs.filter(enabled=enabled)
92
- return qs.select_related("learning_package").order_by('pk')
@@ -1,98 +0,0 @@
1
- """
2
- Core models for Collections
3
- """
4
- from __future__ import annotations
5
-
6
- from django.conf import settings
7
- from django.db import models
8
- from django.utils.translation import gettext_lazy as _
9
-
10
- from ....lib.fields import MultiCollationTextField, case_insensitive_char_field
11
- from ....lib.validators import validate_utc_datetime
12
- from ..publishing.models import LearningPackage
13
-
14
- __all__ = [
15
- "Collection",
16
- ]
17
-
18
-
19
- class Collection(models.Model):
20
- """
21
- Represents a collection of library components
22
- """
23
-
24
- id = models.AutoField(primary_key=True)
25
-
26
- # Each collection belongs to a learning package
27
- learning_package = models.ForeignKey(LearningPackage, on_delete=models.CASCADE)
28
-
29
- title = case_insensitive_char_field(
30
- null=False,
31
- blank=False,
32
- max_length=500,
33
- help_text=_(
34
- "The title of the collection."
35
- ),
36
- )
37
-
38
- description = MultiCollationTextField(
39
- blank=True,
40
- null=False,
41
- default="",
42
- max_length=10_000,
43
- help_text=_(
44
- "Provides extra information for the user about this collection."
45
- ),
46
- db_collations={
47
- "sqlite": "NOCASE",
48
- "mysql": "utf8mb4_unicode_ci",
49
- }
50
- )
51
-
52
- # We don't have api functions to handle the enabled field. This is a placeholder for future use and
53
- # a way to "soft delete" collections.
54
- enabled = models.BooleanField(
55
- default=True,
56
- help_text=_(
57
- "Whether the collection is enabled or not."
58
- ),
59
- )
60
-
61
- created_by = models.ForeignKey(
62
- settings.AUTH_USER_MODEL,
63
- on_delete=models.SET_NULL,
64
- null=True,
65
- blank=True,
66
- )
67
-
68
- created = models.DateTimeField(
69
- auto_now_add=True,
70
- validators=[
71
- validate_utc_datetime,
72
- ],
73
- )
74
-
75
- modified = models.DateTimeField(
76
- auto_now=True,
77
- validators=[
78
- validate_utc_datetime,
79
- ],
80
- )
81
-
82
- class Meta:
83
- verbose_name_plural = "Collections"
84
- indexes = [
85
- models.Index(fields=["learning_package", "title"]),
86
- ]
87
-
88
- def __repr__(self) -> str:
89
- """
90
- Developer-facing representation of a Collection.
91
- """
92
- return str(self)
93
-
94
- def __str__(self) -> str:
95
- """
96
- User-facing string representation of a Collection.
97
- """
98
- return f"<{self.__class__.__name__}> ({self.id}:{self.title})"
@@ -1,6 +1,6 @@
1
- Django<5.0
2
- rules<4.0
3
1
  edx-drf-extensions
4
- djangorestframework<4.0
5
- attrs
6
2
  celery
3
+ rules<4.0
4
+ attrs
5
+ Django<5.0
6
+ djangorestframework<4.0