openedx-learning 0.12.0__py2.py3-none-any.whl → 0.13.1__py2.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.
@@ -1,4 +1,4 @@
1
1
  """
2
2
  Open edX Learning ("Learning Core").
3
3
  """
4
- __version__ = "0.12.0"
4
+ __version__ = "0.13.1"
@@ -0,0 +1,42 @@
1
+ """
2
+ Django Admin pages for Collection models.
3
+ """
4
+ from django.contrib import admin
5
+ from django.utils.translation import gettext_lazy as _
6
+
7
+ from .models import Collection
8
+
9
+
10
+ class CollectionAdmin(admin.ModelAdmin):
11
+ """
12
+ The Collection model admin.
13
+
14
+ Allows users to easily disable/enable (aka soft delete and restore) or bulk delete Collections.
15
+ """
16
+ readonly_fields = ["key", "learning_package"]
17
+ list_filter = ["enabled"]
18
+ list_display = ["key", "title", "enabled", "modified"]
19
+ fieldsets = [
20
+ (
21
+ "",
22
+ {
23
+ "fields": ["key", "learning_package"],
24
+ }
25
+ ),
26
+ (
27
+ _("Edit only in Studio"),
28
+ {
29
+ "fields": ["title", "enabled", "description", "created_by"],
30
+ "description": _("⚠ Changes made here should be done in Studio Django Admin, not the LMS."),
31
+ }
32
+ ),
33
+ ]
34
+
35
+ def has_add_permission(self, request, *args, **kwargs):
36
+ """
37
+ Disallow adding new collections via Django Admin.
38
+ """
39
+ return False # pragma: no cover
40
+
41
+
42
+ admin.site.register(Collection, CollectionAdmin)
@@ -20,10 +20,12 @@ from .models import Collection
20
20
  __all__ = [
21
21
  "add_to_collection",
22
22
  "create_collection",
23
+ "delete_collection",
23
24
  "get_collection",
24
25
  "get_collections",
25
26
  "get_entity_collections",
26
27
  "remove_from_collection",
28
+ "restore_collection",
27
29
  "update_collection",
28
30
  ]
29
31
 
@@ -84,6 +86,42 @@ def update_collection(
84
86
  return collection
85
87
 
86
88
 
89
+ def delete_collection(
90
+ learning_package_id: int,
91
+ key: str,
92
+ *,
93
+ hard_delete=False,
94
+ ) -> Collection:
95
+ """
96
+ Disables or deletes a collection identified by the given learning_package + key.
97
+
98
+ By default (hard_delete=False), the collection is "soft deleted", i.e disabled.
99
+ Soft-deleted collections can be re-enabled using restore_collection.
100
+ """
101
+ collection = get_collection(learning_package_id, key)
102
+
103
+ if hard_delete:
104
+ collection.delete()
105
+ else:
106
+ collection.enabled = False
107
+ collection.save()
108
+ return collection
109
+
110
+
111
+ def restore_collection(
112
+ learning_package_id: int,
113
+ key: str,
114
+ ) -> Collection:
115
+ """
116
+ Undo a "soft delete" by re-enabling a Collection.
117
+ """
118
+ collection = get_collection(learning_package_id, key)
119
+
120
+ collection.enabled = True
121
+ collection.save()
122
+ return collection
123
+
124
+
87
125
  def add_to_collection(
88
126
  learning_package_id: int,
89
127
  key: str,
@@ -0,0 +1,18 @@
1
+ # Generated by Django 4.2.15 on 2024-09-24 07:31
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ('oel_collections', '0004_collection_key'),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AlterField(
14
+ model_name='collection',
15
+ name='enabled',
16
+ field=models.BooleanField(default=True, help_text='Disabled collections are "soft deleted", and should be re-enabled before use, or be deleted.'),
17
+ ),
18
+ ]
@@ -133,12 +133,10 @@ class Collection(models.Model):
133
133
  }
134
134
  )
135
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
136
  enabled = models.BooleanField(
139
137
  default=True,
140
138
  help_text=_(
141
- "Whether the collection is enabled or not."
139
+ 'Disabled collections are "soft deleted", and should be re-enabled before use, or be deleted.',
142
140
  ),
143
141
  )
144
142
 
@@ -42,6 +42,7 @@ __all__ = [
42
42
  "get_component_by_uuid",
43
43
  "get_component_version_by_uuid",
44
44
  "component_exists_by_key",
45
+ "get_collection_components",
45
46
  "get_components",
46
47
  "create_component_version_content",
47
48
  "look_up_component_version_content",
@@ -339,6 +340,21 @@ def get_components(
339
340
  return qset
340
341
 
341
342
 
343
+ def get_collection_components(
344
+ learning_package_id: int,
345
+ collection_key: str,
346
+ ) -> QuerySet[Component]:
347
+ """
348
+ Returns a QuerySet of Components relating to the PublishableEntities in a Collection.
349
+
350
+ Components have a one-to-one relationship with PublishableEntity, but the reverse may not always be true.
351
+ """
352
+ return Component.objects.filter(
353
+ learning_package_id=learning_package_id,
354
+ publishable_entity__collections__key=collection_key,
355
+ ).order_by('pk')
356
+
357
+
342
358
  def look_up_component_version_content(
343
359
  learning_package_key: str,
344
360
  component_key: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openedx-learning
3
- Version: 0.12.0
3
+ Version: 0.13.1
4
4
  Summary: Open edX Learning Core and Tagging.
5
5
  Home-page: https://github.com/openedx/openedx-learning
6
6
  Author: David Ormsbee
@@ -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: celery
21
+ Requires-Dist: attrs
22
22
  Requires-Dist: Django<5.0
23
23
  Requires-Dist: djangorestframework<4.0
24
- Requires-Dist: rules<4.0
25
24
  Requires-Dist: edx-drf-extensions
26
- Requires-Dist: attrs
25
+ Requires-Dist: celery
26
+ Requires-Dist: rules<4.0
27
27
 
28
28
  Open edX Learning Core (and Tagging)
29
29
  ====================================
@@ -1,4 +1,4 @@
1
- openedx_learning/__init__.py,sha256=A3F2eIt1aRYsY0WQV1upYl-XM-eKJqIdLO55kEcvNuc,68
1
+ openedx_learning/__init__.py,sha256=ktqHmS9Hb8-3sCQfbMV2mr3Bd1bnH7z_ed1NYYChMB4,68
2
2
  openedx_learning/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  openedx_learning/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  openedx_learning/api/authoring.py,sha256=vbRpiQ2wOfN3oR2bbN0-bI2ra0QRtha9tVixKW1ENis,929
@@ -6,17 +6,19 @@ openedx_learning/api/authoring_models.py,sha256=PrhEYozI7nzC7N1v_sP1QgjwjRvLX6it
6
6
  openedx_learning/apps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  openedx_learning/apps/authoring/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  openedx_learning/apps/authoring/collections/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- openedx_learning/apps/authoring/collections/api.py,sha256=8jNn_S43JqWIGWyDvR7McxGJ-3TboibdHF3LWyQMFWE,4978
9
+ openedx_learning/apps/authoring/collections/admin.py,sha256=f0hySjDMfIphVDEGkCSMIUHoEiqHRA7EE2NiO7lvL4g,1156
10
+ openedx_learning/apps/authoring/collections/api.py,sha256=Lui-9mvlUjXSfCcaHrYJc2y2aJ1obJPCIp5hvxYwnkI,5894
10
11
  openedx_learning/apps/authoring/collections/apps.py,sha256=67imy9vnyXml4cfLNGFJhuZr2yx1q92-xz4ih3yJgNU,416
11
- openedx_learning/apps/authoring/collections/models.py,sha256=YAwDf8igFbs8Fox3QpbkzBOvYL39cBsRdelxlXx6IYs,8545
12
+ openedx_learning/apps/authoring/collections/models.py,sha256=os8EKUVZ2IhMfFo2XN9tklByCUXphEtzAkKAOc0KyW8,8451
12
13
  openedx_learning/apps/authoring/collections/migrations/0001_initial.py,sha256=xcJoqMLROW9FTILYrz6UsyotVu9wBN5tRBwRoAWG6dg,1496
13
14
  openedx_learning/apps/authoring/collections/migrations/0002_remove_collection_name_collection_created_by_and_more.py,sha256=NRl-_-EkE-w4JLeJsZf6lHxYNV3TIAJVIWbv_-xytGo,2162
14
15
  openedx_learning/apps/authoring/collections/migrations/0003_collection_entities.py,sha256=-YddfCFS0HW3JsEcpatjakOyeGVklOmba9uRQ-0zIxQ,1805
15
16
  openedx_learning/apps/authoring/collections/migrations/0004_collection_key.py,sha256=G1STMrsCjU8Ykp0Zm_nIf5YqZCBy1TRTVX7q7zrly8c,2021
17
+ openedx_learning/apps/authoring/collections/migrations/0005_alter_collection_options_alter_collection_enabled.py,sha256=HdU_3zxN32nzzvOFpiVpQXleHleJhnq2d8k7jAxhUTM,504
16
18
  openedx_learning/apps/authoring/collections/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
19
  openedx_learning/apps/authoring/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
20
  openedx_learning/apps/authoring/components/admin.py,sha256=QE7e76C6X2V1AQPxQe6SayQPfCMmbs4RZPEPIGcvTWw,4672
19
- openedx_learning/apps/authoring/components/api.py,sha256=FXYUUL6Q-MdsH78WKr9yRftJ9YcP5YfGDlJIIUT2zeA,21878
21
+ openedx_learning/apps/authoring/components/api.py,sha256=uIgJYLV6jfazt8rZgtKwhTKpgHhFurLwAfHL1cUMH9I,22410
20
22
  openedx_learning/apps/authoring/components/apps.py,sha256=YoYPsI9gcleA3uEs8CiLIrjUncRMo2DKbYt4mDfzePg,770
21
23
  openedx_learning/apps/authoring/components/models.py,sha256=T-wc7vxaWMlulQmMsVH7m6Pd857P3Eguo0vtflTLURI,13415
22
24
  openedx_learning/apps/authoring/components/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -108,8 +110,8 @@ openedx_tagging/core/tagging/rest_api/v1/serializers.py,sha256=gbvEBLvsmfPc3swWz
108
110
  openedx_tagging/core/tagging/rest_api/v1/urls.py,sha256=dNUKCtUCx_YzrwlbEbpDfjGVQbb2QdJ1VuJCkladj6E,752
109
111
  openedx_tagging/core/tagging/rest_api/v1/views.py,sha256=ZRkSILdb8g5k_BcuuVVfdffEdY9vFQ_YtMa3JrN0Xz8,35581
110
112
  openedx_tagging/core/tagging/rest_api/v1/views_import.py,sha256=kbHUPe5A6WaaJ3J1lFIcYCt876ecLNQfd19m7YYub6c,1470
111
- openedx_learning-0.12.0.dist-info/LICENSE.txt,sha256=QTW2QN7q3XszgUAXm9Dzgtu5LXYKbR1SGnqMa7ufEuY,35139
112
- openedx_learning-0.12.0.dist-info/METADATA,sha256=QwEYCY9OeCr03fC0GgdLy7eEpptZEaVFx1KcR8JoYeI,8777
113
- openedx_learning-0.12.0.dist-info/WHEEL,sha256=muXAwoPanksrVvf9Mcykr8l6Q0JyBrGUVYr50kE4bxo,109
114
- openedx_learning-0.12.0.dist-info/top_level.txt,sha256=IYFbr5mgiEHd-LOtZmXj3q3a0bkGK1M9LY7GXgnfi4M,33
115
- openedx_learning-0.12.0.dist-info/RECORD,,
113
+ openedx_learning-0.13.1.dist-info/LICENSE.txt,sha256=QTW2QN7q3XszgUAXm9Dzgtu5LXYKbR1SGnqMa7ufEuY,35139
114
+ openedx_learning-0.13.1.dist-info/METADATA,sha256=ESWEGMxOJNF9R6AwR48b_BDHw5022_jCQ3803_b_Jws,8777
115
+ openedx_learning-0.13.1.dist-info/WHEEL,sha256=muXAwoPanksrVvf9Mcykr8l6Q0JyBrGUVYr50kE4bxo,109
116
+ openedx_learning-0.13.1.dist-info/top_level.txt,sha256=IYFbr5mgiEHd-LOtZmXj3q3a0bkGK1M9LY7GXgnfi4M,33
117
+ openedx_learning-0.13.1.dist-info/RECORD,,