Trying to relocate admin (not working yet)

This commit is contained in:
Griatch 2021-05-16 23:40:31 +02:00
parent 273cc31146
commit 8e02be23e4
15 changed files with 67 additions and 49 deletions

View file

View file

@ -213,12 +213,12 @@ class AccountAttributeInline(AttributeInline):
related_field = "accountdb" related_field = "accountdb"
@admin.register(AccountDB)
class AccountDBAdmin(BaseUserAdmin): class AccountDBAdmin(BaseUserAdmin):
""" """
This is the main creation screen for Users/accounts This is the main creation screen for Users/accounts
""" """
list_display = ("username", "email", "is_staff", "is_superuser") list_display = ("username", "email", "is_staff", "is_superuser")
form = AccountDBChangeForm form = AccountDBChangeForm
add_form = AccountDBCreationForm add_form = AccountDBCreationForm
@ -362,4 +362,4 @@ class AccountDBAdmin(BaseUserAdmin):
return HttpResponseRedirect(reverse("admin:accounts_accountdb_change", args=[obj.id])) return HttpResponseRedirect(reverse("admin:accounts_accountdb_change", args=[obj.id]))
admin.site.register(AccountDB, AccountDBAdmin) # admin.site.register(AccountDB, AccountDBAdmin)

View file

@ -13,12 +13,14 @@ from django.contrib.admin.views.decorators import staff_member_required
def evennia_admin(request): def evennia_admin(request):
""" """
Helpful Evennia-specific admin page. Helpful Evennia-specific admin page.
""" """
return render(request, "evennia_admin.html", {"accountdb": AccountDB}) return render(request, "admin/frontpage.html", {"accountdb": AccountDB})
def admin_wrapper(request): def admin_wrapper(request):
""" """
Wrapper that allows us to properly use the base Django admin site, if needed. Wrapper that allows us to properly use the base Django admin site, if needed.
""" """
return staff_member_required(site.index)(request) return staff_member_required(site.index)(request)

30
evennia/web/admin/urls.py Normal file
View file

@ -0,0 +1,30 @@
"""
Rerouting admin frontpage to evennia version.
These patterns are all under the admin/* namespace.
"""
from django.conf import settings
from django.contrib import admin
from django.conf.urls import url, include
from . import frontpage
urlpatterns = [
# Django original admin page. Make this URL is always available, whether
# we've chosen to use Evennia's custom admin or not.
url(r"/django/", frontpage.admin_wrapper, name="django_admin"),
# Admin docs
url(r"/doc/", include("django.contrib.admindocs.urls")),
]
if settings.EVENNIA_ADMIN:
urlpatterns += [
# Our override for the admin.
url("^/$", frontpage.evennia_admin, name="evennia_admin"),
# Makes sure that other admin pages get loaded.
url(r"^/", admin.site.urls),
]
else:
# Just include the normal Django admin.
urlpatterns += [url(r"^/", admin.site.urls)]

View file

@ -16,7 +16,6 @@
<h3>Game entities</h3> <h3>Game entities</h3>
<p class="card-text"> <p class="card-text">
<h4><a href="{% url "admin:accounts_accountdb_changelist" %}">Accounts</a></h4> <h4><a href="{% url "admin:accounts_accountdb_changelist" %}">Accounts</a></h4>
Accounts can have several characters under them. A user's login and Accounts can have several characters under them. A user's login and

View file

@ -30,6 +30,8 @@ urlpatterns = [
path("", include("evennia.web.website.urls")), path("", include("evennia.web.website.urls")),
# webclient # webclient
path("webclient/", include("evennia.web.webclient.urls")), path("webclient/", include("evennia.web.webclient.urls")),
# admin
path("admin", include("evennia.web.admin.urls")),
# favicon # favicon
path("favicon.ico", RedirectView.as_view(url="/media/images/favicon.ico", permanent=False)), path("favicon.ico", RedirectView.as_view(url="/media/images/favicon.ico", permanent=False)),
] ]

View file

@ -1,15 +1,26 @@
# """
# This file defines global variables that will always be This file defines global variables that will always be available in a view
# available in a view context without having to repeatedly context without having to repeatedly include it.
# include it. For this to work, this file is included in
# the settings file, in the TEMPLATE_CONTEXT_PROCESSORS For this to work, this file is included in the settings file, in the
# tuple. TEMPLATE_CONTEXT_PROCESSORS tuple.
#
"""
import os import os
from django.conf import settings from django.conf import settings
from evennia.utils.utils import get_evennia_version from evennia.utils.utils import get_evennia_version
# Setup lists of the most relevant apps so
# the adminsite becomes more readable.
ACCOUNT_RELATED = ["Accounts"]
GAME_ENTITIES = ["Objects", "Scripts", "Comms", "Help"]
GAME_SETUP = ["Permissions", "Config"]
CONNECTIONS = ["Irc"]
WEBSITE = ["Flatpages", "News", "Sites"]
# Determine the site name and server version # Determine the site name and server version
def set_game_name_and_slogan(): def set_game_name_and_slogan():
""" """
@ -18,6 +29,7 @@ def set_game_name_and_slogan():
Notes: Notes:
This function is used for unit testing the values of the globals. This function is used for unit testing the values of the globals.
""" """
global GAME_NAME, GAME_SLOGAN, SERVER_VERSION global GAME_NAME, GAME_SLOGAN, SERVER_VERSION
try: try:
@ -31,18 +43,6 @@ def set_game_name_and_slogan():
GAME_SLOGAN = SERVER_VERSION GAME_SLOGAN = SERVER_VERSION
set_game_name_and_slogan()
# Setup lists of the most relevant apps so
# the adminsite becomes more readable.
ACCOUNT_RELATED = ["Accounts"]
GAME_ENTITIES = ["Objects", "Scripts", "Comms", "Help"]
GAME_SETUP = ["Permissions", "Config"]
CONNECTIONS = ["Irc"]
WEBSITE = ["Flatpages", "News", "Sites"]
def set_webclient_settings(): def set_webclient_settings():
""" """
As with set_game_name_and_slogan above, this sets global variables pertaining As with set_game_name_and_slogan above, this sets global variables pertaining
@ -50,6 +50,7 @@ def set_webclient_settings():
Notes: Notes:
Used for unit testing. Used for unit testing.
""" """
global WEBCLIENT_ENABLED, WEBSOCKET_CLIENT_ENABLED, WEBSOCKET_PORT, WEBSOCKET_URL global WEBCLIENT_ENABLED, WEBSOCKET_CLIENT_ENABLED, WEBSOCKET_PORT, WEBSOCKET_URL
WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED
@ -64,13 +65,15 @@ def set_webclient_settings():
WEBSOCKET_URL = settings.WEBSOCKET_CLIENT_URL WEBSOCKET_URL = settings.WEBSOCKET_CLIENT_URL
set_game_name_and_slogan()
set_webclient_settings() set_webclient_settings()
# The main context processor function # The main context processor function
def general_context(request): def general_context(request):
""" """
Returns common Evennia-related context stuff, which Returns common Evennia-related context stuff, which is automatically added
is automatically added to context of all views. to context of all views.
""" """
account = None account = None
if request.user.is_authenticated: if request.user.is_authenticated:

View file

@ -7,7 +7,7 @@ from django.contrib import admin
from django.conf.urls import url, include from django.conf.urls import url, include
from django import views as django_views from django import views as django_views
from .views import (index, errors, accounts, help as helpviews, channels, from .views import (index, errors, accounts, help as helpviews, channels,
characters, admin as adminviews) characters)
urlpatterns = [ urlpatterns = [
# website front page # website front page
@ -52,26 +52,8 @@ urlpatterns = [
url(r"^characters/delete/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$", url(r"^characters/delete/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$",
characters.CharacterDeleteView.as_view(), characters.CharacterDeleteView.as_view(),
name="character-delete"), name="character-delete"),
# Django original admin page. Make this URL is always available, whether
# we've chosen to use Evennia's custom admin or not.
url(r"django_admin/", adminviews.admin_wrapper, name="django_admin"),
# Admin docs
url(r"^admin/doc/", include("django.contrib.admindocs.urls")),
] ]
if settings.EVENNIA_ADMIN:
urlpatterns += [
# Our override for the admin.
url("^admin/$", adminviews.evennia_admin, name="evennia_admin"),
# Makes sure that other admin pages get loaded.
url(r"^admin/", admin.site.urls),
]
else:
# Just include the normal Django admin.
urlpatterns += [url(r"^admin/", admin.site.urls)]
# This sets up the server if the user want to run the Django # This sets up the server if the user want to run the Django
# test server (this should normally not be needed). # test server (this should normally not be needed).

View file

@ -22,7 +22,7 @@ def _gamestats():
fpage_account_limit = 4 fpage_account_limit = 4
# A QuerySet of the most recently connected accounts. # A QuerySet of the most recently connected accounts.
recent_users = AccountDB.objects.get_recently_connected_accounts()[:fpage_account_limit] recent_users = AccountDB.objects.get_recently_connected_accounts()
nplyrs_conn_recent = len(recent_users) or "none" nplyrs_conn_recent = len(recent_users) or "none"
nplyrs = AccountDB.objects.num_total_accounts() or "none" nplyrs = AccountDB.objects.num_total_accounts() or "none"
nplyrs_reg_recent = len(AccountDB.objects.get_recently_created_accounts()) or "none" nplyrs_reg_recent = len(AccountDB.objects.get_recently_created_accounts()) or "none"
@ -44,7 +44,7 @@ def _gamestats():
pagevars = { pagevars = {
"page_title": "Front Page", "page_title": "Front Page",
"accounts_connected_recent": recent_users, "accounts_connected_recent": recent_users[:fpage_account_limit],
"num_accounts_connected": nsess or "no one", "num_accounts_connected": nsess or "no one",
"num_accounts_registered": nplyrs or "no", "num_accounts_registered": nplyrs or "no",
"num_accounts_connected_recent": nplyrs_conn_recent or "no", "num_accounts_connected_recent": nplyrs_conn_recent or "no",