-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof-of-concept: Introduce HTMX-based replacement for QuickSelect component in Maintenance tool #2883
Draft
lunkwill42
wants to merge
6
commits into
Uninett:master
Choose a base branch
from
lunkwill42:poc/maintenance-htmx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Proof-of-concept: Introduce HTMX-based replacement for QuickSelect component in Maintenance tool #2883
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
757a313
WIP: install htmx and django-htmx
lunkwill42 0abd6c8
WIP: Use django-htmx
lunkwill42 f25082b
WIP: htmx search for maintenance components
lunkwill42 26a7e4d
Make component_search POST-only
lunkwill42 4261b7d
fixup! WIP: htmx search for maintenance components
lunkwill42 f123d85
fixup! WIP: htmx search for maintenance components
lunkwill42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,20 +15,21 @@ | |
# | ||
|
||
import logging | ||
|
||
import time | ||
from datetime import datetime, date | ||
from datetime import datetime | ||
from typing import List, Tuple | ||
|
||
from django.db import transaction, connection | ||
from django.db.models import Count, Q | ||
from django.db.models import Count, Model, Q | ||
from django.shortcuts import render, get_object_or_404, redirect | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse | ||
from django.utils.safestring import mark_safe | ||
|
||
from nav.django.utils import get_account | ||
from nav.models.manage import Netbox | ||
from nav.models.manage import Location, Netbox, NetboxGroup, Room | ||
from nav.models.msgmaint import MaintenanceTask, MaintenanceComponent | ||
from nav.models.service import Service | ||
from nav.web.message import new_message, Messages | ||
from nav.web.quickselect import QuickSelect | ||
|
||
|
@@ -363,6 +364,27 @@ def edit(request, task_id=None, start_time=None, **_): | |
) | ||
|
||
|
||
def component_search(request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefix with |
||
"""HTMX endpoint for component searches from maintenance task form""" | ||
search = request.POST.get("search") | ||
results = {} | ||
searches: List[Tuple[Model, Q]] = [ | ||
(Location, Q(id__icontains=search)), | ||
(Room, Q(id__icontains=search)), | ||
(Netbox, Q(sysname__icontains=search)), | ||
(NetboxGroup, Q(id__icontains=search)), | ||
(Service, Q(handler__icontains=search) | Q(netbox__sysname__icontains=search)), | ||
] | ||
|
||
for component_type, query in searches: | ||
component_result = component_type.objects.filter(query) | ||
if component_result: | ||
component_title = component_type._meta.verbose_name.title() | ||
results[component_title] = component_result | ||
|
||
return render(request, 'maintenance/search-results.html', {'results': results}) | ||
|
||
|
||
def add_box_to_maintenance(request): | ||
""" | ||
This view puts a Netbox on immediate, indefinite maintenance and | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% if results %} | ||
{% for component_type, values in results.items %} | ||
{% if values %} | ||
<h4>{{ component_type }}</h4> | ||
<ul> | ||
{% for value in values %} | ||
<li>{{ value }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endfor %} | ||
{% else %} | ||
<strong>No hits</strong> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why stick with
re_path
?path
is easier to read.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could ask you the same. I used the same pattern as the surrounding lines. They were all last modified by you as part of some Django upgrade, I believe :)