diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3c908e6..6a12cf1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,14 @@ 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' +* Added attributesField to every Form plugin for customizing + +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..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,19 +108,24 @@ 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, "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( { diff --git a/djangocms_form_builder/attributes.py b/djangocms_form_builder/attributes.py new file mode 100644 index 0000000..95c4bce --- /dev/null +++ b/djangocms_form_builder/attributes.py @@ -0,0 +1,28 @@ +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 bf69262..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" @@ -69,7 +70,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/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 = {} 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,