Skip to content

Commit

Permalink
chore: add backends (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV authored May 27, 2024
1 parent 51befb7 commit 569c698
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 269 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ Unreleased

*

0.5.1 - 2024-05-27
**********************************************

Changed
=======

* Add backends for edx-platform imports

0.5.0 - 2024-01-29
**********************************************

Changed
=======

* Use urllib constraint as in edx-platform

0.4.3 - 2023-11-27
**********************************************

Expand Down
4 changes: 1 addition & 3 deletions imagesgallery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
Init for the ImagesGalleryXBlock package.
"""

from .imagesgallery import ImagesGalleryXBlock

__version__ = '0.4.3'
__version__ = "0.5.1"
28 changes: 28 additions & 0 deletions imagesgallery/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Images Gallery Django application initialization.
"""

from django.apps import AppConfig


class ImagesGalleryConfig(AppConfig):
"""
Configuration for the Images Gallery Django application.
"""

name = "imagesgallery"

plugin_app = {
"settings_config": {
"lms.djangoapp": {
"common": {"relative_path": "settings.common"},
"test": {"relative_path": "settings.test"},
"production": {"relative_path": "settings.production"},
},
"cms.djangoapp": {
"common": {"relative_path": "settings.common"},
"test": {"relative_path": "settings.test"},
"production": {"relative_path": "settings.production"},
},
},
}
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions imagesgallery/edxapp_wrapper/backends/contentstore_r_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Contentstore module definitions for Open edX Redwood release.
"""

# pylint: disable=import-error, unused-import
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from cms.djangoapps.contentstore.views.assets import update_course_run_asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Site Configuration module definitions for Open edX Redwood release.
"""

# pylint: disable=import-error, unused-import
from openedx.core.djangoapps.site_configuration import helpers
40 changes: 40 additions & 0 deletions imagesgallery/edxapp_wrapper/contentstore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Contentstore module generalized definitions.
"""

from importlib import import_module

from django.conf import settings


def get_static_content():
"""
Wrapper for `xmodule.contentstore.content.StaticContent` in edx-platform.
"""
backend_function = settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND
backend = import_module(backend_function)

return backend.StaticContent


def contentstore(*args, **kwargs):
"""
Wrapper method of `xmodule.contentstore.django.contentstore` in edx-platform.
"""
backend_function = settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND
backend = import_module(backend_function)

return backend.contentstore(*args, **kwargs)


def update_course_run_asset(*args, **kwargs):
"""
Wrapper method of `cms.djangoapps.contentstore.views.assets.update_course_run_asset` in edx-platform.
"""
backend_function = settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND
backend = import_module(backend_function)

return backend.update_course_run_asset(*args, **kwargs)


StaticContent = get_static_content()
20 changes: 20 additions & 0 deletions imagesgallery/edxapp_wrapper/site_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Site Configuration module generalized definitions.
"""

from importlib import import_module

from django.conf import settings


def get_configuration_helpers():
"""
Wrapper for `openedx.core.djangoapps.site_configuration.helpers` function in edx-platform.
"""
backend_function = settings.IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND
backend = import_module(backend_function)

return backend.helpers


configuration_helpers = get_configuration_helpers()
26 changes: 7 additions & 19 deletions imagesgallery/imagesgallery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""TO-DO: Write a description of what this XBlock is."""
"""Images Gallery XBlock."""
from __future__ import annotations

import logging
Expand All @@ -9,23 +9,16 @@
import pkg_resources
from django.conf import settings
from django.utils import translation
from opaque_keys.edx.keys import AssetKey
from web_fragments.fragment import Fragment
from webob.response import Response
from xblock.core import XBlock
from xblock.fields import List, Scope
from xblock.fragment import Fragment
from xblock.reference.user_service import XBlockUser
from xblockutils.resources import ResourceLoader

try:
from opaque_keys.edx.keys import AssetKey
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
except ImportError:
configuration_helpers = None
StaticContent = None
contentstore = None
AssetKey = None
from xblock.utils.resources import ResourceLoader

from imagesgallery.edxapp_wrapper.contentstore import StaticContent, contentstore, update_course_run_asset
from imagesgallery.edxapp_wrapper.site_configuration import configuration_helpers

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -226,11 +219,6 @@ def studio_view(self, context=None) -> Fragment:
@XBlock.handler
def file_upload(self, request, suffix=''): # pylint: disable=unused-argument
"""Handler for file upload to the course assets."""
# Temporary fix for supporting both contentstore assets management versions (master / Palm)
try:
from cms.djangoapps.contentstore.views.assets import update_course_run_asset # pylint: disable=import-outside-toplevel
except ImportError:
from cms.djangoapps.contentstore.asset_storage_handler import update_course_run_asset # pylint: disable=import-outside-toplevel
uploaded_content = []
for _, file in request.params.items():
try:
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions imagesgallery/settings/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Settings for the Images Gallery XBlock.
"""


def plugin_settings(settings):
"""
Read / Update necessary common project settings.
"""
settings.IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND = "imagesgallery.edxapp_wrapper.backends.site_configuration_r_v1"
settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND = "imagesgallery.edxapp_wrapper.backends.contentstore_r_v1"
17 changes: 17 additions & 0 deletions imagesgallery/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Settings for the Images Gallery XBlock.
"""


def plugin_settings(settings):
"""
Read / Update necessary common project settings.
"""
settings.IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND = getattr(settings, "ENV_TOKENS", {}).get(
"IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND",
settings.IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND,
)
settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND = getattr(settings, "ENV_TOKENS", {}).get(
"IMAGES_GALLERY_CONTENTSTORE_BACKEND",
settings.IMAGES_GALLERY_CONTENTSTORE_BACKEND,
)
49 changes: 49 additions & 0 deletions imagesgallery/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Django settings for imagesgallery project.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os

SECRET_KEY = os.getenv("DJANGO_SECRET", "open_secret")

# Application definition

INSTALLED_APPS = (
"statici18n",
"imagesgallery",
)

# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "/static/"

# statici18n
# https://django-statici18n.readthedocs.io/en/latest/settings.html

STATICI18N_DOMAIN = "text"
STATICI18N_PACKAGES = ("imagesgallery.translations",)
STATICI18N_ROOT = "imagesgallery/public/js"
STATICI18N_OUTPUT_DIR = "translations"

# XBlock settings
IMAGES_GALLERY_SITE_CONFIGURATION_BACKEND = "imagesgallery.edxapp_wrapper.backends.site_configuration_r_v1"
IMAGES_GALLERY_CONTENTSTORE_BACKEND = "imagesgallery.edxapp_wrapper.backends.contentstore_r_v1"
6 changes: 2 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
It eases running django related commands with the correct settings already
imported.
"""

import os
import sys

from django.core.management import execute_from_command_line

if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"imagesgallery.locale.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "imagesgallery.settings.test")

execute_from_command_line(sys.argv)
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edx-i18n-tools
Mako
XBlock
xblock-utils
edx-opaque-keys
Loading

0 comments on commit 569c698

Please sign in to comment.