Skip to content

Commit

Permalink
Basic admin skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Mar 26, 2024
1 parent b624bbb commit 0e6c8d2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Django stuff:
staticfiles/
8 changes: 5 additions & 3 deletions scripts/dockerpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ migrate() {

createsuperuser() {
if [ -z "$DJANGO_SUPERUSER_EMAIL" ]; then
echo "DJANGO_SUPERUSER_EMAIL is not set. Will not create a superuser."
else
python manage.py createsuperuser --noinput
# SUPER TOP SECRET (okay, not really)
export DJANGO_SUPERUSER_USERNAME="[email protected]"
export DJANGO_SUPERUSER_EMAIL="[email protected]"
export DJANGO_SUPERUSER_PASSWORD="dev123!"
fi
python manage.py createsuperuser --noinput
}

start() {
Expand Down
18 changes: 18 additions & 0 deletions server/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.contrib import admin
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.contrib.auth.models import Group, User
from django.utils.translation import gettext_lazy as _


class AdminSite(admin.AdminSite):
"""Custom admin site."""

site_title = _("VoterBowl admin")
site_header = _("VoterBowl admin")
index_title = _("VoterBowl admin")


admin_site = AdminSite()
admin_site.enable_nav_sidebar = False
admin_site.register(User, UserAdmin)
admin_site.register(Group, GroupAdmin)
17 changes: 17 additions & 0 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"django_htmx.middleware.HtmxMiddleware",
]

if not DEBUG:
MIDDLEWARE = (
MIDDLEWARE[:1]
+ [
"whitenoise.middleware.WhiteNoiseMiddleware",
]
+ MIDDLEWARE[1:]
)

ROOT_URLCONF = "server.urls"

TEMPLATES = [
Expand Down Expand Up @@ -122,6 +131,14 @@

STATIC_URL = "static/"
STATICFILES_DIRS = [BASE_DIR / "server" / "static"]
STATIC_ROOT = BASE_DIR / "staticfiles"

if not DEBUG:
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
}
}

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
Expand Down
5 changes: 3 additions & 2 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import include, path

from .admin import admin_site

urlpatterns = [
path("__reload__/", include("django_browser_reload.urls")),
path("admin/", admin.site.urls),
path("admin/", admin_site.urls),
path("", include("server.vb.urls")),
]
2 changes: 1 addition & 1 deletion server/vb/templates/base.dhtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
VoterBowl, coming soon.
<div>
<style>
me {
me {
background: blue;
color: white;
}
Expand Down

0 comments on commit 0e6c8d2

Please sign in to comment.