Skip to content

Commit

Permalink
Style the Admin Panel with a modern theme and Khoj branding
Browse files Browse the repository at this point in the history
Overview
- The default django admin panel UI looks pretty dated and didn't
  have any Khoj specific branding
- Used the Unfold Django admin panel theme for a modern look
- Used the Khoj logo and name in Admin panel title, headings, favicons

Details:
All models shown on Admin panel need to inherit from unfold's
ModelAdmin to get styling applied. So

- Make all models on Admin panel inherit from unfold's ModelAdmin
- Subclassed UserAdmin to inherit from unfold's ModelAdmin
- Deregistered the unused Auth Group model from the Admin panel
  We can add it back when its actually used. Avoid confusion for now
- Explicitly register DjangoJobExecution on admin panel and again make
  it inherit from the unfold.admin.ModelAdmin
  • Loading branch information
debanjum committed Dec 4, 2024
1 parent 9f7cb33 commit c3a89fa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies = [
"anyio == 3.7.1",
"pymupdf == 1.24.11",
"django == 5.0.9",
"django-unfold == 0.42.0",
"authlib == 1.2.1",
"llama-cpp-python == 0.2.88",
"itsdangerous == 2.1.2",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/khoj/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import os
from pathlib import Path

from django.templatetags.static import static

from khoj.utils.helpers import in_debug_mode, is_env_var_true

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -72,6 +74,7 @@
"django.contrib.auth",
"django.contrib.contenttypes",
"khoj.database.apps.DatabaseConfig",
"unfold",
"django.contrib.admin",
"django.contrib.sessions",
"django.contrib.messages",
Expand Down Expand Up @@ -195,3 +198,21 @@
# that supports multiple background worker processes instead (e.g. Dramatiq, Celery, Django-RQ,
# etc. See: https://djangopackages.org/grids/g/workers-queues-tasks/ for popular options).
APSCHEDULER_RUN_NOW_TIMEOUT = 240 # Seconds

UNFOLD = {
"SITE_TITLE": "Khoj Admin Panel",
"SITE_HEADER": "Khoj Admin Panel",
"SITE_URL": "/",
"SITE_ICON": {
"light": lambda request: static("assets/icons/khoj_lantern_128x128.png"),
"dark": lambda request: static("assets/icons/khoj_lantern_128x128_dark.png"),
},
"SITE_FAVICONS": [
{
"rel": "icon",
"sizes": "32x32",
"type": "image/svg+xml",
"href": lambda request: static("assets/icons/khoj_lantern.svg"),
},
],
}
71 changes: 44 additions & 27 deletions src/khoj/database/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from apscheduler.job import Job
from django.contrib import admin, messages
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import Group
from django.http import HttpResponse
from django_apscheduler.admin import DjangoJobAdmin
from django_apscheduler.admin import DjangoJobAdmin, DjangoJobExecutionAdmin
from django_apscheduler.jobstores import DjangoJobStore
from django_apscheduler.models import DjangoJob
from django_apscheduler.models import DjangoJob, DjangoJobExecution
from unfold import admin as unfold_admin

from khoj.database.models import (
Agent,
Expand All @@ -35,10 +38,8 @@
)
from khoj.utils.helpers import ImageIntentType

admin.site.unregister(DjangoJob)


class KhojDjangoJobAdmin(DjangoJobAdmin):
class KhojDjangoJobAdmin(DjangoJobAdmin, unfold_admin.ModelAdmin):
list_display = (
"id",
"next_run_time",
Expand All @@ -62,10 +63,25 @@ def get_search_results(self, request, queryset, search_term):
return queryset, use_distinct


class KhojDjangoJobExecutionAdmin(DjangoJobExecutionAdmin, unfold_admin.ModelAdmin):
pass


admin.site.unregister(DjangoJob)
admin.site.register(DjangoJob, KhojDjangoJobAdmin)
admin.site.unregister(DjangoJobExecution)
admin.site.register(DjangoJobExecution, KhojDjangoJobExecutionAdmin)


class GroupAdmin(BaseGroupAdmin, unfold_admin.ModelAdmin):
pass


class UserAdmin(BaseUserAdmin, unfold_admin.ModelAdmin):
pass


class KhojUserAdmin(UserAdmin):
class KhojUserAdmin(UserAdmin, unfold_admin.ModelAdmin):
class DateJoinedAfterFilter(admin.SimpleListFilter):
title = "Joined after"
parameter_name = "joined_after"
Expand Down Expand Up @@ -137,21 +153,22 @@ def get_email_login_url(self, request, queryset):
get_email_login_url.short_description = "Get email login URL" # type: ignore


admin.site.unregister(Group)
admin.site.register(KhojUser, KhojUserAdmin)

admin.site.register(ProcessLock)
admin.site.register(SpeechToTextModelOptions)
admin.site.register(ReflectiveQuestion)
admin.site.register(ClientApplication)
admin.site.register(GithubConfig)
admin.site.register(NotionConfig)
admin.site.register(UserVoiceModelConfig)
admin.site.register(VoiceModelOption)
admin.site.register(UserRequests)
admin.site.register(ProcessLock, unfold_admin.ModelAdmin)
admin.site.register(SpeechToTextModelOptions, unfold_admin.ModelAdmin)
admin.site.register(ReflectiveQuestion, unfold_admin.ModelAdmin)
admin.site.register(ClientApplication, unfold_admin.ModelAdmin)
admin.site.register(GithubConfig, unfold_admin.ModelAdmin)
admin.site.register(NotionConfig, unfold_admin.ModelAdmin)
admin.site.register(UserVoiceModelConfig, unfold_admin.ModelAdmin)
admin.site.register(VoiceModelOption, unfold_admin.ModelAdmin)
admin.site.register(UserRequests, unfold_admin.ModelAdmin)


@admin.register(Agent)
class AgentAdmin(admin.ModelAdmin):
class AgentAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"name",
Expand All @@ -161,7 +178,7 @@ class AgentAdmin(admin.ModelAdmin):


@admin.register(Entry)
class EntryAdmin(admin.ModelAdmin):
class EntryAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"created_at",
Expand All @@ -183,7 +200,7 @@ class EntryAdmin(admin.ModelAdmin):


@admin.register(Subscription)
class KhojUserSubscription(admin.ModelAdmin):
class KhojUserSubscription(unfold_admin.ModelAdmin):
list_display = (
"id",
"user",
Expand All @@ -195,7 +212,7 @@ class KhojUserSubscription(admin.ModelAdmin):


@admin.register(ChatModelOptions)
class ChatModelOptionsAdmin(admin.ModelAdmin):
class ChatModelOptionsAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"chat_model",
Expand All @@ -206,7 +223,7 @@ class ChatModelOptionsAdmin(admin.ModelAdmin):


@admin.register(TextToImageModelConfig)
class TextToImageModelOptionsAdmin(admin.ModelAdmin):
class TextToImageModelOptionsAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"model_name",
Expand All @@ -216,7 +233,7 @@ class TextToImageModelOptionsAdmin(admin.ModelAdmin):


@admin.register(OpenAIProcessorConversationConfig)
class OpenAIProcessorConversationConfigAdmin(admin.ModelAdmin):
class OpenAIProcessorConversationConfigAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"name",
Expand All @@ -227,7 +244,7 @@ class OpenAIProcessorConversationConfigAdmin(admin.ModelAdmin):


@admin.register(SearchModelConfig)
class SearchModelConfigAdmin(admin.ModelAdmin):
class SearchModelConfigAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"name",
Expand All @@ -238,7 +255,7 @@ class SearchModelConfigAdmin(admin.ModelAdmin):


@admin.register(ServerChatSettings)
class ServerChatSettingsAdmin(admin.ModelAdmin):
class ServerChatSettingsAdmin(unfold_admin.ModelAdmin):
list_display = (
"chat_default",
"chat_advanced",
Expand All @@ -247,7 +264,7 @@ class ServerChatSettingsAdmin(admin.ModelAdmin):


@admin.register(WebScraper)
class WebScraperAdmin(admin.ModelAdmin):
class WebScraperAdmin(unfold_admin.ModelAdmin):
list_display = (
"priority",
"name",
Expand All @@ -261,7 +278,7 @@ class WebScraperAdmin(admin.ModelAdmin):


@admin.register(Conversation)
class ConversationAdmin(admin.ModelAdmin):
class ConversationAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"user",
Expand Down Expand Up @@ -367,7 +384,7 @@ def get_actions(self, request):


@admin.register(UserConversationConfig)
class UserConversationConfigAdmin(admin.ModelAdmin):
class UserConversationConfigAdmin(unfold_admin.ModelAdmin):
list_display = (
"id",
"get_user_email",
Expand Down

0 comments on commit c3a89fa

Please sign in to comment.