Skip to content

Commit 793f669

Browse files
committed
Fix: No Form plugin within Form plugin
1 parent 802ddfb commit 793f669

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

djangocms_form_builder/cms_plugins/ajax_plugins.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ def form_valid(self, form):
8686
get_option(form, render_success), context.flatten(), self.request
8787
),
8888
)
89-
else:
89+
elif redirect:
9090
errors, result, redir, content = (
9191
[],
9292
"success",
93-
redirect or "",
93+
redirect,
94+
"",
95+
)
96+
else:
97+
errors, result, redir, content = (
98+
[_("No content in response from")],
99+
"error",
100+
"",
94101
"",
95102
)
96103
redirect = redirect or redir
@@ -238,8 +245,8 @@ def render(self, context, instance, placeholder):
238245
class FormPlugin(CMSAjaxForm):
239246
name = _("Form")
240247
model = models.Form
241-
form = forms.FormsForm
242248

249+
# form = forms.FormsForm
243250
render_template = f"djangocms_form_builder/{settings.framework}/form.html"
244251
change_form_template = "djangocms_frontend/admin/base.html"
245252
allow_children = True
@@ -269,15 +276,17 @@ class FormPlugin(CMSAjaxForm):
269276
),
270277
]
271278

272-
# @classmethod
273-
# def get_parent_classes(cls, slot, page, instance=None): # TODO Should avoid nested forms -> not working
274-
# """Only valid if not inside form"""
275-
# parent = instance
276-
# while parent is not None:
277-
# if parent.plugin_type == FormPlugin.__name__:
278-
# return [""]
279-
# parent = parent.parent
280-
# return super().get_parent_classes(slot, page, instance)
279+
cache_parent_classes = False
280+
281+
@classmethod
282+
def get_parent_classes(cls, slot, page, instance=None):
283+
"""Only valid if not inside form"""
284+
parent = instance
285+
while parent is not None:
286+
if parent.plugin_type == FormPlugin.__name__:
287+
return [""]
288+
parent = parent.parent
289+
return super().get_parent_classes(slot, page, instance)
281290

282291
def get_fieldsets(self, request, obj=None):
283292
if recaptcha.installed:
@@ -311,28 +320,7 @@ def get_form_class(self, slug=None):
311320
if self.instance.child_plugin_instances:
312321
return self.create_form_class_from_plugins()
313322
if self.instance.form_selection:
314-
form_class = forms._form_registry.get(self.instance.form_selection, None)
315-
if form_class:
316-
# add options from form admin - if the form_class does not already set them
317-
additional_options = dict(
318-
floating_labels=self.instance.form_floating_labels,
319-
field_sep=self.instance.form_spacing,
320-
login_required=self.instance.form_login_required,
321-
unique=self.instance.form_unique,
322-
form_actions=self.instance.form_actions,
323-
)
324-
if hasattr(form_class, "Meta"):
325-
options = getattr(
326-
form_class.Meta,
327-
"_original_options",
328-
getattr(form_class.Meta, "options", {})
329-
)
330-
form_class.Meta._original_options = options # store original options settings
331-
additional_options.update(options) # apply them to the form admin's option
332-
form_class.Meta.options = additional_options # use them
333-
else:
334-
form_class.Meta = type("Meta", (), dict(options=additional_options))
335-
return form_class
323+
return forms._form_registry.get(self.instance.form_selection, None)
336324
return None
337325

338326
def create_form_class_from_plugins(self):

0 commit comments

Comments
 (0)