mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 20:46:30 -06:00
#6797: Improve form error/django messages handling
This commit is contained in:
parent
8e3ab8d5c5
commit
0b09365d0d
@ -854,7 +854,7 @@ class BulkEditView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View):
|
||||
return redirect(self.get_return_url(request))
|
||||
|
||||
except ValidationError as e:
|
||||
messages.error(self.request, "{} failed validation: {}".format(obj, e))
|
||||
messages.error(self.request, "{} failed validation: {}".format(obj, ", ".join(e.messages)))
|
||||
|
||||
except PermissionsViolation:
|
||||
msg = "Object update failed due to object-level permissions violation"
|
||||
|
BIN
netbox/project-static/dist/netbox-dark.css
vendored
BIN
netbox/project-static/dist/netbox-dark.css
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox-light.css
vendored
BIN
netbox/project-static/dist/netbox-light.css
vendored
Binary file not shown.
@ -1062,6 +1062,13 @@ div.card > div.card-header > div.table-controls {
|
||||
border-bottom: 1px solid $nav-tabs-border-color;
|
||||
}
|
||||
|
||||
#django-messages {
|
||||
position: fixed;
|
||||
right: $spacer;
|
||||
bottom: 0;
|
||||
margin: $spacer;
|
||||
}
|
||||
|
||||
// Page-specific styles.
|
||||
html {
|
||||
// Shade the home page content background-color.
|
||||
|
@ -1,46 +1,13 @@
|
||||
{% load helpers %}
|
||||
|
||||
<div id="django-messages" class="toast-container position-fixed bottom-0 end-0 m-3">
|
||||
<div id="django-messages" class="toast-container">
|
||||
{# Django Messages #}
|
||||
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
{% with message.level_tag|status_from_tag as status %}
|
||||
{% with status|icon_from_status as icon %}
|
||||
<div class="django-message toast align-items-center border-0 bg-{{ status }}" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="10000">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="mdi mdi-{{ icon }} me-1"></i>
|
||||
{{ message }}
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
||||
{% elif form and form.non_field_errors %}
|
||||
{# Non-Field Form Errors #}
|
||||
|
||||
{% for error in form.non_field_errors.get_json_data %}
|
||||
<div class="django-message toast align-items-center border-0 bg-danger" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="10000">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="mdi mdi-{{ "danger"|icon_from_status }} me-1"></i>
|
||||
{{ error.message }}
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% elif form and form.errors %}
|
||||
{# Form Field Errors #}
|
||||
|
||||
{% if form and form.errors %}
|
||||
{% for field in form %}
|
||||
{% for error in field.errors %}
|
||||
<div class="django-message toast align-items-center border-0 bg-danger" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="60000">
|
||||
<div class="django-message toast align-items-center border-0 bg-danger" data-django-type="field-error" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="60000">
|
||||
<div class="toast-header bg-danger">
|
||||
<strong class="me-auto">
|
||||
<i class="mdi mdi-{{ "danger"|icon_from_status }} me-1"></i>
|
||||
@ -54,6 +21,40 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{# Non-Field Form Errors #}
|
||||
{% if form and form.non_field_errors %}
|
||||
{% for error in form.non_field_errors.get_json_data %}
|
||||
<div class="django-message toast align-items-center border-0 bg-danger" data-django-type="non-field-error" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="10000">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="mdi mdi-{{ "danger"|icon_from_status }} me-1"></i>
|
||||
{{ error.message }}
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{# Django Messages #}
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
{% with message.level_tag|status_from_tag as status %}
|
||||
{% with status|icon_from_status as icon %}
|
||||
<div class="django-message toast align-items-center border-0 bg-{{ status }}" data-django-type="message" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="10000">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="mdi mdi-{{ icon }} me-1"></i>
|
||||
{{ message }}
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user