Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ venv/
!.vscode/settings.json.example

# Media files (for uploads)
media/
/media/

# Media files generated during test runs
test_media/
/test_media/

# uv stuff
.lock
CACHEDIR.TAG
pyvenv.cfg
10 changes: 5 additions & 5 deletions .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ layers=
openedx_learning.api.authoring

# The "backup_restore" app handle the new export and import mechanism.
openedx_learning.apps.authoring.backup_restore
openedx_learning.apps.authoring.applets.backup_restore

# The "components" app is responsible for storing versioned Components,
# which is Open edX Studio terminology maps to things like individual
# Problems, Videos, and blocks of HTML text. This is also the type we would
# associate with a single "leaf" XBlock–one that is not a container type and
# has no child elements.
openedx_learning.apps.authoring.components
openedx_learning.apps.authoring.applets.components

# The "contents" app stores the simplest pieces of binary and text data,
# without versioning information. These belong to a single Learning Package.
openedx_learning.apps.authoring.contents
openedx_learning.apps.authoring.applets.contents

# The "collections" app stores arbitrary groupings of PublishableEntities.
# Its only dependency should be the publishing app.
openedx_learning.apps.authoring.collections
openedx_learning.apps.authoring.applets.collections

# The lowest layer is "publishing", which holds the basic primitives needed
# to create Learning Packages and manage the draft and publish states for
# various types of content.
openedx_learning.apps.authoring.publishing
openedx_learning.apps.authoring.applets.publishing
6 changes: 3 additions & 3 deletions docs/decisions/0016-python-public-api-conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Learning Core Django apps will be grouped into packages.
Apps in ``openedx_learning`` will be grouped into broadly related packages under ``openedx_learning.apps``. The first of these groups will be "authoring" (``openedx_learning.apps.authoring``). Future packages may include "learner", "personalization", "activity", "grading", etc.

Learning Core Django apps will continue to have their own ``api`` modules.
So for example, ``openedx_learning.apps.authoring.components.api`` will continue to exist.
So for example, ``openedx_learning.apps.authoring.applets.components.api`` will continue to exist.

Learning Core will have a top level package for its public API.
All public APIs intended for use by consumers of Learning Core will be represented as modules in the ``openedx_learning.api`` package that corresponds to the app groupings (e.g. ``openedx_learning.api.authoring``).
Expand All @@ -35,14 +35,14 @@ App ``api`` modules will define their public functions using ``__all__``.
This relies on the individual apps to properly set ``__all__`` to the list of functions that they are willing to publicly support.

App ``api`` modules within a package of apps still import from each other.
So for example, ``openedx_learning.apps.authoring.components.api`` will continue to import APIs that it needs from ``..publishing.api``, instead of using the public API at ``openedx_learning.api.authoring``. These imports should not use wildcards.
So for example, ``openedx_learning.apps.authoring.applets.components.api`` will continue to import APIs that it needs from ``..publishing.api``, instead of using the public API at ``openedx_learning.api.authoring``. These imports should not use wildcards.

Functions and constants that are not listed as part of a module's ``__all__`` may still be imported by other app APIs in the same package grouping. This should allow a package more flexibility to create provisional APIs that we may not want to support publicly.

If a function or attribute is intended to be completely private to an app's ``api`` module (i.e. not used even by other apps in its package), it should be prefixed with an underscore.

App ``api`` modules should not import directly from apps outside their package.
For example, ``openedx_learning.apps.personalization.api`` should import authoring API functions from ``openedx_learning.api.authoring``, **not** directly from something like ``openedx_learning.apps.authoring.components.api``. This will help to limit the impact of refactoring app package internal changes, as well as exposing shortcomings in the existing public APIs.
For example, ``openedx_learning.apps.personalization.api`` should import authoring API functions from ``openedx_learning.api.authoring``, **not** directly from something like ``openedx_learning.apps.authoring.applets.components.api``. This will help to limit the impact of refactoring app package internal changes, as well as exposing shortcomings in the existing public APIs.

Public API modules may implement their own functions.
In addition to aggregating app ``api`` modules via wildcard imports, public API modules like ``openedx_learning.api.authoring`` may implement their own functionality. This will be useful for convenience functions that invoke multiple app APIs, and for backwards compatibility shims. When possible, the bulk of the logic for these should continue to live in app-defined APIs, with the public API module acting more as a glue layer.
Expand Down
6 changes: 3 additions & 3 deletions olx_importer/management/commands/load_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from django.db import transaction

# Model references to remove
from openedx_learning.apps.authoring.components import api as components_api
from openedx_learning.apps.authoring.contents import api as contents_api
from openedx_learning.apps.authoring.publishing import api as publishing_api
from openedx_learning.apps.authoring.applets.components import api as components_api
from openedx_learning.apps.authoring.applets.contents import api as contents_api
from openedx_learning.apps.authoring.applets.publishing import api as publishing_api

SUPPORTED_TYPES = ["problem", "video", "html"]
logger = logging.getLogger(__name__)
Expand Down
16 changes: 8 additions & 8 deletions openedx_learning/api/authoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"""
# These wildcard imports are okay because these api modules declare __all__.
# pylint: disable=wildcard-import
from ..apps.authoring.backup_restore.api import *
from ..apps.authoring.collections.api import *
from ..apps.authoring.components.api import *
from ..apps.authoring.contents.api import *
from ..apps.authoring.publishing.api import *
from ..apps.authoring.sections.api import *
from ..apps.authoring.subsections.api import *
from ..apps.authoring.units.api import *
from ..apps.authoring.applets.backup_restore.api import *
from ..apps.authoring.applets.collections.api import *
from ..apps.authoring.applets.components.api import *
from ..apps.authoring.applets.contents.api import *
from ..apps.authoring.applets.publishing.api import *
from ..apps.authoring.applets.sections.api import *
from ..apps.authoring.applets.subsections.api import *
from ..apps.authoring.applets.units.api import *

# This was renamed after the authoring API refactoring pushed this and other
# app APIs into the openedx_learning.api.authoring module. Here I'm aliasing to
Expand Down
14 changes: 7 additions & 7 deletions openedx_learning/api/authoring_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""
# These wildcard imports are okay because these modules declare __all__.
# pylint: disable=wildcard-import
from ..apps.authoring.collections.models import *
from ..apps.authoring.components.models import *
from ..apps.authoring.contents.models import *
from ..apps.authoring.publishing.models import *
from ..apps.authoring.sections.models import *
from ..apps.authoring.subsections.models import *
from ..apps.authoring.units.models import *
from ..apps.authoring.applets.collections.models import *
from ..apps.authoring.applets.components.models import *
from ..apps.authoring.applets.contents.models import *
from ..apps.authoring.applets.publishing.models import *
from ..apps.authoring.applets.sections.models import *
from ..apps.authoring.applets.subsections.models import *
from ..apps.authoring.applets.units.models import *
12 changes: 12 additions & 0 deletions openedx_learning/apps/authoring/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .applets.backup_restore.admin import *
from .applets.collections.admin import *
from .applets.components.admin import *
from .applets.contents.admin import *
from .applets.publishing.admin import *
from .applets.sections.admin import *
from .applets.subsections.admin import *
from .applets.units.admin import *

#from openedx_learning.lib import appletslib

#globals().update(appletslib.auto_import_admin())
12 changes: 12 additions & 0 deletions openedx_learning/apps/authoring/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .applets.backup_restore.api import *
from .applets.collections.api import *
from .applets.components.api import *
from .applets.contents.api import *
from .applets.publishing.api import *
from .applets.sections.api import *
from .applets.subsections.api import *
from .applets.units.api import *

#from openedx_learning.lib import appletslib

#globals().update(appletslib.auto_import_api())
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from django.contrib.auth.models import User as UserType # pylint: disable=imported-auth-user

from openedx_learning.apps.authoring.backup_restore.zipper import LearningPackageUnzipper, LearningPackageZipper
from openedx_learning.apps.authoring.publishing.api import get_learning_package_by_key
from .zipper import LearningPackageUnzipper, LearningPackageZipper
from ..publishing.api import get_learning_package_by_key


def create_zip_file(lp_key: str, path: str, user: UserType | None = None, origin_server: str | None = None) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from rest_framework import serializers

from openedx_learning.apps.authoring.components import api as components_api
from ..components import api as components_api


class LearningPackageSerializer(serializers.Serializer): # pylint: disable=abstract-method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import tomlkit
from django.contrib.auth.models import User as UserType # pylint: disable=imported-auth-user

from openedx_learning.apps.authoring.collections.models import Collection
from openedx_learning.apps.authoring.publishing import api as publishing_api
from openedx_learning.apps.authoring.publishing.models import PublishableEntity, PublishableEntityVersion
from openedx_learning.apps.authoring.publishing.models.learning_package import LearningPackage
from ..collections.models import Collection
from ..publishing import api as publishing_api
from ..publishing.models import PublishableEntity, PublishableEntityVersion
from ..publishing.models.learning_package import LearningPackage


def toml_learning_package(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
PublishableEntity,
PublishableEntityVersion,
)
from openedx_learning.apps.authoring.backup_restore.serializers import (
from .serializers import (
CollectionSerializer,
ComponentSerializer,
ComponentVersionSerializer,
Expand All @@ -37,21 +37,21 @@
LearningPackageMetadataSerializer,
LearningPackageSerializer,
)
from openedx_learning.apps.authoring.backup_restore.toml import (
from .toml import (
parse_collection_toml,
parse_learning_package_toml,
parse_publishable_entity_toml,
toml_collection,
toml_learning_package,
toml_publishable_entity,
)
from openedx_learning.apps.authoring.collections import api as collections_api
from openedx_learning.apps.authoring.components import api as components_api
from openedx_learning.apps.authoring.contents import api as contents_api
from openedx_learning.apps.authoring.publishing import api as publishing_api
from openedx_learning.apps.authoring.sections import api as sections_api
from openedx_learning.apps.authoring.subsections import api as subsections_api
from openedx_learning.apps.authoring.units import api as units_api
from ..collections import api as collections_api
from ..components import api as components_api
from ..contents import api as contents_api
from ..publishing import api as publishing_api
from ..sections import api as sections_api
from ..subsections import api as subsections_api
from ..units import api as units_api

TOML_PACKAGE_NAME = "package.toml"
DEFAULT_USERNAME = "command"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class Meta:
),
]
indexes = [
models.Index(fields=["learning_package", "title"]),
models.Index(
fields=["learning_package", "title"],
name="oel_authoring_coll_lp_title",
),
]

def __repr__(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

from django.db import models

from ....lib.fields import case_sensitive_char_field, key_field
from ....lib.managers import WithRelationsManager
from openedx_learning.lib.fields import case_sensitive_char_field, key_field
from openedx_learning.lib.managers import WithRelationsManager
from ..contents.models import Content
from ..publishing.models import LearningPackage, PublishableEntityMixin, PublishableEntityVersionMixin

Expand Down Expand Up @@ -63,6 +63,7 @@ class ComponentType(models.Model):
# the UsageKey.
name = case_sensitive_char_field(max_length=100, blank=True)

# TODO: this needs to go into a class Meta
constraints = [
models.UniqueConstraint(
fields=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.core.files.base import ContentFile
from django.db.transaction import atomic

from ....lib.fields import create_hash_digest
from openedx_learning.lib.fields import create_hash_digest
from .models import Content, MediaType

# The public API that will be re-exported by openedx_learning.apps.authoring.api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from django.db import models
from django.utils.module_loading import import_string

from ....lib.fields import MultiCollationTextField, case_insensitive_char_field, hash_field, manual_date_time_field
from ....lib.managers import WithRelationsManager
from openedx_learning.lib.fields import MultiCollationTextField, case_insensitive_char_field, hash_field, manual_date_time_field
from openedx_learning.lib.managers import WithRelationsManager
from ..publishing.models import LearningPackage

logger = getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EntityList(models.Model):
anonymous in a sense–they're pointed to by ContainerVersions and
other models, rather than being looked up by their own identifiers.
"""

@cached_property
def rows(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from django.db.transaction import atomic

from openedx_learning.apps.authoring.subsections.models import Subsection, SubsectionVersion
from ..subsections.models import Subsection, SubsectionVersion

from ..publishing import api as publishing_api
from .models import Section, SectionVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from django.db.transaction import atomic

from openedx_learning.apps.authoring.units.models import Unit, UnitVersion
from ..units.models import Unit, UnitVersion

from ..publishing import api as publishing_api
from .models import Subsection, SubsectionVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from django.db.transaction import atomic

from openedx_learning.apps.authoring.components.models import Component, ComponentVersion

from ..components.models import Component, ComponentVersion
from ..publishing import api as publishing_api
from .models import Unit, UnitVersion

Expand Down
22 changes: 22 additions & 0 deletions openedx_learning/apps/authoring/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.apps import AppConfig

class AuthoringConfig(AppConfig):
name = "openedx_learning.apps.authoring"
verbose_name = "Learning Core > Authoring"
default_auto_field = "django.db.models.BigAutoField"
label = "oel_authoring"

def ready(self):
from .api import register_publishable_models
from .models import (
Component, ComponentVersion,
Container, ContainerVersion,
Section, SectionVersion,
Subsection, SubsectionVersion,
Unit, UnitVersion,
)
register_publishable_models(Component, ComponentVersion)
register_publishable_models(Container, ContainerVersion)
register_publishable_models(Section, SectionVersion)
register_publishable_models(Subsection, SubsectionVersion)
register_publishable_models(Unit, UnitVersion)
12 changes: 0 additions & 12 deletions openedx_learning/apps/authoring/backup_restore/apps.py

This file was deleted.

15 changes: 0 additions & 15 deletions openedx_learning/apps/authoring/collections/apps.py

This file was deleted.

This file was deleted.

Loading
Loading