-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19529 fix CLI running of scripts #19698
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
17cecb0
19529 fix custom script path
arthanson 39d7ca4
19529 fix custom script path
arthanson 2ece669
19529 fix custom script path
arthanson 24b1cb9
19529 fix custom script path
arthanson 2a4ba5b
19680 add object_change migrator
arthanson ee873d9
19680 optimize migration
arthanson a6bbc0b
19680 optimize migration
arthanson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from django.conf import settings | ||
| from django.core.files.storage import storages | ||
| from django.db import migrations | ||
| from urllib.parse import urlparse | ||
|
|
||
| from extras.storage import ScriptFileSystemStorage | ||
|
|
||
|
|
||
| def normalize(url): | ||
| parsed_url = urlparse(url) | ||
| if not parsed_url.path.endswith('/'): | ||
| return url + '/' | ||
| return url | ||
|
|
||
|
|
||
| def fix_script_paths(apps, schema_editor): | ||
| """ | ||
| Fix script paths for scripts that had incorrect path from NB 4.3. | ||
| """ | ||
| storage = storages.create_storage(storages.backends["scripts"]) | ||
| if not isinstance(storage, ScriptFileSystemStorage): | ||
| return | ||
|
|
||
| ScriptModule = apps.get_model('extras', 'ScriptModule') | ||
| script_root_path = normalize(settings.SCRIPTS_ROOT) | ||
| for script in ScriptModule.objects.filter(file_path__startswith=script_root_path): | ||
| script.file_path = script.file_path[len(script_root_path):] | ||
| script.save() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('extras', '0128_tableconfig'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(code=fix_script_paths, reverse_code=migrations.RunPython.noop), | ||
| ] | ||
|
|
||
|
|
||
| def oc_fix_script_paths(objectchange, reverting): | ||
| script_root_path = normalize(settings.SCRIPTS_ROOT) | ||
|
|
||
| for data in (objectchange.prechange_data, objectchange.postchange_data): | ||
| if data is None: | ||
| continue | ||
|
|
||
| if file_path := data.get('file_path'): | ||
| if file_path.startswith(script_root_path): | ||
| data['file_path'] = file_path[len(script_root_path):] | ||
|
|
||
|
|
||
| objectchange_migrators = { | ||
| 'extras.scriptmodule': oc_fix_script_paths, | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.