From c45a2841ab87ee03dc00fa5988ee7f20a28b10a9 Mon Sep 17 00:00:00 2001 From: Stefan van den Eertwegh Date: Sat, 23 Sep 2023 09:03:40 +0200 Subject: [PATCH 1/4] bugfix on charfield, margin list filled --- djangocms_form_builder/cms_plugins/form_plugins.py | 1 - djangocms_form_builder/settings.py | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/djangocms_form_builder/cms_plugins/form_plugins.py b/djangocms_form_builder/cms_plugins/form_plugins.py index bf69262..4dfb355 100644 --- a/djangocms_form_builder/cms_plugins/form_plugins.py +++ b/djangocms_form_builder/cms_plugins/form_plugins.py @@ -69,7 +69,6 @@ class CharFieldPlugin(mixin_factory("CharField"), FormElementPlugin): name = _("Text") model = models.CharField form = forms.CharFieldForm - settings_fields = (("min_length", "max_length"),) @plugin_pool.register_plugin diff --git a/djangocms_form_builder/settings.py b/djangocms_form_builder/settings.py index d62aa53..30e29dd 100644 --- a/djangocms_form_builder/settings.py +++ b/djangocms_form_builder/settings.py @@ -20,7 +20,15 @@ framework = getattr(django_settings, "DJANGOCMS_FRONTEND_FRAMEWORK", "bootstrap5") theme = getattr(django_settings, "DJANGOCMS_FRONTEND_THEME", "djangocms_frontend") -DEFAULT_SPACER_SIZE_CHOICES = (("mb-3", "Default"),) +DEFAULT_SPACER_SIZE_CHOICES = ( + ('', 'no margin set'), + ('mb-1', 'mb-1'), + ('mb-2', 'mb-2'), + ('mb-3', 'mb-3 (default)'), + ('mb-4', 'mb-4'), + ('mb-5', 'mb-5'), +) + TAG_CHOICES = (("div", "div"),) FORM_TEMPLATE = getattr( django_settings, From cb1a6826826aa28e431407603aef87e54f3aad2f Mon Sep 17 00:00:00 2001 From: Stefan van den Eertwegh Date: Sat, 23 Sep 2023 09:43:21 +0200 Subject: [PATCH 2/4] Fixed anonymous as None to Foregin key 'form_user' --- CHANGELOG.rst | 8 +++++++- djangocms_form_builder/actions.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3c908e6..1a7f43c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,13 @@ Changelog ========= -0.1.0 (unreleased) +0.2.0 (unreleased) +================= +* Removed col and rows setting from CharField form plugin +* Set more margin options in spacing between fields +* Fixed anonymous as None to Foregin key 'form_user' + +0.1.0 ================== * Set ``default_auto_field`` to ``BigAutoField`` to ensure projects don't try to create a migration if they still use ``AutoField`` diff --git a/djangocms_form_builder/actions.py b/djangocms_form_builder/actions.py index 6f4790d..5feae40 100644 --- a/djangocms_form_builder/actions.py +++ b/djangocms_form_builder/actions.py @@ -107,19 +107,24 @@ class SaveToDBAction(FormAction): verbose_name = _("Save form submission") def execute(self, form, request): - if get_option(form, "unique", False) and get_option( + + 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"), - "form_user": request.user, + "form_user": form_user, } defaults = {} else: keys = {} defaults = { "form_name": get_option(form, "form_name"), - "form_user": request.user, + "form_user": form_user, } defaults.update( { From a148fff9eda17976371f99491accb6108ee55dd9 Mon Sep 17 00:00:00 2001 From: Stefan van den Eertwegh Date: Sat, 23 Sep 2023 12:56:25 +0200 Subject: [PATCH 3/4] adds advanced settins with own attributes; TODO migration file and renderin in template --- djangocms_form_builder/actions.py | 13 +++++---- djangocms_form_builder/attributes.py | 29 +++++++++++++++++++ .../cms_plugins/form_plugins.py | 3 +- djangocms_form_builder/entry_model.py | 4 +++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 djangocms_form_builder/attributes.py diff --git a/djangocms_form_builder/actions.py b/djangocms_form_builder/actions.py index 5feae40..01de9c4 100644 --- a/djangocms_form_builder/actions.py +++ b/djangocms_form_builder/actions.py @@ -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( @@ -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"), diff --git a/djangocms_form_builder/attributes.py b/djangocms_form_builder/attributes.py new file mode 100644 index 0000000..96d3d06 --- /dev/null +++ b/djangocms_form_builder/attributes.py @@ -0,0 +1,29 @@ +from django.utils.translation import gettext_lazy as _ + +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 + fields = ( + [] + ) + fields.append("attributes") + return insert_fields( + super().get_fieldsets(request, obj), + fields, + blockname=_("Advanced settings"), + blockattrs=self.block_attr, + position=-1, # Always last + ) diff --git a/djangocms_form_builder/cms_plugins/form_plugins.py b/djangocms_form_builder/cms_plugins/form_plugins.py index 4dfb355..12514b2 100644 --- a/djangocms_form_builder/cms_plugins/form_plugins.py +++ b/djangocms_form_builder/cms_plugins/form_plugins.py @@ -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" diff --git a/djangocms_form_builder/entry_model.py b/djangocms_form_builder/entry_model.py index fea63a4..6efcccb 100644 --- a/djangocms_form_builder/entry_model.py +++ b/djangocms_form_builder/entry_model.py @@ -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): @@ -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 = {} From 16d3ac64c0b6ef1fb147a2490b1aa22fda845def Mon Sep 17 00:00:00 2001 From: Stefan van den Eertwegh Date: Sat, 23 Sep 2023 13:07:20 +0200 Subject: [PATCH 4/4] ran isort + modified CHANGELOG --- CHANGELOG.rst | 1 + djangocms_form_builder/attributes.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1a7f43c..6a12cf1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ Changelog * Removed col and rows setting from CharField form plugin * Set more margin options in spacing between fields * Fixed anonymous as None to Foregin key 'form_user' +* Added attributesField to every Form plugin for customizing 0.1.0 ================== diff --git a/djangocms_form_builder/attributes.py b/djangocms_form_builder/attributes.py index 96d3d06..95c4bce 100644 --- a/djangocms_form_builder/attributes.py +++ b/djangocms_form_builder/attributes.py @@ -1,5 +1,4 @@ from django.utils.translation import gettext_lazy as _ - from djangocms_frontend.helpers import insert_fields