1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

updated the files to render fieldset

This commit is contained in:
sai-ganesh-03 2024-11-14 17:19:57 +05:30
parent 771d3ac3d7
commit f92445f00b
4 changed files with 11 additions and 16 deletions

View File

@ -173,6 +173,7 @@ class AdminField:
self.is_first = is_first # Whether this field is first on the line
self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput)
self.is_readonly = False
self.is_fieldset = self.field.field.widget.use_fieldset
def label_tag(self):
classes = []
@ -185,12 +186,14 @@ class AdminField:
if not self.is_first:
classes.append("inline")
attrs = {"class": " ".join(classes)} if classes else {}
tag = "legend" if self.is_fieldset else None
# checkboxes should not have a label suffix as the checkbox appears
# to the left of the label.
return self.field.label_tag(
contents=mark_safe(contents),
attrs=attrs,
label_suffix="" if self.is_checkbox else None,
tag=tag,
)
def errors(self):

View File

@ -12,6 +12,7 @@
{% if line.fields|length == 1 %}{{ line.errors }}{% else %}<div class="flex-container form-multiline">{% endif %}
{% for field in line %}
<div>
{% if field.is_fieldset %}<fieldset{% if field.field.help_text %} aria-describedby="{{ field.field.id_for_label }}_helptext"{% endif %}>{% endif %}
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
<div class="flex-container{% if not line.fields|length == 1 %} fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}{% endif %}{% if field.is_checkbox %} checkbox-row{% endif %}">
{% if field.is_checkbox %}
@ -30,6 +31,7 @@
<div>{{ field.field.help_text|safe }}</div>
</div>
{% endif %}
{% if field.is_fieldset %}</fieldset>{% endif %}
</div>
{% endfor %}
{% if not line.fields|length == 1 %}</div>{% endif %}

View File

@ -27,8 +27,6 @@ class FilteredSelectMultiple(forms.SelectMultiple):
catalog has been loaded in the page
"""
use_fieldset = True
class Media:
js = [
"admin/js/core.js",
@ -52,7 +50,6 @@ class FilteredSelectMultiple(forms.SelectMultiple):
class BaseAdminDateWidget(forms.DateInput):
use_fieldset = True
class Media:
js = [
@ -70,7 +67,6 @@ class AdminDateWidget(BaseAdminDateWidget):
class BaseAdminTimeWidget(forms.TimeInput):
use_fieldset = True
class Media:
js = [
@ -92,7 +88,6 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget):
A SplitDateTime Widget that has some admin-specific styling.
"""
use_fieldset = True
template_name = "admin/widgets/split_datetime.html"
def __init__(self, attrs=None):
@ -109,12 +104,10 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget):
class AdminRadioSelect(forms.RadioSelect):
use_fieldset = True
template_name = "admin/widgets/radio.html"
class AdminFileWidget(forms.ClearableFileInput):
use_fieldset = True
template_name = "admin/widgets/clearable_file_input.html"
@ -144,7 +137,6 @@ class ForeignKeyRawIdWidget(forms.TextInput):
in a <select> box.
"""
use_fieldset = True
template_name = "admin/widgets/foreign_key_raw_id.html"
def __init__(self, rel, admin_site, attrs=None, using=None):
@ -373,28 +365,24 @@ class RelatedFieldWidgetWrapper(forms.Widget):
class AdminTextareaWidget(forms.Textarea):
use_fieldset = True
def __init__(self, attrs=None):
super().__init__(attrs={"class": "vLargeTextField", **(attrs or {})})
class AdminTextInputWidget(forms.TextInput):
use_fieldset = True
def __init__(self, attrs=None):
super().__init__(attrs={"class": "vTextField", **(attrs or {})})
class AdminEmailInputWidget(forms.EmailInput):
use_fieldset = True
def __init__(self, attrs=None):
super().__init__(attrs={"class": "vTextField", **(attrs or {})})
class AdminURLFieldWidget(forms.URLInput):
use_fieldset = True
template_name = "admin/widgets/url.html"
def __init__(self, attrs=None, validator_class=URLValidator):
@ -418,7 +406,6 @@ class AdminURLFieldWidget(forms.URLInput):
class AdminIntegerFieldWidget(forms.NumberInput):
use_fieldset = True
class_name = "vIntegerField"
def __init__(self, attrs=None):
@ -430,7 +417,6 @@ class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget):
class AdminUUIDInputWidget(forms.TextInput):
use_fieldset = True
def __init__(self, attrs=None):
super().__init__(attrs={"class": "vUUIDField", **(attrs or {})})
@ -619,10 +605,8 @@ class AutocompleteMixin:
class AutocompleteSelect(AutocompleteMixin, forms.Select):
use_fieldset = True
pass
class AutocompleteSelectMultiple(AutocompleteMixin, forms.SelectMultiple):
use_fieldset = True
pass

View File

@ -855,6 +855,12 @@ class ManyToManyRawIdWidgetTest(TestCase):
@override_settings(ROOT_URLCONF="admin_widgets.urls")
class RelatedFieldWidgetWrapperTests(SimpleTestCase):
def test_widget_wrapper_uses_fieldset(self):
rel = Individual._meta.get_field("parent").remote_field
widget = forms.TextInput()
wrapper = widgets.RelatedFieldWidgetWrapper(widget, rel, widget_admin_site)
self.assertTrue(wrapper.use_fieldset)
def test_no_can_add_related(self):
rel = Individual._meta.get_field("parent").remote_field
w = widgets.AdminRadioSelect()