Trying to relocate admin (not working yet)

This commit is contained in:
Griatch 2021-05-16 23:40:31 +02:00
parent 4e20f624c2
commit a992522439
15 changed files with 67 additions and 49 deletions

View file

@ -288,11 +288,11 @@ DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# default webclient options (without user changing it)
WEBCLIENT_OPTIONS = {
# Gags prompts in output window and puts them on the input bar
"gagprompt": True,
"gagprompt": True,
# Shows help files in a new popup window instead of in-pane
"helppopup": False,
"helppopup": False,
# Shows notifications of new messages as popup windows
"notification_popup": False,
"notification_popup": False,
# Plays a sound for notifications of new messages
"notification_sound": False
}

View file

View file

@ -213,12 +213,12 @@ class AccountAttributeInline(AttributeInline):
related_field = "accountdb"
@admin.register(AccountDB)
class AccountDBAdmin(BaseUserAdmin):
"""
This is the main creation screen for Users/accounts
"""
list_display = ("username", "email", "is_staff", "is_superuser")
form = AccountDBChangeForm
add_form = AccountDBCreationForm
@ -362,4 +362,4 @@ class AccountDBAdmin(BaseUserAdmin):
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):
"""
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):
"""
Wrapper that allows us to properly use the base Django admin site, if needed.
"""
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>
<p class="card-text">
<h4><a href="{% url "admin:accounts_accountdb_changelist" %}">Accounts</a></h4>
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")),
# webclient
path("webclient/", include("evennia.web.webclient.urls")),
# admin
path("admin", include("evennia.web.admin.urls")),
# favicon
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
# available in a view context without having to repeatedly
# include it. For this to work, this file is included in
# the settings file, in the TEMPLATE_CONTEXT_PROCESSORS
# tuple.
#
"""
This file defines global variables that will always be available in a view
context without having to repeatedly include it.
For this to work, this file is included in the settings file, in the
TEMPLATE_CONTEXT_PROCESSORS tuple.
"""
import os
from django.conf import settings
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
def set_game_name_and_slogan():
"""
@ -18,6 +29,7 @@ def set_game_name_and_slogan():
Notes:
This function is used for unit testing the values of the globals.
"""
global GAME_NAME, GAME_SLOGAN, SERVER_VERSION
try:
@ -31,18 +43,6 @@ def set_game_name_and_slogan():
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():
"""
As with set_game_name_and_slogan above, this sets global variables pertaining
@ -50,6 +50,7 @@ def set_webclient_settings():
Notes:
Used for unit testing.
"""
global WEBCLIENT_ENABLED, WEBSOCKET_CLIENT_ENABLED, WEBSOCKET_PORT, WEBSOCKET_URL
WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED
@ -64,13 +65,15 @@ def set_webclient_settings():
WEBSOCKET_URL = settings.WEBSOCKET_CLIENT_URL
set_game_name_and_slogan()
set_webclient_settings()
# The main context processor function
def general_context(request):
"""
Returns common Evennia-related context stuff, which
is automatically added to context of all views.
Returns common Evennia-related context stuff, which is automatically added
to context of all views.
"""
account = None
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 import views as django_views
from .views import (index, errors, accounts, help as helpviews, channels,
characters, admin as adminviews)
characters)
urlpatterns = [
# website front page
@ -52,26 +52,8 @@ urlpatterns = [
url(r"^characters/delete/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$",
characters.CharacterDeleteView.as_view(),
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
# test server (this should normally not be needed).

View file

@ -22,7 +22,7 @@ def _gamestats():
fpage_account_limit = 4
# 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 = AccountDB.objects.num_total_accounts() or "none"
nplyrs_reg_recent = len(AccountDB.objects.get_recently_created_accounts()) or "none"
@ -44,7 +44,7 @@ def _gamestats():
pagevars = {
"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_registered": nplyrs or "no",
"num_accounts_connected_recent": nplyrs_conn_recent or "no",