Skip to content

Commit

Permalink
adds advanced settins with own attributes; TODO migration file and re…
Browse files Browse the repository at this point in the history
…nderin in template
  • Loading branch information
svandeneertwegh committed Sep 23, 2023
1 parent cb1a682 commit a148fff
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
13 changes: 7 additions & 6 deletions djangocms_form_builder/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def get_action_class(action):

class ActionMixin:
"""Adds action form elements to Form plugin admin"""

def get_form(self, request, *args, **kwargs):
"""Creates new form class based adding the actions as mixins"""
return type(
Expand Down Expand Up @@ -107,13 +108,13 @@ class SaveToDBAction(FormAction):
verbose_name = _("Save form submission")

def execute(self, form, request):

form_user = None
if request.user.is_authenticated:
form_user = request.user

if get_option(form, "unique", False) and get_option(
form, "login_required", False
form_user = None
if request.user.is_authenticated:
form_user = request.user

if get_option(form, "unique", False) and get_option(
form, "login_required", False
):
keys = {
"form_name": get_option(form, "form_name"),
Expand Down
29 changes: 29 additions & 0 deletions djangocms_form_builder/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.utils.translation import gettext_lazy as _

Check failure on line 1 in djangocms_form_builder/attributes.py

View workflow job for this annotation

GitHub Actions / isort

Imports are incorrectly sorted and/or formatted.

from djangocms_frontend.helpers import insert_fields


class AttributesMixin:
block_attr = {
"description": _(
"Advanced settings lets you add html attributes to render this element. Use them wisely and rarely."
),
"classes": (
"collapse",
"attributes",
),
}

def get_fieldsets(self, request, obj=None):
meta = self.form._meta

Check failure on line 18 in djangocms_form_builder/attributes.py

View workflow job for this annotation

GitHub Actions / flake8

local variable 'meta' is assigned to but never used
fields = (
[]
)
fields.append("attributes")
return insert_fields(
super().get_fieldsets(request, obj),
fields,
blockname=_("Advanced settings"),
blockattrs=self.block_attr,
position=-1, # Always last
)
3 changes: 2 additions & 1 deletion djangocms_form_builder/cms_plugins/form_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from .. import forms
from .. import forms as forms_module
from .. import models, settings
from ..attributes import AttributesMixin
from ..helpers import add_plugin, delete_plugin, insert_fields
from .ajax_plugins import FormPlugin

mixin_factory = settings.get_renderer(forms_module)


class FormElementPlugin(CMSPluginBase):
class FormElementPlugin(AttributesMixin, CMSPluginBase):
top_element = FormPlugin.__name__
module = _("Forms")
render_template = f"djangocms_form_builder/{settings.framework}/widgets/base.html"
Expand Down
4 changes: 4 additions & 0 deletions djangocms_form_builder/entry_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils.translation import gettext_lazy as _
from entangled.forms import EntangledModelForm

from .fields import AttributesField


class CSValues(forms.CharField):
class CSVWidget(forms.TextInput):
Expand Down Expand Up @@ -51,6 +53,8 @@ class Meta:
entry_created_at = models.DateTimeField(auto_now_add=True)
entry_updated_at = models.DateTimeField(auto_now=True)

attributes = AttributesField()

def get_admin_form(self):
entangled_fields = []
fields = {}
Expand Down

0 comments on commit a148fff

Please sign in to comment.