|
1 | 1 | from cms.app_base import CMSAppConfig |
2 | 2 | from django.apps import apps |
3 | 3 | from django.conf import settings |
| 4 | +from django.db import OperationalError |
4 | 5 |
|
5 | 6 | from .models import PostContent |
6 | 7 | from .views import ToolbarDetailView |
@@ -45,15 +46,22 @@ def cms_wizards(self): |
45 | 46 | from .cms_appconfig import StoriesConfig |
46 | 47 | from .cms_wizards import PostWizard, PostWizardForm |
47 | 48 |
|
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 [] |
59 | 66 |
|
| 67 | + return lazy(generator, list)() |
0 commit comments