Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 10, 2023
1 parent 5ab8917 commit b7678b3
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 18 deletions.
Empty file.
12 changes: 12 additions & 0 deletions examples/simple/kitchen_sink/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import forms


class KitchenSinkForm(forms.Form):
choices = forms.MultipleChoiceField(
choices=[
("a", "A"),
("b", "B"),
("c", "C"),
],
widget=forms.CheckboxSelectMultiple,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{{ message }}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
</body>
</html>
6 changes: 6 additions & 0 deletions examples/simple/kitchen_sink/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from .views import KitchenSinkFormView

urlpatterns = [
path("", KitchenSinkFormView.as_view(), name="kitchen_sink"),
]
12 changes: 12 additions & 0 deletions examples/simple/kitchen_sink/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.views.generic.edit import FormView
from django.urls import reverse, reverse_lazy

from .forms import KitchenSinkForm


class KitchenSinkFormView(FormView):
template_name = "kitchen_sink/kitchen_sink.html"
form_class = KitchenSinkForm

def get_success_url(self):
return f"{reverse('kitchen_sink')}?success"
1 change: 1 addition & 0 deletions examples/simple/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def gettext(s):
# ***********************************************************************
# Other project specific apps
"foo", # Test app
"kitchen_sink", # Test app
]

STATIC_ROOT = PROJECT_DIR(os.path.join("..", "..", "static"))
Expand Down
1 change: 1 addition & 0 deletions examples/simple/urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .class_based import *
# from .function_based import *
1 change: 1 addition & 0 deletions examples/simple/urls/class_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
url(r"^foo/", include("foo.urls")),
# bar URLs:
# url(r'^bar/', include('bar.urls')),
url(r"^kitchen-sink/", include("kitchen_sink.urls")),
url(r"^$", TemplateView.as_view(template_name=fobi_home_template)),
# django-fobi public forms contrib app:
# url(r'^', include('fobi.contrib.apps.public_forms.urls')),
Expand Down
7 changes: 5 additions & 2 deletions src/fobi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3149,16 +3149,19 @@ def get_ignorable_form_fields(form_element_entries):
# *****************************************************************************


def get_cleaned_data(form, keys_to_remove=[], values_to_remove=[]):
def get_cleaned_data(form, keys_to_remove=None, values_to_remove=None):
"""Get cleaned data.
Gets cleaned data, having the trash (fields without values) filtered
out.
:param form:
:param iterable keys_to_remove:
:param iterable values_to_remove:
:return dict:
"""
if not keys_to_remove:
keys_to_remove = []
if not values_to_remove:
values_to_remove = get_ignorable_form_values()

Expand All @@ -3177,7 +3180,7 @@ def get_cleaned_data(form, keys_to_remove=[], values_to_remove=[]):
return ordered_cleaned_data


def get_field_name_to_label_map(form, keys_to_remove=[], values_to_remove=[]):
def get_field_name_to_label_map(form, keys_to_remove=None, values_to_remove=None):
"""Get field name to label map.
:param form:
Expand Down
6 changes: 4 additions & 2 deletions src/fobi/contrib/apps/drf_integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def get_processed_serializer_data(serializer, form_element_entries):


def get_field_name_to_label_map(
serializer, keys_to_remove=[], values_to_remove=[]
serializer, keys_to_remove=None, values_to_remove=None
):
"""Get field name to label map.
Expand All @@ -290,7 +290,7 @@ def get_field_name_to_label_map(
return field_name_to_label_map


def get_cleaned_data(serializer, keys_to_remove=[], values_to_remove=[]):
def get_cleaned_data(serializer, keys_to_remove=None, values_to_remove=None):
"""Get cleaned data.
Gets cleaned data, having the trash (fields without values) filtered
Expand All @@ -301,6 +301,8 @@ def get_cleaned_data(serializer, keys_to_remove=[], values_to_remove=[]):
:param iterable values_to_remove:
:return dict:
"""
if not keys_to_remove:
keys_to_remove = []
if not values_to_remove:
values_to_remove = get_ignorable_form_values()

Expand Down
10 changes: 8 additions & 2 deletions src/fobi/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ def map_field_name_to_label(form):
)


def clean_dict(source, keys=[], values=[]):
def clean_dict(source, keys=None, values=None):
"""Removes given keys and values from dictionary.
:param dict source:
:param iterable keys:
:param iterable values:
:return dict:
"""
if not keys:
keys = []
if not values:
values = []
dict_data = {}
for key, value in source.items():
if (key not in keys) and (value not in values):
Expand Down Expand Up @@ -338,13 +342,15 @@ def extract_file_path(name):
# *****************************************************************************


def get_registered_models(ignore=[]):
def get_registered_models(ignore=None):
"""Gets registered models as list.
:param iterable ignore: Ignore the following content types (should
be in ``app_label.model`` format (example ``auth.User``).
:return list:
"""
if not ignore:
ignore = []
get_models = django.apps.apps.get_models

registered_models = [
Expand Down
12 changes: 7 additions & 5 deletions src/fobi/templatetags/fobi_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ class FormFieldType(object):
is_radio = False
is_textarea = False

def __init__(self, properties=[]):
def __init__(self, properties=None):
"""Constructor.
By default all of them are false. Provide only property
names that should be set to True.
"""
if not properties:
properties = []
for prop in properties:
setattr(self, prop, True)

Expand All @@ -434,13 +436,13 @@ def render(self, context):
field = self.field.resolve(context, True)
properties = []

if isinstance(field.field.widget, forms.CheckboxInput):
properties.append("is_checkbox")

if isinstance(field.field.widget, forms.CheckboxSelectMultiple):
properties.append("is_checkbox_multiple")

if isinstance(field.field.widget, forms.RadioSelect):
elif isinstance(field.field.widget, forms.CheckboxInput):
properties.append("is_checkbox")

elif isinstance(field.field.widget, forms.RadioSelect):
properties.append("is_radio")

res = FormFieldType(properties)
Expand Down
16 changes: 12 additions & 4 deletions src/fobi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_user_handler_plugins(
handler_plugin_registry,
user,
exclude_used_singles=False,
used_handler_plugin_uids=[],
used_handler_plugin_uids=None,
):
"""Get list of plugins allowed for user.
Expand All @@ -313,6 +313,8 @@ def get_user_handler_plugins(
:param list used_handler_plugin_uids:
:return list:
"""
if not used_handler_plugin_uids:
used_handler_plugin_uids = []
user_handler_plugins = get_user_plugins(
get_allowed_handler_plugin_uids,
get_registered_handler_plugins,
Expand Down Expand Up @@ -410,7 +412,7 @@ def get_allowed_form_handler_plugin_uids(user):


def get_user_form_handler_plugins(
user, exclude_used_singles=False, used_form_handler_plugin_uids=[]
user, exclude_used_singles=False, used_form_handler_plugin_uids=None
):
"""Get list of plugins allowed for user.
Expand All @@ -419,6 +421,8 @@ def get_user_form_handler_plugins(
:param list used_form_handler_plugin_uids:
:return list:
"""
if not used_form_handler_plugin_uids:
used_form_handler_plugin_uids = []
return get_user_handler_plugins(
get_allowed_form_handler_plugin_uids,
get_registered_form_handler_plugins,
Expand All @@ -431,14 +435,16 @@ def get_user_form_handler_plugins(

# def get_user_form_handler_plugins(user,
# exclude_used_singles=False,
# used_form_handler_plugin_uids=[]):
# used_form_handler_plugin_uids=None):
# """Get list of plugins allowed for user.
#
# :param django.contrib.auth.models.User user:
# :param bool exclude_used_singles:
# :param list used_form_handler_plugin_uids:
# :return list:
# """
# if not used_form_handler_plugin_uids:
# used_form_handler_plugin_uids = []
# user_form_handler_plugins = get_user_plugins(
# get_allowed_form_handler_plugin_uids,
# get_registered_form_handler_plugins,
Expand Down Expand Up @@ -510,7 +516,7 @@ def get_allowed_form_wizard_handler_plugin_uids(user):


def get_user_form_wizard_handler_plugins(
user, exclude_used_singles=False, used_form_wizard_handler_plugin_uids=[]
user, exclude_used_singles=False, used_form_wizard_handler_plugin_uids=None
):
"""Get list of plugins allowed for user.
Expand All @@ -519,6 +525,8 @@ def get_user_form_wizard_handler_plugins(
:param list used_form_wizard_handler_plugin_uids:
:return list:
"""
if not used_form_wizard_handler_plugin_uids:
used_form_wizard_handler_plugin_uids = []
return get_user_handler_plugins(
get_allowed_form_wizard_handler_plugin_uids,
get_registered_form_wizard_handler_plugins,
Expand Down
11 changes: 9 additions & 2 deletions src/fobi/views/class_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,10 @@ def get_template_names(self):
else:
theme = self.theme
template_name = theme.view_form_entry_template

if DEBUG:
logger.debug(f"template_name: {template_name}")

return [template_name]

def get_essential_objects(
Expand All @@ -1603,7 +1607,6 @@ def get_essential_objects(
form_element_entries=form_element_entries,
request=request,
)

return (
form_element_entries,
form_cls,
Expand Down Expand Up @@ -1670,7 +1673,7 @@ def get(self, request, *args, **kwargs):

# In debug mode, try to identify possible problems.
if DEBUG:
form.as_p()
logger.debug(form.as_p())
else:
try:
form.as_p()
Expand All @@ -1680,6 +1683,10 @@ def get(self, request, *args, **kwargs):
theme = get_theme(request=request, as_instance=True)
theme.collect_plugin_media(form_element_entries)

if DEBUG:
logger.debug(f"theme.form_view_ajax: {theme.form_view_ajax}")
logger.debug(f"theme.form_snippet_template_name: {theme.form_snippet_template_name}")

return self.render_to_response(
self.get_context_data(
form=form,
Expand Down
7 changes: 6 additions & 1 deletion src/fobi/views/function_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ def view_form_entry(request, form_entry_slug, theme=None, template_name=None):

# In debug mode, try to identify possible problems.
if DEBUG:
form.as_p()
logger.debug(form.as_p())
else:
try:
form.as_p()
Expand All @@ -2337,6 +2337,11 @@ def view_form_entry(request, form_entry_slug, theme=None, template_name=None):
if not template_name:
template_name = theme.view_form_entry_template

if DEBUG:
logger.debug(f"template_name: {template_name}")
logger.debug(f"theme.form_view_ajax: {theme.form_view_ajax}")
logger.debug(f"theme.form_snippet_template_name: {theme.form_snippet_template_name}")

return render(request, template_name, context)


Expand Down

0 comments on commit b7678b3

Please sign in to comment.