Skip to content

Commit

Permalink
fix: import-shadowing leads to non-working form fields
Browse files Browse the repository at this point in the history
  • Loading branch information
saemideluxe committed Jan 9, 2025
1 parent 62d1dba commit 6c0dbcb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions basxbread/layout/components/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import htmlgenerator as hg
from _strptime import TimeRE
from django.conf import settings
from django.forms import widgets
from django.forms import widgets as djangowidgets
from django.urls import reverse
from django.utils import formats
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -84,7 +84,7 @@ def with_fieldwrapper(self):


class HiddenInput(BaseWidget):
django_widget = widgets.HiddenInput
django_widget = djangowidgets.HiddenInput
input_type = "hidden"

def __init__(
Expand All @@ -100,7 +100,7 @@ def __init__(


class TextInput(BaseWidget):
django_widget = widgets.TextInput
django_widget = djangowidgets.TextInput
carbon_input_class = "bx--text-input"
carbon_input_error_class = "bx--text-input--invalid"
input_type = "text"
Expand Down Expand Up @@ -166,23 +166,23 @@ def __init__(self, *args, **attributes):


class UrlInput(TextInput):
django_widget = widgets.URLInput
django_widget = djangowidgets.URLInput
input_type = "url"

def __init__(self, *args, **attributes):
super().__init__(*args, icon="link", **attributes)


class EmailInput(TextInput):
django_widget = widgets.EmailInput
django_widget = djangowidgets.EmailInput
input_type = "email"

def __init__(self, *args, **attributes):
super().__init__(*args, icon="email", **attributes)


class NumberInput(BaseWidget):
django_widget = widgets.NumberInput
django_widget = djangowidgets.NumberInput
input_type = "number"

def __init__(
Expand Down Expand Up @@ -225,12 +225,12 @@ def __init__(


class TimeInput(TextInput):
django_widget = widgets.TimeInput
django_widget = djangowidgets.TimeInput
input_type = "time"


class PasswordInput(TextInput):
django_widget = widgets.PasswordInput
django_widget = djangowidgets.PasswordInput
carbon_input_class = "bx--password-input bx--text-input"
carbon_input_error_class = "bx--text-input--invalid"
input_type = "password"
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(


class Textarea(BaseWidget):
django_widget = widgets.Textarea
django_widget = djangowidgets.Textarea
carbon_input_class = "bx--text-area bx--text-area--v2"
carbon_input_error_class = "bx--text-area--invalid"

Expand Down Expand Up @@ -327,7 +327,7 @@ def __init__(


class Select(BaseWidget):
django_widget = widgets.Select
django_widget = djangowidgets.Select
carbon_input_class = "bx--select-input"

def __init__(
Expand Down Expand Up @@ -509,11 +509,11 @@ def __init__(


class NullBooleanSelect(Select):
django_widget = widgets.NullBooleanSelect
django_widget = djangowidgets.NullBooleanSelect


class SelectMultiple(BaseWidget):
django_widget = widgets.SelectMultiple
django_widget = djangowidgets.SelectMultiple

def __init__(
self,
Expand Down Expand Up @@ -672,7 +672,7 @@ def countselected(context):


class Checkbox(BaseWidget):
django_widget = widgets.CheckboxInput
django_widget = djangowidgets.CheckboxInput
carbon_input_class = "bx--checkbox"
input_type = "checkbox"

Expand Down Expand Up @@ -727,7 +727,7 @@ def __init__(


class CheckboxSelectMultiple(BaseWidget):
django_widget = widgets.CheckboxSelectMultiple
django_widget = djangowidgets.CheckboxSelectMultiple
carbon_input_class = "bx--checkbox"
input_type = "checkbox"

Expand Down Expand Up @@ -813,7 +813,7 @@ def __init__(


class RadioSelect(BaseWidget):
django_widget = widgets.RadioSelect
django_widget = djangowidgets.RadioSelect
carbon_input_class = "bx--radio-button"
input_type = "radio"

Expand Down Expand Up @@ -862,7 +862,7 @@ def __init__(


class DatePicker(BaseWidget):
django_widget = widgets.DateInput
django_widget = djangowidgets.DateInput
carbon_input_class = "bx--date-picker__input"
input_type = "text" # prevent browser style date picker but use carbon design

Expand Down Expand Up @@ -973,7 +973,7 @@ def format_date_value(context):


class FileInput(BaseWidget):
django_widget = widgets.FileInput
django_widget = djangowidgets.FileInput
carbon_input_class = "bx--file-input bx--visually-hidden"
input_type = "file"
clearable = False
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def __init__(


class ClearableFileInput(FileInput):
django_widget = widgets.ClearableFileInput
django_widget = djangowidgets.ClearableFileInput
clearable = True


Expand Down Expand Up @@ -1228,7 +1228,7 @@ def AjaxSearch(url, formatter=str):


class MultiWidget(BaseWidget):
django_widget = widgets.MultiWidget
django_widget = djangowidgets.MultiWidget

def __init__(
self,
Expand Down Expand Up @@ -1277,10 +1277,10 @@ def subwidget(self, boundfield, djangowidget, djangodata, i):


class SplitDateTimeWidget(MultiWidget):
django_widget = widgets.SplitDateTimeWidget
django_widget = djangowidgets.SplitDateTimeWidget

def subwidget(self, boundfield, djangowidget, djangodata, i):
if isinstance(djangowidget, widgets.DateInput):
if isinstance(djangowidget, djangowidgets.DateInput):
return DatePicker(
label=None,
help_text=None,
Expand Down Expand Up @@ -1416,6 +1416,7 @@ def _optgroups_from_choices(optchoices, name, value):

def django2bread_widgetclass(widgetclass, fieldclass=None) -> Optional[hg.Lazy]:
if django2bread_widgetclass.widget_map is None: # type: ignore

django2bread_widgetclass.widget_map: dict = {} # type: ignore
for cls in get_all_subclasses(BaseWidget):
if cls.django_widget not in django2bread_widgetclass.widget_map: # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion basxbread/querysetfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def introspections(context):
)
)

if boundfield:
if boundfield is not None:
self.append(
hg.SCRIPT(
hg.format(
Expand Down

0 comments on commit 6c0dbcb

Please sign in to comment.