diff --git a/changelog.d/+singularize-incidents.changed.md b/changelog.d/+singularize-incidents.changed.md new file mode 100644 index 000000000..fd403e0bf --- /dev/null +++ b/changelog.d/+singularize-incidents.changed.md @@ -0,0 +1,14 @@ +Htmx: Customizers beware: Major refactor in src/argus/htmx/incident(s) and +src/argus/htmx/templates/htmx/incident(s). + +* All directories named "incidents" was changed to "incident". +* The templates that defines columns in the incident list was moved to + `htmx/incident/cells/`. +* The template for selecting sources in the filterbox was moved to + `htmx/incident/widgets/`. +* Whenever there were plural view-names or url-names for incident-related views + they were made singular. + +There will be empty directories left behind, `git` cannot do anything with +these. Run `make clean` to delete cached files then find empty directories with +`find . -type d -empty`. Delete them manually. diff --git a/docs/development/howtos/htmx-frontend/column_for_specific_tag.rst b/docs/development/howtos/htmx-frontend/column_for_specific_tag.rst index 72e443dca..9a6ed0872 100644 --- a/docs/development/howtos/htmx-frontend/column_for_specific_tag.rst +++ b/docs/development/howtos/htmx-frontend/column_for_specific_tag.rst @@ -9,7 +9,7 @@ You only need to add the column to the column config:: IncidentTableColumn( "mytag", "MYTAG", - "htmx/incidents/_incident_tag.html", + "htmx/incidents/cells/_incident_tag.html", context={"tag": "MYTAG"}, ) .. diff --git a/src/argus/htmx/constants.py b/src/argus/htmx/constants.py index 3efdc6932..01f4fd18b 100644 --- a/src/argus/htmx/constants.py +++ b/src/argus/htmx/constants.py @@ -1,5 +1,5 @@ from argus.htmx.dateformat.constants import DATETIME_DEFAULT, DATETIME_FORMATS, DATETIME_CHOICES -from argus.htmx.incidents.constants import DEFAULT_PAGE_SIZE, ALLOWED_PAGE_SIZES, PAGE_SIZE_CHOICES +from argus.htmx.incident.constants import DEFAULT_PAGE_SIZE, ALLOWED_PAGE_SIZES, PAGE_SIZE_CHOICES from argus.htmx.themes.constants import THEME_CHOICES, THEME_NAMES, THEME_DEFAULT diff --git a/src/argus/htmx/dateformat/views.py b/src/argus/htmx/dateformat/views.py index 2bfb3078b..0e31358da 100644 --- a/src/argus/htmx/dateformat/views.py +++ b/src/argus/htmx/dateformat/views.py @@ -8,7 +8,7 @@ from argus.auth.utils import get_or_update_preference -from argus.htmx.incidents.views import HtmxHttpRequest +from argus.htmx.incident.views import HtmxHttpRequest from .constants import DATETIME_FORMATS LOG = logging.getLogger(__name__) diff --git a/src/argus/htmx/defaults.py b/src/argus/htmx/defaults.py index 74b339b1c..3cb3a19da 100644 --- a/src/argus/htmx/defaults.py +++ b/src/argus/htmx/defaults.py @@ -1,7 +1,7 @@ # customize the displayed columns in the incident table # items in INCIDENT_TABLE_COLUMNS can be either a `str` referring to a key in -# argus.htmx.incidents.customization.BUILTIN_COLUMNS or an instance of -# argus.htmx.incidents.customization.IncidentTableColumn +# argus.htmx.incident.customization.BUILTIN_COLUMNS or an instance of +# argus.htmx.incident.customization.IncidentTableColumn from argus.site.settings import get_json_env, get_str_env INCIDENT_TABLE_COLUMNS = [ @@ -14,7 +14,7 @@ "description", "ticket", ] -ARGUS_HTMX_FILTER_FUNCTION = "argus.htmx.incidents.filter.incident_list_filter" +ARGUS_HTMX_FILTER_FUNCTION = "argus.htmx.incident.filter.incident_list_filter" # These templates are auto-discovered by the templating engine and are relative # to the argus.htmx's `templates/` directory diff --git a/src/argus/htmx/incidents/__init__.py b/src/argus/htmx/incident/__init__.py similarity index 100% rename from src/argus/htmx/incidents/__init__.py rename to src/argus/htmx/incident/__init__.py diff --git a/src/argus/htmx/incidents/constants.py b/src/argus/htmx/incident/constants.py similarity index 100% rename from src/argus/htmx/incidents/constants.py rename to src/argus/htmx/incident/constants.py diff --git a/src/argus/htmx/incidents/customization.py b/src/argus/htmx/incident/customization.py similarity index 69% rename from src/argus/htmx/incidents/customization.py rename to src/argus/htmx/incident/customization.py index 94d5ae5bb..773cf69eb 100644 --- a/src/argus/htmx/incidents/customization.py +++ b/src/argus/htmx/incident/customization.py @@ -39,24 +39,24 @@ class IncidentTableColumn: IncidentTableColumn( "row_select", "Selected", - "htmx/incidents/_incident_checkbox.html", - "htmx/incidents/_incident_list_select_all_checkbox.html", + "htmx/incident/cells/_incident_checkbox.html", + "htmx/incident/cells/_incident_list_select_all_checkbox_header.html", ), - IncidentTableColumn("id", "ID", "htmx/incidents/_incident_pk.html"), + IncidentTableColumn("id", "ID", "htmx/incident/cells/_incident_pk.html"), IncidentTableColumn( "start_time", "Timestamp", - "htmx/incidents/_incident_start_time.html", - "htmx/incidents/_incident_start_time_header.html", + "htmx/incident/cells/_incident_start_time.html", + "htmx/incident/cells/_incident_start_time_header.html", ), - IncidentTableColumn("status", "Status", "htmx/incidents/_incident_status.html"), - IncidentTableColumn("level", "Severity level", "htmx/incidents/_incident_level.html"), - IncidentTableColumn("source", "Source", "htmx/incidents/_incident_source.html"), - IncidentTableColumn("description", "Description", "htmx/incidents/_incident_description.html"), - IncidentTableColumn("ack", "Ack", "htmx/incidents/_incident_ack.html"), - IncidentTableColumn("combined_status", "Status", "htmx/incidents/_incident_combined_status.html"), - IncidentTableColumn("ticket", "Ticket", "htmx/incidents/_incident_ticket.html"), - IncidentTableColumn("links", "Actions", "htmx/incidents/_incident_actions.html"), + IncidentTableColumn("status", "Status", "htmx/incident/cells/_incident_status.html"), + IncidentTableColumn("level", "Severity level", "htmx/incident/cells/_incident_level.html"), + IncidentTableColumn("source", "Source", "htmx/incident/cells/_incident_source.html"), + IncidentTableColumn("description", "Description", "htmx/incident/cells/_incident_description.html"), + IncidentTableColumn("ack", "Ack", "htmx/incident/cells/_incident_ack.html"), + IncidentTableColumn("combined_status", "Status", "htmx/incident/cells/_incident_combined_status.html"), + IncidentTableColumn("ticket", "Ticket", "htmx/incident/cells/_incident_ticket.html"), + IncidentTableColumn("links", "Actions", "htmx/incident/cells/_incident_actions.html"), ] BUILTIN_COLUMNS = {col.name: col for col in _BUILTIN_COLUMN_LIST} diff --git a/src/argus/htmx/incidents/filter.py b/src/argus/htmx/incident/filter.py similarity index 90% rename from src/argus/htmx/incidents/filter.py rename to src/argus/htmx/incident/filter.py index 344e0c705..7ede7cb19 100644 --- a/src/argus/htmx/incidents/filter.py +++ b/src/argus/htmx/incident/filter.py @@ -3,17 +3,13 @@ from argus.filter import get_filter_backend from argus.incident.models import SourceSystem from argus.incident.constants import Level -from argus.htmx.widgets import DropdownMultiSelect +from argus.htmx.widgets import BadgeDropdownMultiSelect filter_backend = get_filter_backend() QuerySetFilter = filter_backend.QuerySetFilter -class BadgeDropdownMultiSelect(DropdownMultiSelect): - template_name = "htmx/incidents/widgets/incident_source_select.html" - - class IncidentFilterForm(forms.Form): open = forms.BooleanField(required=False) closed = forms.BooleanField(required=False) @@ -23,7 +19,7 @@ class IncidentFilterForm(forms.Form): widget=BadgeDropdownMultiSelect( attrs={"placeholder": "select sources..."}, extra={ - "hx_get": "htmx:incidents-filter", + "hx_get": "htmx:incident-filter", }, ), choices=tuple(SourceSystem.objects.values_list("id", "name")), diff --git a/src/argus/htmx/incidents/forms.py b/src/argus/htmx/incident/forms.py similarity index 100% rename from src/argus/htmx/incidents/forms.py rename to src/argus/htmx/incident/forms.py diff --git a/src/argus/htmx/incidents/urls.py b/src/argus/htmx/incident/urls.py similarity index 59% rename from src/argus/htmx/incidents/urls.py rename to src/argus/htmx/incident/urls.py index 338e5c069..8421f9619 100644 --- a/src/argus/htmx/incidents/urls.py +++ b/src/argus/htmx/incident/urls.py @@ -7,6 +7,6 @@ urlpatterns = [ path("", views.incident_list, name="incident-list"), path("/", views.incident_detail, name="incident-detail"), - path("update//", views.incidents_update, name="incidents-update"), - path("filter/", views.filter_form, name="incidents-filter"), + path("update//", views.incident_update, name="incident-update"), + path("filter/", views.filter_form, name="incident-filter"), ] diff --git a/src/argus/htmx/incidents/utils.py b/src/argus/htmx/incident/utils.py similarity index 95% rename from src/argus/htmx/incidents/utils.py rename to src/argus/htmx/incident/utils.py index 9f3d02f22..fb9360c6c 100644 --- a/src/argus/htmx/incidents/utils.py +++ b/src/argus/htmx/incident/utils.py @@ -12,7 +12,7 @@ def get_filter_function(arg=None): ARGUS_HTMX_FILTER_FUNCTION can be one of: * a callable that takes a Request and a QuerySet argument, and returns a Form and an updated - QuerySet (see ``argus.htmx.incidents.filter.incident_list_filter``) + QuerySet (see ``argus.htmx.incident.filter.incident_list_filter``) * a dotted path to an importable function that has the above signature * a dotted path to a module. This module should then contain a function named ``incident_list_filter`` with the above signature diff --git a/src/argus/htmx/incidents/views.py b/src/argus/htmx/incident/views.py similarity index 90% rename from src/argus/htmx/incidents/views.py rename to src/argus/htmx/incident/views.py index 5306ee9b5..b1ee81f05 100644 --- a/src/argus/htmx/incidents/views.py +++ b/src/argus/htmx/incident/views.py @@ -61,7 +61,7 @@ def incident_detail(request, pk: int): "incident": incident, "page_title": str(incident), } - return render(request, "htmx/incidents/incident_detail.html", context=context) + return render(request, "htmx/incident/incident_detail.html", context=context) def get_form_data(request, formclass: forms.Form): @@ -77,7 +77,7 @@ def get_form_data(request, formclass: forms.Form): @require_POST -def incidents_update(request: HtmxHttpRequest, action: str): +def incident_update(request: HtmxHttpRequest, action: str): try: formclass, callback_func = INCIDENT_UPDATE_ACTIONS[action] except KeyError: @@ -94,7 +94,7 @@ def filter_form(request: HtmxHttpRequest): incident_list_filter = get_filter_function() filter_form, _ = incident_list_filter(request, None) context = {"filter_form": filter_form} - return render(request, "htmx/incidents/_incident_filterbox.html", context=context) + return render(request, "htmx/incident/_incident_filterbox.html", context=context) @require_GET @@ -124,9 +124,9 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse: # requests, allowing us to skip rendering the unchanging parts of the # template. if request.htmx: - base_template = "htmx/incidents/responses/_incident_list_refresh.html" + base_template = "htmx/incident/responses/_incident_list_refresh.html" else: - base_template = "htmx/incidents/_base.html" + base_template = "htmx/incident/_base.html" context = { "columns": columns, "filtered_count": filtered_count, @@ -140,4 +140,4 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse: "all_page_sizes": ALLOWED_PAGE_SIZES, } - return render(request, "htmx/incidents/incident_list.html", context=context) + return render(request, "htmx/incident/incident_list.html", context=context) diff --git a/src/argus/htmx/templates/htmx/incidents/widgets/incident_source_select.html b/src/argus/htmx/templates/htmx/forms/badge_dropdown_select_multiple.html similarity index 100% rename from src/argus/htmx/templates/htmx/incidents/widgets/incident_source_select.html rename to src/argus/htmx/templates/htmx/forms/badge_dropdown_select_multiple.html diff --git a/src/argus/htmx/templates/htmx/incidents/_base.html b/src/argus/htmx/templates/htmx/incident/_base.html similarity index 100% rename from src/argus/htmx/templates/htmx/incidents/_base.html rename to src/argus/htmx/templates/htmx/incident/_base.html diff --git a/src/argus/htmx/templates/htmx/incidents/_base_incident_update_modal.html b/src/argus/htmx/templates/htmx/incident/_base_incident_update_modal.html similarity index 79% rename from src/argus/htmx/templates/htmx/incidents/_base_incident_update_modal.html rename to src/argus/htmx/templates/htmx/incident/_base_incident_update_modal.html index 9de670649..c84fb515d 100644 --- a/src/argus/htmx/templates/htmx/incidents/_base_incident_update_modal.html +++ b/src/argus/htmx/templates/htmx/incident/_base_incident_update_modal.html @@ -1,6 +1,6 @@ {% extends "htmx/_base_form_modal.html" %} {% block form_control %} - hx-post="{% url endpoint|default:'htmx:incidents-update' action=action %}" + hx-post="{% url endpoint|default:'htmx:incident-update' action=action %}" hx-indicator="#{{ dialog_id }} .htmx-indicator" {% if action_type == "bulk-update" %} hx-include="[name='incident_ids']" diff --git a/src/argus/htmx/templates/htmx/incidents/_incident_acknowledge_modal.html b/src/argus/htmx/templates/htmx/incident/_incident_acknowledge_modal.html similarity index 91% rename from src/argus/htmx/templates/htmx/incidents/_incident_acknowledge_modal.html rename to src/argus/htmx/templates/htmx/incident/_incident_acknowledge_modal.html index 0bd5578c3..6f0b9bcc0 100644 --- a/src/argus/htmx/templates/htmx/incidents/_incident_acknowledge_modal.html +++ b/src/argus/htmx/templates/htmx/incident/_incident_acknowledge_modal.html @@ -1,4 +1,4 @@ -{% extends "htmx/incidents/_base_incident_update_modal.html" %} +{% extends "htmx/incident/_base_incident_update_modal.html" %} {% block dialogform %}