Skip to content

Commit

Permalink
fix Ctrl+Z
Browse files Browse the repository at this point in the history
  • Loading branch information
pix666 committed Dec 12, 2023
1 parent b660960 commit 13827b1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- Added support for Python 3.12.
- Added support for Django 5.0.

### Bug Fixes

- The behavior of `Ctrl+Z` has been fixed when executing management commands.

## [0.17.1](https://github.com/dldevinc/paper-streamfield/tree/v0.17.1) - 2023-11-07

### Features
Expand Down
6 changes: 3 additions & 3 deletions paper_uploads/management/commands/clean_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _clean_invalid_content_types(self, model: Type[Collection]):
default=None
)

if action == "Exit":
if action is None or action == "Exit":
raise ExitException

if action == "Print":
Expand Down Expand Up @@ -292,7 +292,7 @@ def _clean_model_ownership(self, model: Type[BacklinkModelMixin]):
default=None
)

if action == "Exit":
if action is None or action == "Exit":
raise ExitException

if action == "Print":
Expand Down Expand Up @@ -374,7 +374,7 @@ def _clean_file_existence(self, model: Type[FileResource]):
default=None
)

if action == "Exit":
if action is None or action == "Exit":
raise ExitException

if action == "Print":
Expand Down
10 changes: 5 additions & 5 deletions paper_uploads/management/commands/recreate_variations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_model(self):
predicate=lambda model: utils.includes_variations(model),
)

if model_name == "[Exit]":
if model_name is None or model_name == "[Exit]":
raise ExitException

self._model = apps.get_model(model_name)
Expand All @@ -137,7 +137,7 @@ def get_collection_field(self):
append_choices=["[Back]", "[Exit]"]
)

if item_type == "[Exit]":
if item_type is None or item_type == "[Exit]":
raise ExitException

if item_type == "[Back]":
Expand All @@ -156,7 +156,7 @@ def get_resource_field(self):
append_choices=["[Back]", "[Exit]"]
)

if field_name == "[Exit]":
if field_name is None or field_name == "[Exit]":
raise ExitException

if field_name == "[Back]":
Expand All @@ -177,7 +177,7 @@ def get_collection_variations(self):
append_choices=["[Back]", "[Exit]"]
)

if "[Exit]" in variations:
if variations is None or "[Exit]" in variations:
raise ExitException

if "[Back]" in variations:
Expand All @@ -202,7 +202,7 @@ def get_resource_variations(self):
append_choices=["[Back]", "[Exit]"]
)

if "[Exit]" in variations:
if variations is None or "[Exit]" in variations:
raise ExitException

if "[Back]" in variations:
Expand Down
10 changes: 5 additions & 5 deletions paper_uploads/management/commands/remove_variations.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_model(self):
predicate=lambda model: utils.includes_variations(model),
)

if model_name == "[Exit]":
if model_name is None or model_name == "[Exit]":
raise ExitException

self._model = apps.get_model(model_name)
Expand All @@ -132,7 +132,7 @@ def get_collection_field(self):
append_choices=["[Back]", "[Exit]"]
)

if item_type == "[Exit]":
if item_type is None or item_type == "[Exit]":
raise ExitException

if item_type == "[Back]":
Expand All @@ -151,7 +151,7 @@ def get_resource_field(self):
append_choices=["[Back]", "[Exit]"]
)

if field_name == "[Exit]":
if field_name is None or field_name == "[Exit]":
raise ExitException

if field_name == "[Back]":
Expand All @@ -172,7 +172,7 @@ def get_collection_variations(self):
append_choices=["[Back]", "[Exit]"]
)

if "[Exit]" in variations:
if variations is None or "[Exit]" in variations:
raise ExitException

if "[Back]" in variations:
Expand All @@ -197,7 +197,7 @@ def get_resource_variations(self):
append_choices=["[Back]", "[Exit]"]
)

if "[Exit]" in variations:
if variations is None or "[Exit]" in variations:
raise ExitException

if "[Back]" in variations:
Expand Down
14 changes: 11 additions & 3 deletions paper_uploads/management/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,20 @@ def select_resource_model(
from paper_uploads.management import utils
model = select_resource_model()
if utils.is_collection(model):
if model is None:
print("Cancelled by user")
elif utils.is_collection(model):
item_type = select_collection_item_type(model)
variation_name = select_collection_variations(model, item_type)
if item_type is None:
print("Cancelled by user")
else:
variation_name = select_collection_variations(model, item_type)
else:
field_name = select_resource_field(model)
variation_name = select_resource_variations(model, field_name)
if field_name is None:
print("Cancelled by user")
else:
variation_name = select_resource_variations(model, field_name)
"""
choices_data = []
for model in apps.get_models():
Expand Down
19 changes: 12 additions & 7 deletions paper_uploads/management/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def prompt_action(message, choices, **kwargs):
if action == "Run script":
...
elif action == "Exit":
elif action is None or action == "Exit":
...
"""
default = kwargs.pop("default")
kwargs.setdefault("carousel", True)

return inquirer.prompt(
result = inquirer.prompt(
[
inquirer.List(
"answer",
Expand All @@ -87,7 +87,8 @@ def prompt_action(message, choices, **kwargs):
)
],
render=CustomConsoleRender()
)["answer"]
)
return result["answer"] if result is not None else None


def prompt_variants(message, choices, **kwargs):
Expand All @@ -100,9 +101,9 @@ def prompt_variants(message, choices, **kwargs):
choices=["Apple", "Banana", ""]
)
if "Apple" in actions:
if actions is None or "Exit" in actions:
...
elif "Exit" in actions:
elif "Apple" in actions:
...
"""
default = kwargs.pop("default")
Expand All @@ -112,7 +113,7 @@ def prompt_variants(message, choices, **kwargs):
kwargs.setdefault("carousel", True)

while True:
answer = inquirer.prompt(
result = inquirer.prompt(
[
inquirer.Checkbox(
"answer",
Expand All @@ -123,7 +124,11 @@ def prompt_variants(message, choices, **kwargs):
)
],
render=CustomConsoleRender()
)["answer"]
)

if result is None:
return None

answer = result["answer"]
if answer:
return answer

0 comments on commit 13827b1

Please sign in to comment.