Skip to content

Commit 78fd62b

Browse files
committed
fix: Lazy cms_wizards
1 parent b6c6d49 commit 78fd62b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

djangocms_stories/cms_config.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from cms.app_base import CMSAppConfig
22
from django.apps import apps
33
from django.conf import settings
4+
from django.db import OperationalError
45

56
from .models import PostContent
67
from .views import ToolbarDetailView
@@ -45,15 +46,22 @@ def cms_wizards(self):
4546
from .cms_appconfig import StoriesConfig
4647
from .cms_wizards import PostWizard, PostWizardForm
4748

48-
for item, config in enumerate(StoriesConfig.objects.all().order_by("namespace"), start=1):
49-
seed = f"Story{item}Wizard"
50-
new_wizard = type(str(seed), (PostWizard,), {})
51-
new_form = type("{}Form".format(seed), (PostWizardForm,), {"default_appconfig": config.pk})
52-
yield new_wizard(
53-
title=lazy(lambda config=config: gettext("New {0}").format(config.object_name), str)(),
54-
weight=200,
55-
form=new_form,
56-
model=PostContent,
57-
description=lazy(lambda config=config: gettext("Create a new {0} in {1}").format(config.object_name, config.app_title), str)(),
58-
)
49+
def generator():
50+
try:
51+
for item, config in enumerate(StoriesConfig.objects.all().order_by("namespace"), start=1):
52+
seed = f"Story{item}Wizard"
53+
new_wizard = type(str(seed), (PostWizard,), {})
54+
new_form = type("{}Form".format(seed), (PostWizardForm,), {"default_appconfig": config.pk})
55+
yield new_wizard(
56+
title=lazy(lambda config=config: gettext("New {0}").format(config.object_name), str)(),
57+
weight=200,
58+
form=new_form,
59+
model=PostContent,
60+
description=lazy(lambda config=config: gettext("Create a new {0} in {1}").format(config.object_name, config.app_title), str)(),
61+
)
62+
except OperationalError:
63+
# This can happen if, e.g., migrations have not been executed yet.
64+
# In that case, we return an empty list.
65+
return []
5966

67+
return lazy(generator, list)()

djangocms_stories/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from parler.forms import TranslatableModelForm
77
from taggit_autosuggest.widgets import TagAutoSuggest
88

9-
from .models import PostCategory, PostContent, StoriesConfig, Post
10-
from .settings import PERMALINK_TYPE_CATEGORY, get_setting
9+
from .models import PostCategory, StoriesConfig
10+
from .settings import get_setting
1111

1212
User = get_user_model()
1313

0 commit comments

Comments
 (0)