Skip to content

Commit

Permalink
Merge branch 'master' into incidents-filter-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
podliashanyk committed Jan 22, 2025
2 parents c9c7b36 + 249b681 commit 0cd72b9
Show file tree
Hide file tree
Showing 32 changed files with 338 additions and 119 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
- id: end-of-file-fixer
exclude: &exclude_pattern '^changelog.d/'
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
# Run the linter
- id: ruff
Expand All @@ -17,7 +17,7 @@ repos:
- id: ruff-format
name: "Ruff formatting"
- repo: https://github.com/djlint/djLint
rev: v1.36.3
rev: v1.36.4
hooks:
- id: djlint-reformat-django
- id: djlint-django
Expand Down
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,59 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [1.31.0] - 2025-01-17

Mostly changes to the new frontend this time around.

Two development-relevant changes:

- Refactor of incident-specific frontend pages, many files have new names
- How to define a preference has changed

There are visible changes to the destinations-page and profiles page as well.

### Added

- Added howto for how to easily toggle the use of django-debug-toolbar with the
help of the extra/overriding-apps machinery and an environment variable.

### HTMx app

#### Added

- Centre destination page content.
([#1079](https://github.com/Uninett/Argus/issues/1079))
- Add vertical gap between collapse element and create form on HTMX
destinations page. ([#1080](https://github.com/Uninett/Argus/issues/1080))

#### Changed

- Streamline definition and usage of preferences
([#1072](https://github.com/Uninett/Argus/issues/1072))
- Only update the related media list when deleting a destination.
([#1128](https://github.com/Uninett/Argus/issues/1128))
- 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.
- Polished the looks of the profiles page. More to come!

#### Fixed

- Fix create destination form generating extra div when submitting.
([#1129](https://github.com/Uninett/Argus/issues/1129))


## [1.30.0] - 2024-12-19

Mostly changes to the alpha frontend
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind docclean

TAILWINDDIR=src/argus/htmx/tailwindtheme
STATICDIR=src/argus/htmx/static
Expand All @@ -15,6 +15,9 @@ distclean:
-rm -rf ./dist
-rm -rf ./build

docclean:
-rm -rf ./docs/_build

coverageclean:
-rm .coverage
-rm .coverage.*
Expand All @@ -24,7 +27,7 @@ coverageclean:
testclean: coverageclean clean
-rm -rf .tox

nuke: clean distclean testclean cacheclean
nuke: clean docclean distclean testclean cacheclean

tailwind:
tailwindcss -c $(TAILWINDDIR)/tailwind.config.js -i $(TAILWINDDIR)/styles.css -o $(STATICDIR)/styles.css
18 changes: 16 additions & 2 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Release Notes

This file documents changes to Argus that are relevant for operations and
end-users.
This file documents changes to Argus that are relevant for operations,
customizers and end-users.

## [1.31.0] - 2025-01-17

Mostly changes to the new frontend this time around.

Two development-relevant changes that affect customization:

- Refactor of incident-specific frontend pages, many files have new names
- How to define a preference has changed

There are visible changes to the destinations-page and profiles page as well.

This release is the first round of polish for the profiles page. More is to
come.

## [1.30.0] - 2024-12-19

Expand Down
1 change: 0 additions & 1 deletion changelog.d/+polish-profiles-page.changed.md

This file was deleted.

14 changes: 0 additions & 14 deletions changelog.d/+singularize-incidents.changed.md

This file was deleted.

2 changes: 0 additions & 2 deletions changelog.d/+toggle-django-debug-toolbar.added.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/1072.changed.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/1079.added.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/1080.added.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/1129.fixed.md

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/1136.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update only the related media list when updating a destination.
4 changes: 4 additions & 0 deletions src/argus/htmx/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"argus.htmx.middleware.HtmxMessageMiddleware": "end",
},
},
{
"app_name": "django.forms",
"settings": {"FORM_RENDERER": "django.forms.renderers.TemplatesSetting"},
},
]

APP_SETTINGS = ListAppSetting(_app_settings).root
65 changes: 43 additions & 22 deletions src/argus/htmx/destination/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,51 @@ def create_htmx(request) -> HttpResponse:
@require_http_methods(["POST"])
def delete_htmx(request, pk: int) -> HttpResponse:
destination = get_object_or_404(request.user.destinations.all(), pk=pk)
template = "htmx/destination/_form_list.html"
media = destination.media
error_msg = None
try:
medium = api_safely_get_medium_object(destination.media.slug)
medium.raise_if_not_deletable(destination)
except NotificationMedium.NotDeletableError:
error_msg = "This destination cannot be deleted."
return _render_destination_list(request, errors=[error_msg], template=template)
error_msg = "That destination cannot be deleted."
else:
destination.delete()
return _render_destination_list(request, template=template)

forms = _get_update_forms(request.user, media=media)

context = {
"error_msg": error_msg,
"forms": forms,
"media": media,
}
return render(request, "htmx/destination/_collapse_with_forms.html", context=context)


@require_http_methods(["POST"])
def update_htmx(request, pk: int) -> HttpResponse:
destination = DestinationConfig.objects.get(pk=pk)
media = destination.media
form = DestinationFormUpdate(request.POST or None, instance=destination, request=request)
template = "htmx/destination/_form_list.html"
if form.is_valid():
if is_valid := form.is_valid():
form.save()
return _render_destination_list(request, template=template)

update_forms = _get_update_forms(request.user)
for index, update_form in enumerate(update_forms):
if update_form.instance.pk == pk:
update_forms[index] = form
break
return _render_destination_list(request, update_forms=update_forms, template=template)
update_forms = _get_update_forms(request.user, media=media)

if not is_valid:
update_forms = _replace_form_in_list(update_forms, form)

context = {
"error_msg": None,
"forms": update_forms,
"media": media,
}
return render(request, "htmx/destination/_collapse_with_forms.html", context=context)


def _render_destination_list(
request,
create_form: Optional[DestinationFormCreate] = None,
update_forms: Optional[Sequence[DestinationFormUpdate]] = None,
errors: Optional[Sequence[str]] = None,
template: str = "htmx/destination/destination_list.html",
) -> HttpResponse:
"""Function to render the destinations page.
Expand All @@ -71,29 +82,31 @@ def _render_destination_list(
with errors while retaining the user input. If you want a blank form, pass None.
:param update_forms: list of update forms to display. Useful for rendering forms
with error messages while retaining the user input.
If this is None, the update forms will be generated from the user's destinations.
:param errors: a list of error messages to display on the page. Will not be tied to
any form fields."""
If this is None, the update forms will be generated from the user's destinations."""

if create_form is None:
create_form = DestinationFormCreate()
if update_forms is None:
update_forms = _get_update_forms(request.user)
if errors is None:
errors = []
grouped_forms = _group_update_forms_by_media(update_forms)
context = {
"create_form": create_form,
"grouped_forms": grouped_forms,
"errors": errors,
"page_title": "Destinations",
}
return render(request, template, context=context)


def _get_update_forms(user) -> list[DestinationFormUpdate]:
def _get_update_forms(user, media: Media = None) -> list[DestinationFormUpdate]:
"""Get a list of update forms for the user's destinations.
:param media: if provided, only return destinations for this media.
"""
if media:
destinations = user.destinations.filter(media=media)
else:
destinations = user.destinations.all()
# Sort by oldest first
destinations = user.destinations.all().order_by("pk")
destinations = destinations.order_by("pk")
return [DestinationFormUpdate(instance=destination) for destination in destinations]


Expand All @@ -111,3 +124,11 @@ def _group_update_forms_by_media(
grouped_destinations[form.instance.media].append(form)

return grouped_destinations


def _replace_form_in_list(forms: list[DestinationFormUpdate], form: DestinationFormUpdate):
for index, f in enumerate(forms):
if f.instance.pk == form.instance.pk:
forms[index] = form
break
return forms
9 changes: 6 additions & 3 deletions src/argus/htmx/incident/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class IncidentFilterForm(forms.Form):
sourceSystemIds = forms.MultipleChoiceField(
widget=BadgeDropdownMultiSelect(
attrs={"placeholder": "select sources..."},
extra={
"hx_get": "htmx:incident-filter",
},
partial_get=None,
),
choices=tuple(SourceSystem.objects.values_list("id", "name")),
required=False,
Expand All @@ -58,6 +56,11 @@ class IncidentFilterForm(forms.Form):
required=False,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# mollify tests
self.fields["sourceSystemIds"].widget.partial_get = reverse("htmx:incident-filter")

def _tristate(self, onkey, offkey):
on = self.cleaned_data.get(onkey, None)
off = self.cleaned_data.get(offkey, None)
Expand Down
6 changes: 6 additions & 0 deletions src/argus/htmx/notificationprofile/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
urlpatterns = [
path("", views.NotificationProfileListView.as_view(), name="notificationprofile-list"),
path("create/", views.NotificationProfileCreateView.as_view(), name="notificationprofile-create"),
path("field/filters/", views.filters_form_view, name="notificationprofile-filters-field-create"),
path("field/destinations/", views.destinations_form_view, name="notificationprofile-destinations-field-create"),
path("<pk>/", views.NotificationProfileDetailView.as_view(), name="notificationprofile-detail"),
path("<pk>/update/", views.NotificationProfileUpdateView.as_view(), name="notificationprofile-update"),
path("<pk>/delete/", views.NotificationProfileDeleteView.as_view(), name="notificationprofile-delete"),
path("<pk>/field/filters/", views.filters_form_view, name="notificationprofile-filters-field-update"),
path(
"<pk>/field/destinations/", views.destinations_form_view, name="notificationprofile-destinations-field-update"
),
]
Loading

0 comments on commit 0cd72b9

Please sign in to comment.