Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated some bugs and enhancements #8

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
12 changes: 9 additions & 3 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,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(
{
Expand Down
28 changes: 28 additions & 0 deletions djangocms_form_builder/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.utils.translation import gettext_lazy as _
from djangocms_frontend.helpers import insert_fields
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not assume django CMS frontend is installed.



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 17 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
)
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -69,7 +70,6 @@ class CharFieldPlugin(mixin_factory("CharField"), FormElementPlugin):
name = _("Text")
model = models.CharField
form = forms.CharFieldForm
settings_fields = (("min_length", "max_length"),)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove min_length and max_length? aren't they potentially needed for form validation?



@plugin_pool.register_plugin
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
10 changes: 9 additions & 1 deletion djangocms_form_builder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather ask you to set this in your settings. It will first try to take DJANGO_FORM_BUILDER_SPACER_CHOICES then take django CMS frontend's settings if available.

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,
Expand Down
Loading