From d00c6cceec9d9188a010d77d8b72fcfcb098228d Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Mon, 29 Apr 2024 11:57:44 +0200
Subject: [PATCH 001/216] Initial commit
---
.gitignore | 12 ++++++++++++
Makefile | 21 +++++++++++++++++++++
README.rst | 13 +++++++++++++
pyproject.toml | 27 +++++++++++++++++++++++++++
4 files changed, 73 insertions(+)
create mode 100644 .gitignore
create mode 100644 Makefile
create mode 100644 README.rst
create mode 100644 pyproject.toml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..776a3b475
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+.*
+
+*.egg
+*.egg-info
+*.py[cio]
+*.sw?
+
+__pycache__/
+build/
+dist/
+
+!.gitignore
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..a0219489d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+.PHONY: clean testclean distclean coverageclean nuke
+
+clean:
+ -find . -name __pycache__ -print0 | xargs -0 rm -rf
+ -find . -name "*.pyc" -print0 | xargs -0 rm -rf
+ -find . -name "*.egg-info" -print0 | xargs -0 rm -rf
+
+distclean:
+ -rm -rf ./dist
+ -rm -rf ./build
+
+coverageclean:
+ -rm .coverage
+ -rm .coverage.*
+ -rm coverage.xml
+ -rm -rf htmlcov
+
+testclean: coverageclean clean
+ -rm -rf .tox
+
+nuke: clean distclean testclean
diff --git a/README.rst b/README.rst
new file mode 100644
index 000000000..44021e088
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,13 @@
+===================
+argus-HTMx-frontend
+===================
+
+Experimental frontend for `argus-server`_ as a django app.
+
+Will possibly cease to exist as a separate app if the experiment is deemed
+successful.
+
+See `argus-server`_ for more.
+
+
+.. _argus-server: https://github.com/Uninett/Argus
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 000000000..a03958c0d
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,27 @@
+[build-system]
+requires = ["flit_core >=3.2,<4"]
+build-backend = "flit_core.buildapi"
+
+[project]
+description = "HTTP Frontend as a django app for argus-server using HTMx"
+name = "argus_htmx"
+readme = "README.rst"
+authors = [{name = "Hanne Moa", email = "hanne.moa@sikt.no"}]
+requires-python = ">=3.8"
+classifiers = [
+ "Framework :: Django",
+ "Framework :: Django :: 4.2",
+ "Programming Language :: Python :: 3 :: Only",
+ "Environment :: Web Environment",
+]
+dynamic = ["version"]
+dependencies = [
+ "argus-server",
+ "django-htmx",
+]
+
+[project.urls]
+Github = "https://github.com/Uninett/argus-htmx-frontend"
+
+[project.optional-dependencies]
+docs = ["sphinx"]
From 9280888878bd08d599d4cbbf5ec228433f758cf6 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Mon, 29 Apr 2024 12:00:02 +0200
Subject: [PATCH 002/216] Moved from argus-server, experimental branch
---
src/argus_htmx/__init__.py | 0
src/argus_htmx/admin.py | 3 ++
src/argus_htmx/apps.py | 7 +++
src/argus_htmx/migrations/__init__.py | 0
src/argus_htmx/models.py | 3 ++
src/argus_htmx/templates/base.html | 17 +++++++
src/argus_htmx/templates/htmx/base.html | 7 +++
.../htmx/incidents/_incident_description.html | 1 +
.../htmx/incidents/_incident_pk.html | 1 +
.../htmx/incidents/_incident_row.html | 14 ++++++
.../htmx/incidents/_incident_start_time.html | 1 +
.../htmx/incidents/incident_detail.html | 44 +++++++++++++++++++
.../templates/htmx/incidents/list.html | 15 +++++++
src/argus_htmx/tests.py | 3 ++
src/argus_htmx/urls.py | 10 +++++
src/argus_htmx/views.py | 39 ++++++++++++++++
16 files changed, 165 insertions(+)
create mode 100644 src/argus_htmx/__init__.py
create mode 100644 src/argus_htmx/admin.py
create mode 100644 src/argus_htmx/apps.py
create mode 100644 src/argus_htmx/migrations/__init__.py
create mode 100644 src/argus_htmx/models.py
create mode 100644 src/argus_htmx/templates/base.html
create mode 100644 src/argus_htmx/templates/htmx/base.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_description.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_pk.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_row.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_start_time.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/incident_detail.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/list.html
create mode 100644 src/argus_htmx/tests.py
create mode 100644 src/argus_htmx/urls.py
create mode 100644 src/argus_htmx/views.py
diff --git a/src/argus_htmx/__init__.py b/src/argus_htmx/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/argus_htmx/admin.py b/src/argus_htmx/admin.py
new file mode 100644
index 000000000..8c38f3f3d
--- /dev/null
+++ b/src/argus_htmx/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/src/argus_htmx/apps.py b/src/argus_htmx/apps.py
new file mode 100644
index 000000000..92120760b
--- /dev/null
+++ b/src/argus_htmx/apps.py
@@ -0,0 +1,7 @@
+from django.apps import AppConfig
+
+
+class HtmxFrontendConfig(AppConfig):
+ default_auto_field = "django.db.models.BigAutoField"
+ label = "argus_htmx"
+ name = "argus_htmx"
diff --git a/src/argus_htmx/migrations/__init__.py b/src/argus_htmx/migrations/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/argus_htmx/models.py b/src/argus_htmx/models.py
new file mode 100644
index 000000000..71a836239
--- /dev/null
+++ b/src/argus_htmx/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/src/argus_htmx/templates/base.html b/src/argus_htmx/templates/base.html
new file mode 100644
index 000000000..50a363847
--- /dev/null
+++ b/src/argus_htmx/templates/base.html
@@ -0,0 +1,17 @@
+{% load static %}
+
+
+
+
+ Argus Server: {{ page_title }}
+
+ {% block head %}
+ {% endblock head %}
+
+
+ Argus Server: {{ page_title }}
+ {% block main %}
+ {% endblock main %}
+ {% block tail %}{% endblock tail %}
+
+
diff --git a/src/argus_htmx/templates/htmx/base.html b/src/argus_htmx/templates/htmx/base.html
new file mode 100644
index 000000000..703b4e8d1
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/base.html
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+{% block head %}
+
+{% endblock head %}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_description.html b/src/argus_htmx/templates/htmx/incidents/_incident_description.html
new file mode 100644
index 000000000..1cdd1d3cb
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_description.html
@@ -0,0 +1 @@
+{{ incident.description }}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_pk.html b/src/argus_htmx/templates/htmx/incidents/_incident_pk.html
new file mode 100644
index 000000000..6fb14aa51
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_pk.html
@@ -0,0 +1 @@
+{{ incident.pk }}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_row.html b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
new file mode 100644
index 000000000..f73932066
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
@@ -0,0 +1,14 @@
+
+ HTMX-app
+
+ {% block incident_pk %}
+ {% include "htmx/incidents/_incident_pk.html" %}
+ {% endblock %}
+ {% block start_time %}
+ {% include "htmx/incidents/_incident_start_time.html" %}
+ {% endblock %}
+ {% block description %}
+ {% include "htmx/incidents/_incident_description.html" %}
+ {% endblock %}
+
+
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_start_time.html b/src/argus_htmx/templates/htmx/incidents/_incident_start_time.html
new file mode 100644
index 000000000..721f2a5c9
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_start_time.html
@@ -0,0 +1 @@
+{{ incident.start_time }}
diff --git a/src/argus_htmx/templates/htmx/incidents/incident_detail.html b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
new file mode 100644
index 000000000..d9bc73ac3
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
@@ -0,0 +1,44 @@
+{% extends "htmx/base.html" %}
+
+{% block main %}
+{{ incident.pk }}: {{ incident.description }}
+
+{% block incident_detail %}
+
+Status
+
+{{ incident.level }}
+{{ incident.is_open }}
+{{ incident.ticket_url }}
+
+
+
+
+
+
+Primary details #{{ incident.pk }}
+
+Description
+{{ incident.description }}
+
+Start time
+{{ incident.start_time }}
+
+Source id
+{{ incident.source_incident_id }}
+
+Details url
+{{ incident.details_url }}
+
+Ticket url
+{{ incident.ticket_url }}
+
+{% endblock incident_detail %}
+{% endblock main %}
diff --git a/src/argus_htmx/templates/htmx/incidents/list.html b/src/argus_htmx/templates/htmx/incidents/list.html
new file mode 100644
index 000000000..8946f3124
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/list.html
@@ -0,0 +1,15 @@
+{% extends "htmx/base.html" %}
+
+{% block main %}
+Latest: {{ latest }}
+
+ {% for incident in qs|slice:5 %}
+ {% block incident %}
+ {% include "htmx/incidents/_incident_row.html" %}
+ {% endblock incident %}
+ {% empty %}
+ - None found
+ {% endfor %}
+
+Total, all time: {{ qs|length }}
+{% endblock main %}
diff --git a/src/argus_htmx/tests.py b/src/argus_htmx/tests.py
new file mode 100644
index 000000000..7ce503c2d
--- /dev/null
+++ b/src/argus_htmx/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/src/argus_htmx/urls.py b/src/argus_htmx/urls.py
new file mode 100644
index 000000000..d18721d29
--- /dev/null
+++ b/src/argus_htmx/urls.py
@@ -0,0 +1,10 @@
+from django.urls import path
+
+from . import views
+
+
+app_name = "htmx"
+urlpatterns = [
+ path("incidents/", views.incidents, name="htmx_incidents"),
+ path("incidents//", views.incident_detail, name="htmx_incident_detail"),
+]
diff --git a/src/argus_htmx/views.py b/src/argus_htmx/views.py
new file mode 100644
index 000000000..9e478f029
--- /dev/null
+++ b/src/argus_htmx/views.py
@@ -0,0 +1,39 @@
+import logging
+
+from django.conf import settings
+from django.shortcuts import render, reverse, get_object_or_404
+
+from argus.incident.models import Incident
+
+LOG = logging.getLogger(__name__)
+
+
+def incidents(request):
+ qs = Incident.objects.all().order_by("-start_time")
+ latest = qs.latest("start_time").start_time
+ context = {
+ "qs": qs,
+ "latest": latest,
+ "page_title": "Incidents",
+ }
+ return render(request, "htmx/incidents/list.html", context=context)
+
+
+# fetch with htmx
+def incident_row(request, pk: int):
+ incident = get_object_or_404(Incident, d=pk)
+ context = {"incident": incident}
+ return render(request, "htmx/incidents/_incident_row.html", context=context)
+
+
+def incident_detail(request, pk: int):
+ incident = get_object_or_404(Incident, id=pk)
+ context = {
+ "incident": incident,
+ "page_title": str(incident),
+ }
+ return render(request, "htmx/incidents/incident_detail.html", context=context)
+
+
+#
+# incident.tags.key
From ce582ad22025536fef8e499e8cf4a3ecc743173a Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Mon, 29 Apr 2024 13:32:36 +0200
Subject: [PATCH 003/216] Add installation and configuration instructions to
README
---
README.rst | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
diff --git a/README.rst b/README.rst
index 44021e088..b3e1a2e98 100644
--- a/README.rst
+++ b/README.rst
@@ -7,7 +7,63 @@ Experimental frontend for `argus-server`_ as a django app.
Will possibly cease to exist as a separate app if the experiment is deemed
successful.
-See `argus-server`_ for more.
+See `argus-server`_ for more abour argus.
+Imports `django-htmx`_. See the `documentation for django-htmx`_
+for details.
+How to play
+===========
+
+Install
+-------
+
+To make sure you do not accidentally work on an old argus-server, do the following:
+
+1. Use/make a venv, for instance: create a new one with ``python -m venv argus-htmx``
+2. Check out argus-server code
+3. Install argus-server dynamically into the venv: ``pip install -e .``
+4. Check out this repo
+5. Install this app dynamically into the venv: ``pip install -e .``
+
+It is now safe to remove argus-server from the venv if you feel like it.
+
+Configure
+---------
+
+Do this in your workdir, which could be the checked out `argus-server`_ repo.
+
+Django-style
+~~~~~~~~~~~~
+
+In your local settings that star-imports from an `argus-server`_ settings file::
+
+ INSTALLED_APPS += [
+ "django_htmx",
+ "argus_htmx",
+ ]
+ ROOT_URLCONF = "urls.py"
+ MIDDLEWARE += ["django_htmx.middleware.HtmxMiddleware"]
+
+Next to ``localsettings.py`` create an ``urls.py`` containing::
+
+ from argus.site.urls import urlpatterns
+
+ urlpatterns += [
+ path("", include("argus_htmx.urls")
+ ]
+
+With EXTRA_APPS
+~~~~~~~~~~~~~~~
+
+In your environment variables::
+
+ ARGUS_EXTRA_APPS = '[{"app_name": "django_htmx"},{"app_name": "argus_htmx","urls": {"path": "", "urlpatterns_module": "argus_htmx.urls"}}]'
+
+In your local settings that star-imports from an `argus-server`_ settings file::
+
+ MIDDLEWARE += ["django_htmx.middleware.HtmxMiddleware"]
+
+.. _django-htmx: https://github.com/adamchainz/django-htmx
.. _argus-server: https://github.com/Uninett/Argus
+.. _documentation for django-htmx: https://django-htmx.readthedocs.io/en/latest/
From af0a9460be4b0b337d81278c1acdcfee4581707d Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Mon, 29 Apr 2024 13:55:11 +0200
Subject: [PATCH 004/216] Add version to argus_htmx.__init__
---
src/argus_htmx/__init__.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/argus_htmx/__init__.py b/src/argus_htmx/__init__.py
index e69de29bb..a4e2017f0 100644
--- a/src/argus_htmx/__init__.py
+++ b/src/argus_htmx/__init__.py
@@ -0,0 +1 @@
+__version__ = "0.1"
From d8e779020f1bf045529cf92afa48badc22c3c538 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 08:41:04 +0200
Subject: [PATCH 005/216] Namespace urls
---
src/argus_htmx/templates/htmx/incidents/_incident_row.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_row.html b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
index f73932066..c3da9cad3 100644
--- a/src/argus_htmx/templates/htmx/incidents/_incident_row.html
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
@@ -1,6 +1,6 @@
HTMX-app
-
+
{% block incident_pk %}
{% include "htmx/incidents/_incident_pk.html" %}
{% endblock %}
From 253bcabee3f7ebfea624c90ea39f069d9b48a5c0 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 10:26:08 +0200
Subject: [PATCH 006/216] Add status- and ack-column to incidents list
---
.../templates/htmx/incidents/_incident_ack.html | 1 +
src/argus_htmx/templates/htmx/incidents/_incident_pk.html | 2 +-
.../templates/htmx/incidents/_incident_row.html | 8 ++++++--
.../templates/htmx/incidents/_incident_status.html | 1 +
4 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_ack.html
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_status.html
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_ack.html b/src/argus_htmx/templates/htmx/incidents/_incident_ack.html
new file mode 100644
index 000000000..43a150cae
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_ack.html
@@ -0,0 +1 @@
+{% if incident.acked %}Acked{% else %}Unacked{% endif %}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_pk.html b/src/argus_htmx/templates/htmx/incidents/_incident_pk.html
index 6fb14aa51..65cd57aeb 100644
--- a/src/argus_htmx/templates/htmx/incidents/_incident_pk.html
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_pk.html
@@ -1 +1 @@
-{{ incident.pk }}
+{{ incident.pk }}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_row.html b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
index c3da9cad3..f5eb24594 100644
--- a/src/argus_htmx/templates/htmx/incidents/_incident_row.html
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
@@ -1,14 +1,18 @@
HTMX-app
-
{% block incident_pk %}
{% include "htmx/incidents/_incident_pk.html" %}
{% endblock %}
+ {% block status %}
+ {% include "htmx/incidents/_incident_status.html" %}
+ {% endblock %}
+ {% block acknowledgement %}
+ {% include "htmx/incidents/_incident_ack.html" %}
+ {% endblock %}
{% block start_time %}
{% include "htmx/incidents/_incident_start_time.html" %}
{% endblock %}
{% block description %}
{% include "htmx/incidents/_incident_description.html" %}
{% endblock %}
-
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_status.html b/src/argus_htmx/templates/htmx/incidents/_incident_status.html
new file mode 100644
index 000000000..1ad4e5921
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_status.html
@@ -0,0 +1 @@
+{% if incident.open %}Open{% else %}Closed{% endif %}
From d57851337c98b8730f1ae9af1ac505102e8638f9 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 10:55:36 +0200
Subject: [PATCH 007/216] Get acks by clicking in ack column
Allows for acking if authenticated.
---
src/argus_htmx/forms.py | 6 +++
.../htmx/incidents/_incident_ack.html | 4 +-
.../htmx/incidents/incident_add_ack.html | 39 +++++++++++++++++++
src/argus_htmx/urls.py | 1 +
src/argus_htmx/views.py | 21 ++++++++--
5 files changed, 67 insertions(+), 4 deletions(-)
create mode 100644 src/argus_htmx/forms.py
create mode 100644 src/argus_htmx/templates/htmx/incidents/incident_add_ack.html
diff --git a/src/argus_htmx/forms.py b/src/argus_htmx/forms.py
new file mode 100644
index 000000000..510dc8283
--- /dev/null
+++ b/src/argus_htmx/forms.py
@@ -0,0 +1,6 @@
+from django import forms
+
+class AckForm(forms.Form):
+ description = forms.CharField()
+ expiration = forms.DateTimeField(required=False)
+
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_ack.html b/src/argus_htmx/templates/htmx/incidents/_incident_ack.html
index 43a150cae..d8d5aaf49 100644
--- a/src/argus_htmx/templates/htmx/incidents/_incident_ack.html
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_ack.html
@@ -1 +1,3 @@
-{% if incident.acked %}Acked{% else %}Unacked{% endif %}
+
+ {% if incident.acked %}Acked{% else %}Unacked{% endif %}
+
diff --git a/src/argus_htmx/templates/htmx/incidents/incident_add_ack.html b/src/argus_htmx/templates/htmx/incidents/incident_add_ack.html
new file mode 100644
index 000000000..a614c64de
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/incident_add_ack.html
@@ -0,0 +1,39 @@
+{% extends "htmx/base.html" %}
+
+{% block main %}
+Add ack
+
+{% block list_of_acks %}
+
+Acks
+{% for ack in incident.acks %}
+Description: {{ ack.event.description }}
+Expiration: {{ ack.expiration }}
+Acked by: {{ ack.event.actor }}
+{% if ack.event.actor.groups.exists %}
+
Groups:
+{% for group in ack.event.actor.groups.all %}
+{{ group }}
+{% endfor %}
+
+{% endif %}
+
+{% endfor %}
+
+{% endblock list_of_acks %}
+
+{% block add_ack %}
+
+Add ack
+{% if request.user.is_authenticated %}
+
+{% else %}
+You need to Log in
+{% endif %}
+
+{% endblock add_ack %}
+{% endblock main %}
diff --git a/src/argus_htmx/urls.py b/src/argus_htmx/urls.py
index d18721d29..5d8f908a1 100644
--- a/src/argus_htmx/urls.py
+++ b/src/argus_htmx/urls.py
@@ -7,4 +7,5 @@
urlpatterns = [
path("incidents/", views.incidents, name="htmx_incidents"),
path("incidents//", views.incident_detail, name="htmx_incident_detail"),
+ path("incidents//ack/", views.incident_add_ack, name="htmx-incident-add-ack"),
]
diff --git a/src/argus_htmx/views.py b/src/argus_htmx/views.py
index 9e478f029..bf450222b 100644
--- a/src/argus_htmx/views.py
+++ b/src/argus_htmx/views.py
@@ -5,6 +5,8 @@
from argus.incident.models import Incident
+from .forms import AckForm
+
LOG = logging.getLogger(__name__)
@@ -34,6 +36,19 @@ def incident_detail(request, pk: int):
}
return render(request, "htmx/incidents/incident_detail.html", context=context)
-
-#
-# incident.tags.key
+def incident_add_ack(request, pk: int):
+ incident = get_object_or_404(Incident, id=pk)
+ context = {
+ "form": AckForm,
+ "incident": incident,
+ "page_title": str(incident),
+ }
+ if request.POST:
+ form = AckForm(request.POST)
+ if form.is_valid():
+ incident.create_ack(
+ request.user,
+ description=form.cleaned_data["description"],
+ expiration=form.cleaned_data["expiration"],
+ )
+ return render(request, "htmx/incidents/incident_add_ack.html", context=context)
From 529b83da817df4fc5370e23bce0c6ff7862ddfc7 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 12:25:42 +0200
Subject: [PATCH 008/216] Add group handling to incident_add_ack view
---
src/argus_htmx/views.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/argus_htmx/views.py b/src/argus_htmx/views.py
index bf450222b..9c58539ad 100644
--- a/src/argus_htmx/views.py
+++ b/src/argus_htmx/views.py
@@ -1,6 +1,9 @@
import logging
+from typing import Optional
from django.conf import settings
+from django.contrib.auth.models import Group
+from django.core.exceptions import PermissionDenied
from django.shortcuts import render, reverse, get_object_or_404
from argus.incident.models import Incident
@@ -36,14 +39,22 @@ def incident_detail(request, pk: int):
}
return render(request, "htmx/incidents/incident_detail.html", context=context)
-def incident_add_ack(request, pk: int):
+def incident_add_ack(request, pk: int, group: Optional[str] = None):
incident = get_object_or_404(Incident, id=pk)
+ is_group_member = None
+ if group:
+ group = get_object_or_404(Group, name=group)
+ is_group_member = request.user.groups.filter(pk=group.pk).exists()
context = {
"form": AckForm,
"incident": incident,
"page_title": str(incident),
+ 'group': group,
+ 'is_group_member': is_group_member,
}
if request.POST:
+ if group and not is_group_member:
+ raise PermissionDenied("User {request.user} is not a member of the correct group")
form = AckForm(request.POST)
if form.is_valid():
incident.create_ack(
From be2263b24c517d4484910ba602a541e0a5b0858f Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 13:12:41 +0200
Subject: [PATCH 009/216] Show tags in incident list and detail
* Add "tagvalues" template tag. Needs SQL optimization.
---
.../templates/htmx/incidents/_incident_row.html | 3 +++
.../templates/htmx/incidents/_incident_tag.html | 2 ++
.../templates/htmx/incidents/incident_detail.html | 6 +++---
src/argus_htmx/templatetags/__init__.py | 0
src/argus_htmx/templatetags/argus_htmx.py | 14 ++++++++++++++
5 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 src/argus_htmx/templates/htmx/incidents/_incident_tag.html
create mode 100644 src/argus_htmx/templatetags/__init__.py
create mode 100644 src/argus_htmx/templatetags/argus_htmx.py
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_row.html b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
index f5eb24594..25a2a8d5d 100644
--- a/src/argus_htmx/templates/htmx/incidents/_incident_row.html
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_row.html
@@ -9,6 +9,9 @@
{% block acknowledgement %}
{% include "htmx/incidents/_incident_ack.html" %}
{% endblock %}
+ {% block tag %}
+ {% include "htmx/incidents/_incident_tag.html" with tag="location" %}
+ {% endblock %}
{% block start_time %}
{% include "htmx/incidents/_incident_start_time.html" %}
{% endblock %}
diff --git a/src/argus_htmx/templates/htmx/incidents/_incident_tag.html b/src/argus_htmx/templates/htmx/incidents/_incident_tag.html
new file mode 100644
index 000000000..a997b34bc
--- /dev/null
+++ b/src/argus_htmx/templates/htmx/incidents/_incident_tag.html
@@ -0,0 +1,2 @@
+{% load argus_htmx %}
+{{ incident|tagvalues:tag|first }}
diff --git a/src/argus_htmx/templates/htmx/incidents/incident_detail.html b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
index d9bc73ac3..e0f85451f 100644
--- a/src/argus_htmx/templates/htmx/incidents/incident_detail.html
+++ b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
@@ -16,9 +16,9 @@ Status
diff --git a/src/argus_htmx/templatetags/__init__.py b/src/argus_htmx/templatetags/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/argus_htmx/templatetags/argus_htmx.py b/src/argus_htmx/templatetags/argus_htmx.py
new file mode 100644
index 000000000..4e8ce4be8
--- /dev/null
+++ b/src/argus_htmx/templatetags/argus_htmx.py
@@ -0,0 +1,14 @@
+from django import template
+
+
+register = template.Library()
+
+
+@register.filter
+def tagvalues(incident, key) -> list:
+ """Return values of tags with key KEY for incident INCIDENT
+
+ There can be multiple tags with the same key
+ """
+ tags = incident.deprecated_tags
+ return [str(tag.value) for tag in tags]
From f94713fe0c70ee4ccaf7a4f11a66c3260bcd4dc1 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 13:16:43 +0200
Subject: [PATCH 010/216] Improve incident detail level and status
---
.../templates/htmx/incidents/incident_detail.html | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/argus_htmx/templates/htmx/incidents/incident_detail.html b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
index e0f85451f..67bbdb4a8 100644
--- a/src/argus_htmx/templates/htmx/incidents/incident_detail.html
+++ b/src/argus_htmx/templates/htmx/incidents/incident_detail.html
@@ -7,9 +7,14 @@ {{ incident.pk }}: {{ incident.description }}
Status
+{% if incident.open %}Open{% else %}Closed{% endif %}
+
+
+
+
+Level
+
{{ incident.level }}
-{{ incident.is_open }}
-{{ incident.ticket_url }}
From 655ca4fdfb4be0f3a0b20b4cd184a6269be0def0 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 14:25:41 +0200
Subject: [PATCH 011/216] Remove unused template
---
src/argus_htmx/templates/base.html | 17 -----------------
1 file changed, 17 deletions(-)
delete mode 100644 src/argus_htmx/templates/base.html
diff --git a/src/argus_htmx/templates/base.html b/src/argus_htmx/templates/base.html
deleted file mode 100644
index 50a363847..000000000
--- a/src/argus_htmx/templates/base.html
+++ /dev/null
@@ -1,17 +0,0 @@
-{% load static %}
-
-
-
-
- Argus Server: {{ page_title }}
-
- {% block head %}
- {% endblock head %}
-
-
- Argus Server: {{ page_title }}
- {% block main %}
- {% endblock main %}
- {% block tail %}{% endblock tail %}
-
-
From afb77ee9e12c0d88321a15d076fcc0b6a5c80dd5 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Tue, 30 Apr 2024 15:05:51 +0200
Subject: [PATCH 012/216] Override in base.html
* Do some minimal styling
* Add some placeholders for things to come
* Add login and logout links
It is not possible to correctly log out from OAuth2 yet
---
src/argus_htmx/templates/htmx/base.html | 26 +++++++++++++++++++
.../templates/registration/login.html | 18 +++++++++++++
src/argus_htmx/urls.py | 13 +++++++++-
src/argus_htmx/views.py | 4 +++
4 files changed, 60 insertions(+), 1 deletion(-)
create mode 100644 src/argus_htmx/templates/registration/login.html
diff --git a/src/argus_htmx/templates/htmx/base.html b/src/argus_htmx/templates/htmx/base.html
index 703b4e8d1..a8a387d5a 100644
--- a/src/argus_htmx/templates/htmx/base.html
+++ b/src/argus_htmx/templates/htmx/base.html
@@ -1,7 +1,33 @@
{% extends "base.html" %}
{% block head %}
+
{% endblock head %}
+
+{% block header %}
+
+{% endblock header %}
diff --git a/src/argus_htmx/templates/registration/login.html b/src/argus_htmx/templates/registration/login.html
new file mode 100644
index 000000000..78c4ec9b1
--- /dev/null
+++ b/src/argus_htmx/templates/registration/login.html
@@ -0,0 +1,18 @@
+{% extends "htmx/base.html" %}
+
+{% block main %}
+Log In
+
+
+Federated logins
+{% for backend in oauth2_backends %}
+{{ backend }}
+{% endfor %}
+
+{% endblock main %}
diff --git a/src/argus_htmx/urls.py b/src/argus_htmx/urls.py
index 5d8f908a1..93bd7a1a8 100644
--- a/src/argus_htmx/urls.py
+++ b/src/argus_htmx/urls.py
@@ -1,10 +1,21 @@
-from django.urls import path
+from django.urls import path, include
+from django.contrib.auth import views as auth_views
+
+from argus.auth.utils import get_psa_authentication_names
+from argus.auth.views import LogoutView
from . import views
app_name = "htmx"
urlpatterns = [
+ path(
+ "accounts/login/",
+ auth_views.LoginView.as_view(extra_context={"oauth2_backends": get_psa_authentication_names()}),
+ name="login",
+ ),
+ path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
+ #path("accounts/", include("django.contrib.auth.urls")),
path("incidents/", views.incidents, name="htmx_incidents"),
path("incidents//", views.incident_detail, name="htmx_incident_detail"),
path("incidents//ack/", views.incident_add_ack, name="htmx-incident-add-ack"),
diff --git a/src/argus_htmx/views.py b/src/argus_htmx/views.py
index 9c58539ad..012d9a83f 100644
--- a/src/argus_htmx/views.py
+++ b/src/argus_htmx/views.py
@@ -63,3 +63,7 @@ def incident_add_ack(request, pk: int, group: Optional[str] = None):
expiration=form.cleaned_data["expiration"],
)
return render(request, "htmx/incidents/incident_add_ack.html", context=context)
+
+
+# def login(request):
+#
From a45e96061a1c33a063e6467f280c5f3d3fa4677e Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Fri, 3 May 2024 13:09:31 +0200
Subject: [PATCH 013/216] Add classifier to underline instability of code
---
pyproject.toml | 1 +
1 file changed, 1 insertion(+)
diff --git a/pyproject.toml b/pyproject.toml
index a03958c0d..5bddd47e3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,6 +9,7 @@ readme = "README.rst"
authors = [{name = "Hanne Moa", email = "hanne.moa@sikt.no"}]
requires-python = ">=3.8"
classifiers = [
+ "Development Status :: 2 - Pre-Alpha",
"Framework :: Django",
"Framework :: Django :: 4.2",
"Programming Language :: Python :: 3 :: Only",
From 5a55b2655bbe2876017cd2dc726f4ad1b67cf5b0 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Fri, 3 May 2024 13:33:08 +0200
Subject: [PATCH 014/216] Switch to better names for import vs. install
---
pyproject.toml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/pyproject.toml b/pyproject.toml
index 5bddd47e3..df3a75b87 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
[project]
description = "HTTP Frontend as a django app for argus-server using HTMx"
-name = "argus_htmx"
+name = "argus-htmx-frontend"
readme = "README.rst"
authors = [{name = "Hanne Moa", email = "hanne.moa@sikt.no"}]
requires-python = ">=3.8"
@@ -26,3 +26,6 @@ Github = "https://github.com/Uninett/argus-htmx-frontend"
[project.optional-dependencies]
docs = ["sphinx"]
+
+[tool.flit.module]
+name = "argus_htmx"
From b60890472b8733ff57f508bc95c190877144d7f2 Mon Sep 17 00:00:00 2001
From: Hanne Moa
Date: Wed, 15 May 2024 08:19:04 +0200
Subject: [PATCH 015/216] Add theme-switching support
* Support primitive theme switching
* Add two context processors for theming: theme via GET, theme via session
* Update readme
---
README.rst | 10 ++++++++-
src/argus_htmx/context_processors.py | 19 +++++++++++++++++
src/argus_htmx/static/color-schemes/blue.css | 7 +++++++
src/argus_htmx/static/color-schemes/dark.css | 7 +++++++
src/argus_htmx/static/color-schemes/light.css | 7 +++++++
src/argus_htmx/templates/htmx/base.html | 21 +++++++++++++++++--
src/argus_htmx/views.py | 4 +++-
7 files changed, 71 insertions(+), 4 deletions(-)
create mode 100644 src/argus_htmx/context_processors.py
create mode 100644 src/argus_htmx/static/color-schemes/blue.css
create mode 100644 src/argus_htmx/static/color-schemes/dark.css
create mode 100644 src/argus_htmx/static/color-schemes/light.css
diff --git a/README.rst b/README.rst
index b3e1a2e98..ebb6d49e5 100644
--- a/README.rst
+++ b/README.rst
@@ -45,6 +45,11 @@ In your local settings that star-imports from an `argus-server`_ settings file::
ROOT_URLCONF = "urls.py"
MIDDLEWARE += ["django_htmx.middleware.HtmxMiddleware"]
+In the same file, add a copy of the entirety of ``TEMPLATES``. Choose one of
+the functions in ``argus_htmx.context_processors``. In the entry for
+``django.template.backends.django.DjangoTemplates``, append the full dotted
+path to the end of the ``context_processors`` list.
+
Next to ``localsettings.py`` create an ``urls.py`` containing::
from argus.site.urls import urlpatterns
@@ -56,9 +61,12 @@ Next to ``localsettings.py`` create an ``urls.py`` containing::
With EXTRA_APPS
~~~~~~~~~~~~~~~
+Choose one of the functions in ``argus_htmx.context_processors``, exemplified
+by "theme_via_GET" below.
+
In your environment variables::
- ARGUS_EXTRA_APPS = '[{"app_name": "django_htmx"},{"app_name": "argus_htmx","urls": {"path": "", "urlpatterns_module": "argus_htmx.urls"}}]'
+ ARGUS_EXTRA_APPS = '[{"app_name": "django_htmx"}, {"app_name": "argus_htmx", "urls": {"path": "", "urlpatterns_module": "argus_htmx.urls"}, "context_processors": ["arguss_htmx.context_processor.theme_via_GET"]}]'
In your local settings that star-imports from an `argus-server`_ settings file::
diff --git a/src/argus_htmx/context_processors.py b/src/argus_htmx/context_processors.py
new file mode 100644
index 000000000..1d81d1032
--- /dev/null
+++ b/src/argus_htmx/context_processors.py
@@ -0,0 +1,19 @@
+"""
+This should probably be in a separate 3rd party theming-app!
+
+How to use:
+
+Update the "context_processors" list for the TEMPLATES-backend
+``django.template.backends.django.DjangoTemplates`` with *one* of these.
+
+See django settings for ``TEMPLATES``.
+"""
+
+def theme_via_GET(request):
+ theme = request.GET.get("theme", None)
+ return {"theme": theme}
+
+
+def theme_via_session(request):
+ theme = request.session.get("theme", None)
+ return {"theme": theme}
diff --git a/src/argus_htmx/static/color-schemes/blue.css b/src/argus_htmx/static/color-schemes/blue.css
new file mode 100644
index 000000000..21dce662d
--- /dev/null
+++ b/src/argus_htmx/static/color-schemes/blue.css
@@ -0,0 +1,7 @@
+:root {
+ --main-bg-color: lightblue;
+ --main-fg-color: darkblue;
+ --main-link-color: blue;
+ --nav-bg-color: darkblue;
+ --nav-fg-color: cyan;
+}
diff --git a/src/argus_htmx/static/color-schemes/dark.css b/src/argus_htmx/static/color-schemes/dark.css
new file mode 100644
index 000000000..3afd9bd11
--- /dev/null
+++ b/src/argus_htmx/static/color-schemes/dark.css
@@ -0,0 +1,7 @@
+:root {
+ --main-bg-color: #121212;
+ --main-fg-color: #eee;
+ --main-link-color: #809fff;
+ --nav-bg-color: black;
+ --nav-fg-color: #eee;
+}
diff --git a/src/argus_htmx/static/color-schemes/light.css b/src/argus_htmx/static/color-schemes/light.css
new file mode 100644
index 000000000..935cd6647
--- /dev/null
+++ b/src/argus_htmx/static/color-schemes/light.css
@@ -0,0 +1,7 @@
+:root {
+ --main-bg-color: white;
+ --main-fg-color: black;
+ --main-link-color: blue;
+ --nav-bg-color: lightgrey;
+ --nav-fg-color: black;
+}
diff --git a/src/argus_htmx/templates/htmx/base.html b/src/argus_htmx/templates/htmx/base.html
index a8a387d5a..00be1081f 100644
--- a/src/argus_htmx/templates/htmx/base.html
+++ b/src/argus_htmx/templates/htmx/base.html
@@ -2,14 +2,30 @@
{% block head %}
+{% if theme %}
+
+{% else %}
+
+
+{% endif %}
{% endblock head %}
@@ -19,6 +35,7 @@ Logo Argus: {{ page_title }}
Timeslots
Profiles
{% block userlink %}
+Theme: "{{ theme }}"
{% if request.user.is_authenticated %}
{{ request.user }}