Skip to content

Commit

Permalink
Add submit message action
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 7, 2025
1 parent 5276a4f commit f7d5755
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
exclude:
- python-version: 3.9
requirements-file: dj50_cms41.txt
- python-version: 3.9
requirements-file: dj51_cms41.txt

steps:
- uses: actions/checkout@v3
Expand Down
25 changes: 25 additions & 0 deletions djangocms_form_builder/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.utils.translation import gettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLFormField
from entangled.forms import EntangledModelFormMixin

from . import models
Expand Down Expand Up @@ -219,3 +220,27 @@ def execute(self, form, request):
fail_silently=True,
html_message=html_message,
)


@register
class SubmitMessageAction(FormAction):
verbose_name = _("Submit message")

class Meta:
entangled_fields = {
"action_parameters": [
"submitmessage_message",
]
}

submitmessage_message = HTMLFormField(
label=_("Message"),
required=True,
initial=_("<p>Thank you for your submission.</p>"),
)

def execute(self, form, request):
message = self.get_parameter(form, "submitmessage_message")
form.get_success_context = lambda *args, **kwargs: {"message": message}
form.Meta.options["render_success"] = "djangocms_form_builder/actions/submit_message.html"
form.Meta.options["redirect"] = None
8 changes: 8 additions & 0 deletions djangocms_form_builder/cms_plugins/ajax_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def form_valid(self, form):
if hasattr(form, get_success_context):
get_success_context = getattr(form, get_success_context)
context.update(get_success_context(self.request, self.instance, form))
print(context)
errors, result, redir, content = (
[],
context.get("result", "success"),
Expand All @@ -108,6 +109,13 @@ def form_valid(self, form):
"",
)
redirect = redirect or redir
print( {

Check failure on line 112 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

whitespace after '('

Check failure on line 112 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

whitespace after '('
"result": result,

Check failure on line 113 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line over-indented for hanging indent

Check failure on line 113 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line over-indented for hanging indent
"redirect": redirect,
"errors": errors,
"field_errors": {},
"content": content,
})

Check failure on line 118 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line under-indented for hanging indent

Check failure on line 118 in djangocms_form_builder/cms_plugins/ajax_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line under-indented for hanging indent
return JsonResponse(
{
"result": result,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ message|safe }}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@
if ('redirect' in data) {
if (data.redirect !== '' && data.redirect !== 'result') {
window.location.href = data.redirect;
} else
} else if (data.redirect !== '') {
window.location.reload();
}
}
}

Expand Down

0 comments on commit f7d5755

Please sign in to comment.