Skip to content

Commit a148fff

Browse files
adds advanced settins with own attributes; TODO migration file and renderin in template
1 parent cb1a682 commit a148fff

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

djangocms_form_builder/actions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def get_action_class(action):
5757

5858
class ActionMixin:
5959
"""Adds action form elements to Form plugin admin"""
60+
6061
def get_form(self, request, *args, **kwargs):
6162
"""Creates new form class based adding the actions as mixins"""
6263
return type(
@@ -107,13 +108,13 @@ class SaveToDBAction(FormAction):
107108
verbose_name = _("Save form submission")
108109

109110
def execute(self, form, request):
110-
111-
form_user = None
112-
if request.user.is_authenticated:
113-
form_user = request.user
114111

115-
if get_option(form, "unique", False) and get_option(
116-
form, "login_required", False
112+
form_user = None
113+
if request.user.is_authenticated:
114+
form_user = request.user
115+
116+
if get_option(form, "unique", False) and get_option(
117+
form, "login_required", False
117118
):
118119
keys = {
119120
"form_name": get_option(form, "form_name"),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from django.utils.translation import gettext_lazy as _
2+
3+
from djangocms_frontend.helpers import insert_fields
4+
5+
6+
class AttributesMixin:
7+
block_attr = {
8+
"description": _(
9+
"Advanced settings lets you add html attributes to render this element. Use them wisely and rarely."
10+
),
11+
"classes": (
12+
"collapse",
13+
"attributes",
14+
),
15+
}
16+
17+
def get_fieldsets(self, request, obj=None):
18+
meta = self.form._meta
19+
fields = (
20+
[]
21+
)
22+
fields.append("attributes")
23+
return insert_fields(
24+
super().get_fieldsets(request, obj),
25+
fields,
26+
blockname=_("Advanced settings"),
27+
blockattrs=self.block_attr,
28+
position=-1, # Always last
29+
)

djangocms_form_builder/cms_plugins/form_plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
from .. import forms
77
from .. import forms as forms_module
88
from .. import models, settings
9+
from ..attributes import AttributesMixin
910
from ..helpers import add_plugin, delete_plugin, insert_fields
1011
from .ajax_plugins import FormPlugin
1112

1213
mixin_factory = settings.get_renderer(forms_module)
1314

1415

15-
class FormElementPlugin(CMSPluginBase):
16+
class FormElementPlugin(AttributesMixin, CMSPluginBase):
1617
top_element = FormPlugin.__name__
1718
module = _("Forms")
1819
render_template = f"djangocms_form_builder/{settings.framework}/widgets/base.html"

djangocms_form_builder/entry_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from django.utils.translation import gettext_lazy as _
88
from entangled.forms import EntangledModelForm
99

10+
from .fields import AttributesField
11+
1012

1113
class CSValues(forms.CharField):
1214
class CSVWidget(forms.TextInput):
@@ -51,6 +53,8 @@ class Meta:
5153
entry_created_at = models.DateTimeField(auto_now_add=True)
5254
entry_updated_at = models.DateTimeField(auto_now=True)
5355

56+
attributes = AttributesField()
57+
5458
def get_admin_form(self):
5559
entangled_fields = []
5660
fields = {}

0 commit comments

Comments
 (0)