Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/argus/htmx/incident/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
path("filter/delete/<int:pk>/", views.delete_filter, name="filter-delete"),
path("filter/update/<int:pk>/", views.update_filter, name="filter-update"),
path("filter/existing/", views.get_existing_filters, name="existing-filters"),
path("fake_ticket/<int:pk>/", views.get_fake_ticket, name="fake-ticket"),
]
16 changes: 16 additions & 0 deletions src/argus/htmx/incident/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import logging
from datetime import datetime, timedelta
from typing import Optional
from urllib.parse import urljoin

from django import forms
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib import messages
from django.utils.timezone import now as tznow
from django.urls import reverse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from django.utils.timezone import now as tznow
from django.urls import reverse
from django.urls import reverse
from django.utils.timezone import now as tznow

from django.shortcuts import render, get_object_or_404

from django.views.decorators.http import require_POST, require_GET
Expand All @@ -19,6 +22,7 @@
from argus.incident.models import Incident
from argus.incident.ticket.utils import get_ticket_plugin_path
from argus.incident.ticket.base import TicketPluginException
from argus.incident.serializers import IncidentSerializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from argus.incident.ticket.utils import get_ticket_plugin_path
from argus.incident.ticket.base import TicketPluginException
from argus.incident.serializers import IncidentSerializer
from argus.incident.serializers import IncidentSerializer
from argus.incident.ticket.utils import get_ticket_plugin_path
from argus.incident.ticket.base import TicketPluginException

from argus.notificationprofile.models import Filter
from argus.util.datetime_utils import make_aware

Expand Down Expand Up @@ -257,3 +261,15 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse:
}

return render(request, "htmx/incident/incident_list.html", context=context)


@require_GET
def get_fake_ticket(request: HtmxHttpRequest, pk: int) -> HttpResponse:
incident = get_object_or_404(Incident.objects.all(), pk=pk)
context = IncidentSerializer(incident).data
argus_url = urljoin(
getattr(settings, "FRONTEND_URL", ""),
reverse("htmx:incident-detail", kwargs={"pk": pk}),
)
context["argus_url"] = argus_url
Comment on lines +269 to +274
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use

def serialize_incident_for_ticket_autocreation(incident: Incident, actor: User):
serialized_incident = IncidentSerializer(incident).data
# TODO: ensure argus_url ends with "/" on HTMx frontend
serialized_incident["argus_url"] = urljoin(
getattr(settings, "FRONTEND_URL", ""),
f"incidents/{incident.pk}",
)
serialized_incident["user"] = actor.get_full_name()
return serialized_incident
for this

return render(request, "incident/ticket/default_ticket_body.html", context=context)