Address PR review: reorder field checkboxes, fix indentation, add simultaneous-field test
- Move field checkboxes before the find/replace/use_regex inputs so they
are not visually conflated with the 'use regex' checkbox
- Fix indentation inside the {% if rename_fields %} block
- Add trailing newline to bulk_rename.html
- Add test_bulk_rename_name_and_label_fields to verify that submitting
field_names=['name', 'label'] updates both fields simultaneously
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5c06d8ddc3
commit
91f779b661
|
|
@ -66,28 +66,28 @@ Context:
|
|||
<div class="card-body">
|
||||
{# Hidden fields #}
|
||||
{% for field in form.hidden_fields %}{{ field }}{% endfor %}
|
||||
{# Per-field checkboxes first, so they aren't confused with "use regex" #}
|
||||
{% if rename_fields %}
|
||||
<div class="row mb-3">
|
||||
<label class="col-sm-3 col-form-label pt-0 text-lg-end">{% trans "Fields" %}</label>
|
||||
<div class="col">
|
||||
{% for field in rename_fields %}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="field_names"
|
||||
id="id_field_names_{{ field }}" value="{{ field }}"
|
||||
{% if field in selected_field_names %}checked{% endif %}>
|
||||
<label class="form-check-label" for="id_field_names_{{ field }}">{{ field|title }}</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{# Standard fields (find, replace, use_regex) #}
|
||||
{% for field in form.visible_fields %}
|
||||
{% if not form.meta_fields or field.name not in form.meta_fields %}
|
||||
{% render_field field %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{# Per-field rename checkboxes, rendered before the changelog fieldset #}
|
||||
{% if rename_fields %}
|
||||
<div class="row mb-3">
|
||||
<label class="col-sm-3 col-form-label pt-0 text-lg-end">{% trans "Fields" %}</label>
|
||||
<div class="col">
|
||||
{% for field in rename_fields %}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="field_names"
|
||||
id="id_field_names_{{ field }}" value="{{ field }}"
|
||||
{% if field in selected_field_names %}checked{% endif %}>
|
||||
<label class="form-check-label" for="id_field_names_{{ field }}">{{ field|title }}</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{# Changelog / meta fields #}
|
||||
{% if form.meta_fields %}
|
||||
<div class="bg-primary-subtle border border-primary rounded-1 pt-3 px-3 mb-3">
|
||||
|
|
|
|||
|
|
@ -1143,6 +1143,33 @@ class ViewTestCases:
|
|||
self.assertEqual(instance.label, f'{original_labels[i]}X')
|
||||
self.assertEqual(instance.name, objects[i].name)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_bulk_rename_name_and_label_fields(self):
|
||||
"""When field_names=['name', 'label'] is submitted, both fields are updated simultaneously."""
|
||||
if 'label' not in {f.name for f in self.model._meta.fields}:
|
||||
self.skipTest("Model does not have a label field")
|
||||
|
||||
objects = self._get_queryset().all()[:3]
|
||||
pk_list = [obj.pk for obj in objects]
|
||||
original_names = [obj.name for obj in objects]
|
||||
original_labels = [obj.label for obj in objects]
|
||||
data = {
|
||||
'pk': pk_list,
|
||||
'field_names': ['name', 'label'],
|
||||
'_apply': True,
|
||||
}
|
||||
data.update(self.rename_data)
|
||||
|
||||
obj_perm = ObjectPermission(name='Test permission', actions=['change'])
|
||||
obj_perm.save()
|
||||
obj_perm.users.add(self.user)
|
||||
obj_perm.object_types.add(ObjectType.objects.get_for_model(self.model))
|
||||
|
||||
self.assertHttpStatus(self.client.post(self._get_url('bulk_rename'), data), 302)
|
||||
for i, instance in enumerate(self._get_queryset().filter(pk__in=pk_list)):
|
||||
self.assertEqual(instance.name, f'{original_names[i]}X')
|
||||
self.assertEqual(instance.label, f'{original_labels[i]}X')
|
||||
|
||||
class PrimaryObjectViewTestCase(
|
||||
GetObjectViewTestCase,
|
||||
GetObjectChangelogViewTestCase,
|
||||
|
|
|
|||
Loading…
Reference in New Issue