-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dev mode admin + refactor api init (#7628)
* feat: style admin site in dev mode * refactor: eliminate base_site.html * fix: remove debug * fix: commit missing __init__.py * refactor: make method static; fix tests * refactor: move api init to AppConfig.ready() Avoids interacting with the app registry before it's ready.
- Loading branch information
1 parent
b90820e
commit 95a7e14
Showing
11 changed files
with
85 additions
and
30 deletions.
There are no files selected for viewing
Empty file.
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,6 @@ | ||
# Copyright The IETF Trust 2024, All Rights Reserved | ||
from django.contrib.admin import apps as admin_apps | ||
|
||
|
||
class AdminConfig(admin_apps.AdminConfig): | ||
default_site = "ietf.admin.sites.AdminSite" |
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,15 @@ | ||
# Copyright The IETF Trust 2024, All Rights Reserved | ||
from django.contrib.admin import AdminSite as _AdminSite | ||
from django.conf import settings | ||
from django.utils.safestring import mark_safe | ||
|
||
|
||
class AdminSite(_AdminSite): | ||
site_title = "Datatracker admin" | ||
|
||
@staticmethod | ||
def site_header(): | ||
if settings.SERVER_MODE == "production": | ||
return "Datatracker administration" | ||
else: | ||
return mark_safe('Datatracker administration <span class="text-danger">δ</span>') |
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,15 @@ | ||
from django.apps import AppConfig | ||
from . import populate_api_list | ||
|
||
|
||
class ApiConfig(AppConfig): | ||
name = "ietf.api" | ||
|
||
def ready(self): | ||
"""Hook to do init after the app registry is fully populated | ||
Importing models or accessing the app registry is ok here, but do not | ||
interact with the database. See | ||
https://docs.djangoproject.com/en/4.2/ref/applications/#django.apps.AppConfig.ready | ||
""" | ||
populate_api_list() |
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,27 @@ | ||
{% extends 'admin/base.html' %} | ||
{% load static %} | ||
{% block extrastyle %}{{ block.super }} | ||
{% if server_mode and server_mode != "production" %} | ||
<style> | ||
{# grab colors that match bootstrap so we don't have to import the css #} | ||
html, :root{ | ||
--bs-danger-bg-subtle: #F8D7DAFF; | ||
--bs-danger-text-emphasis: #58151CFF; | ||
--bs-danger: #DC3545FF; | ||
--bs-secondary: #6C757DFF; | ||
--bs-primary-text-emphasis: #052C65FF; | ||
} | ||
html[data-theme="light"], :root { | ||
--primary: var(--bs-danger-bg-subtle); | ||
--secondary: var(--bs-danger-bg-subtle); | ||
--accent: var(--bs-danger-text-emphasis); | ||
--primary-fg: var(--bs-primary-text-emphasis); | ||
--link-fg: var(--bs-danger-text-emphasis); | ||
--header-color: var(--bs-secondary); | ||
--breadcrumbs-fg: var(--bs-secondary); | ||
--breadcrumbs-link-fg: var(--link-fg); | ||
} | ||
span.text-danger { color: var(--bs-danger); } | ||
</style> | ||
{% endif %} | ||
{% endblock %} |
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
|
||
import debug # pyflakes:ignore | ||
|
||
from ietf.admin.sites import AdminSite | ||
from ietf.person.name import name_parts, unidecode_name | ||
from ietf.submit.tests import submission_file | ||
from ietf.utils.draft import PlaintextDraft, getmeta | ||
|
@@ -325,7 +326,7 @@ def test_all_model_admins_exist(self): | |
User.objects.create_superuser('admin', '[email protected]', 'admin+password') | ||
self.client.login(username='admin', password='admin+password') | ||
rtop = self.client.get("/admin/") | ||
self.assertContains(rtop, 'Django administration') | ||
self.assertContains(rtop, AdminSite.site_header()) | ||
for name in self.apps: | ||
app_name = self.apps[name] | ||
self.assertContains(rtop, name) | ||
|