diff --git a/openedx_learning/apps/authoring/containers/models.py b/openedx_learning/apps/authoring/containers/models.py index a441823c..66588bf3 100644 --- a/openedx_learning/apps/authoring/containers/models.py +++ b/openedx_learning/apps/authoring/containers/models.py @@ -1,7 +1,13 @@ from django.db import models -from openedx_learning.apps.authoring.publishing.models import PublishableEntity, PublishableEntityVersion -from ..publishing.model_mixins import PublishableEntityMixin, PublishableEntityVersionMixin +from openedx_learning.apps.authoring.publishing.models import ( + PublishableEntity, + PublishableEntityVersion, +) +from ..publishing.model_mixins import ( + PublishableEntityMixin, + PublishableEntityVersionMixin, +) class EntityList(models.Model): @@ -14,6 +20,7 @@ class EntityList(models.Model): anonymous in a sense–they're pointed to by ContainerEntityVersions and other models, rather than being looked up by their own identifers. """ + pass @@ -25,6 +32,7 @@ class EntityListRow(models.Model): There is a row in this table for each member of an EntityList. The order_num field is used to determine the order of the members in the list. """ + entity_list = models.ForeignKey(EntityList, on_delete=models.CASCADE) # This ordering should be treated as immutable–if the ordering needs to @@ -70,6 +78,7 @@ class ContainerEntity(PublishableEntityMixin): PublishLog and Containers that were affected in a publish because their child elements were published. """ + pass @@ -93,6 +102,7 @@ class ContainerEntityVersion(PublishableEntityVersionMixin): makes things easier to reason about if we say that defined_list never changes for a given ContainerEntityVersion. """ + container = models.ForeignKey( ContainerEntity, on_delete=models.CASCADE, diff --git a/openedx_learning/apps/authoring/units/api.py b/openedx_learning/apps/authoring/units/api.py index 6b6c8731..9e06a8ad 100644 --- a/openedx_learning/apps/authoring/units/api.py +++ b/openedx_learning/apps/authoring/units/api.py @@ -4,9 +4,13 @@ """ from django.db.transaction import atomic + +from openedx_learning.apps.authoring.containers.models import EntityListRow from ..publishing import api as publishing_api from ..containers import api as container_api from .models import Unit, UnitVersion +from django.db.models import QuerySet + from datetime import datetime @@ -18,10 +22,9 @@ "get_unit", "get_unit_version", "get_latest_unit_version", - "get_unit_version_by_version_num", - "get_user_defined_components_in_unit_version", - "get_initial_components_in_unit_version", - "get_frozen_components_in_unit_version", + "get_user_defined_list_in_unit_version", + "get_initial_list_in_unit_version", + "get_frozen_list_in_unit_version", ] @@ -175,23 +178,14 @@ def get_latest_unit_version(unit_pk: int) -> UnitVersion: return Unit.objects.get(pk=unit_pk).versioning.latest -def get_unit_version_by_version_num(unit_pk: int, version_num: int) -> UnitVersion: - """Get a unit version by version number. - - Args: - unit_pk: The unit ID. - version_num: The version number. - """ - return Unit.objects.get(pk=unit_pk).versioning.get(version_num=version_num) - - -def get_user_defined_list_in_unit_version(unit_version_pk: int) -> list[int]: +def get_user_defined_list_in_unit_version(unit_version_pk: int) -> QuerySet[EntityListRow]: """Get the list in a unit version. Args: unit_version_pk: The unit version ID. """ - return UnitVersion.objects.get(pk=unit_version_pk).container_version.defined_list + unit_version = UnitVersion.objects.get(pk=unit_version_pk) + return container_api.get_defined_list_for_container_version(unit_version.container_entity_version) def get_initial_list_in_unit_version(unit_version_pk: int) -> list[int]: @@ -200,7 +194,8 @@ def get_initial_list_in_unit_version(unit_version_pk: int) -> list[int]: Args: unit_version_pk: The unit version ID. """ - return UnitVersion.objects.get(pk=unit_version_pk).container_version.initial_list + unit_version = UnitVersion.objects.get(pk=unit_version_pk) + return container_api.get_initial_list_for_container_version(unit_version.container_entity_version) def get_frozen_list_in_unit_version(unit_version_pk: int) -> list[int]: @@ -209,4 +204,5 @@ def get_frozen_list_in_unit_version(unit_version_pk: int) -> list[int]: Args: unit_version_pk: The unit version ID. """ - return UnitVersion.objects.get(pk=unit_version_pk).container_version.frozen_list + unit_version = UnitVersion.objects.get(pk=unit_version_pk) + return container_api.get_frozen_list_for_container_version(unit_version.container_entity_version) diff --git a/openedx_learning/apps/authoring/units/models.py b/openedx_learning/apps/authoring/units/models.py index 943ef514..a9d167a2 100644 --- a/openedx_learning/apps/authoring/units/models.py +++ b/openedx_learning/apps/authoring/units/models.py @@ -1,16 +1,19 @@ from django.db import models -from ..containers.model_mixin import ContainerEntityMixin, ContainerEntityVersionMixin +from ..containers.models_mixin import ContainerEntityMixin, ContainerEntityVersionMixin + class Unit(ContainerEntityMixin): """ A Unit is Container, which is a PublishableEntity. """ + class UnitVersion(ContainerEntityVersionMixin): """ A UnitVersion is a ContainerVersion, which is a PublishableEntityVersion. """ + # Not sure what other metadata goes here, but we want to try to separate things # like scheduling information and such into different models. unit = models.ForeignKey( @@ -18,4 +21,3 @@ class UnitVersion(ContainerEntityVersionMixin): on_delete=models.CASCADE, related_name="versions", ) -