From 6efb75ae84452819ff561ab923153838c17317e9 Mon Sep 17 00:00:00 2001 From: Adam Cox Date: Tue, 6 Oct 2026 13:05:56 -0500 Subject: [PATCH] adds a section to list users' api keys --- ohmg/accounts/models.py | 7 +++- ohmg/accounts/urls.py | 3 +- ohmg/accounts/views.py | 15 ++++++++ ohmg/frontend/static/css/site_base.css | 22 ++++++++++- ohmg/frontend/templates/_navbar.html | 7 +++- .../frontend/templates/accounts/api-keys.html | 38 +++++++++++++++++++ .../templates/allauth/layouts/base.html | 15 +++++--- 7 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 ohmg/frontend/templates/accounts/api-keys.html diff --git a/ohmg/accounts/models.py b/ohmg/accounts/models.py index afd0a488..0ba61356 100644 --- a/ohmg/accounts/models.py +++ b/ohmg/accounts/models.py @@ -30,7 +30,12 @@ def profile_url(self): @cached_property def api_keys(self): - return [i for i in APIKey.objects.filter(account=self).values_list("value", flat=True)] + return [ + i + for i in APIKey.objects.filter(account=self).values_list( + "value", "active", "request_count" + ) + ] def update_sesh_counts(self): self.load_ct = Map.objects.filter(loaded_by=self).count() diff --git a/ohmg/accounts/urls.py b/ohmg/accounts/urls.py index 495935fe..718fb25e 100644 --- a/ohmg/accounts/urls.py +++ b/ohmg/accounts/urls.py @@ -1,10 +1,11 @@ from django.urls import include, path -from .views import OHMGSignupView, ProfilesView, ProfileView +from .views import APIKeysView, OHMGSignupView, ProfilesView, ProfileView urlpatterns = [ ## overwrite the default allauth signup view here path("account/signup/", OHMGSignupView.as_view(), name="account_signup"), + path("account/api-keys/", APIKeysView.as_view(), name="api_keys"), path("account/", include("allauth.urls")), path("profile//", ProfileView.as_view(), name="profile_detail"), path("profiles/", ProfilesView.as_view(), name="profiles"), diff --git a/ohmg/accounts/views.py b/ohmg/accounts/views.py index 8bf1d186..03fb17d7 100644 --- a/ohmg/accounts/views.py +++ b/ohmg/accounts/views.py @@ -64,3 +64,18 @@ def form_valid(self, form): if not verify_prosopo_token(token): raise ValidationError("Invalid token", code="invalid") return super(self.__class__, self).form_valid(form) + + +class APIKeysView(View): + def get(self, request): + ohmg_context = generate_ohmg_context(request) + return render( + request, + "accounts/api-keys.html", + context={ + "CONTEXT": ohmg_context, + "PROFILES_PROPS": { + "CONTEXT": ohmg_context, + }, + }, + ) diff --git a/ohmg/frontend/static/css/site_base.css b/ohmg/frontend/static/css/site_base.css index cfe52e5e..64171b35 100644 --- a/ohmg/frontend/static/css/site_base.css +++ b/ohmg/frontend/static/css/site_base.css @@ -52,8 +52,26 @@ img { } table { - border-spacing: 0; - width: 100%; + min-width: 100%; + border: 1px solid #ddd; +} + +table caption { + color: #333; + text-align: center; +} + +th, +td { + padding: 4px; +} + +tr:nth-child(even) { + background-color: #f6f6f6; +} + +tr:nth-child(odd) { + background-color: #ffffff; } pre { diff --git a/ohmg/frontend/templates/_navbar.html b/ohmg/frontend/templates/_navbar.html index 5a51afeb..c15bf3d7 100644 --- a/ohmg/frontend/templates/_navbar.html +++ b/ohmg/frontend/templates/_navbar.html @@ -44,14 +44,17 @@