-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asset handling updates (config, admin) #234
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When you fetch a single ComponentVersion, you are often going to want to pull data related to its Component, and possibly the LearningPackage it belongs to. This commit adds a select_related call to eliminate the extra roundtrips for this information.
ormsbee
force-pushed
the
asset-integration
branch
2 times, most recently
from
September 27, 2024 03:44
2cc3ff2
to
e055898
Compare
@kdmccormick, @bradenmacdonald: I still need to add a couple of small tests, but this is the basic learning core piece of it. |
Now updated with tests. |
bradenmacdonald
approved these changes
Sep 29, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! A couple minor comments but nothing blocking.
I tested this as described here.
tests/openedx_learning/apps/authoring/contents/test_file_storage.py
Outdated
Show resolved
Hide resolved
WARNING: This commit will break any file-backed Content entries you currently have. Though you will likely only have them if you've used the very recently created add_assets_to_component command. This commit switches us away from using the default_storage and requires the project to set an OPENEDX_LEARNING settings dictionary with a MEDIA key like: OPENEDX_LEARNING = { 'MEDIA': { "BACKEND": "django.core.files.storage.FileSystemStorage", "OPTIONS": { "location": "/openedx/media-private/openedx-learning", } } } If no such setting is present, Content operations that require file access will raise a django.core.exceptions.ImproperlyConfigured error. In addition to that, Content files will be stored in a "content" subdirectory of the specified media location. This is to allow us more flexibility as we start to use file storage for other things like the import/export process. We need to have a separate space for Learning Core media files because these files should NOT be directly accessible via the browser (as the MEDIA_ROOT is). This is because of access policies and the fact that the filenames will not be meaningful by themselves and must be translated by app logic. For details, please see: * docs/decisions/0015-serving-static-assets.rst * openedx_learning/apps/authoring/contents/models.py * openedx_learning/apps/authoring/components/models.py Hiding these files in a new location also required changes to the Django admin, which are included here. This commit also adds a little extra to the admin to make it easier to map Component assets to actual files on disk. This commit also adds the following helpers to the Content model: * read_file(): return opened Django File object for the Content. * os_path(): get the full OS path to the stored file, if available. * path(): get the logical path for this asset relative to our configured OPENEDX_LEARNING['MEDIA'] storage root. This commit also auto-strips file paths starting with '/'. Allowing absolute paths tripped me up multiple times as I was setting up my test data, and I don't think there's any advantage to allowing inconsistencies (e.g. "/static/foo.png" and "static/foo.png"). We now force the relative form ("static/foo.png").
ormsbee
force-pushed
the
asset-integration
branch
from
October 2, 2024 18:23
9b2679c
to
fd83506
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this should be the last of the Learning Core changes needed to get minimal asset handling into Content Libraries.
The meat of this is:
Also includes the following performance tweak:
This will not work without the
OPENEDX_LEARNING
setting set, which will be done by default in tutor dev once overhangio/tutor#1124 lands.Screenshots: