Skip to content

Commit

Permalink
feat: add logging configuration (#97)
Browse files Browse the repository at this point in the history
* feat: makes characters searchable in admin view

* misc: adds quotes to character name in admin view for improved readability

* feat: adds logging configuration

* fix: fixes unit test file name so it is discovered by test suit

* chore: delete unused file
  • Loading branch information
corp-0 authored Sep 23, 2024
1 parent bb66a17 commit 23a23bb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/central_command/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
import sys

from datetime import timedelta
from pathlib import Path
Expand Down Expand Up @@ -86,6 +87,57 @@
},
]

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "[%(asctime)s] %(levelname)s %(name)s: %(message)s",
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "standard",
"stream": sys.stdout,
}
},
"loggers": {
# root logger
"": {
"handlers": ["console"],
"level": "INFO",
"propagate": True,
},
"django": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
"django.db.backends": {
"handlers": ["console"],
"level": "ERROR",
"propagate": False,
},
"django.utils.autoreload": {
"handlers": ["console"],
"level": "WARNING",
"propagate": False,
},
"accounts": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
"persistence": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
},
}

WSGI_APPLICATION = "central_command.wsgi.application"

# Database
Expand Down
12 changes: 12 additions & 0 deletions src/persistence/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from typing import Tuple

from django.contrib import admin
from django.db.models import Q, QuerySet
from django.http import HttpRequest

from .models import Character


@admin.register(Character)
class CharacterAdminView(admin.ModelAdmin):
readonly_fields = ("character_name", "last_updated")
list_filter = ("character_sheet_version", "account__unique_identifier")
search_fields = ("data__Name__icontains", "account__unique_identifier__icontains", "account__email__icontains")

def get_search_results(self, request: HttpRequest, queryset: QuerySet, search_term: str) -> Tuple[QuerySet, bool]:
queryset, use_distinct = super().get_search_results(request, queryset, search_term)

queryset |= self.model.objects.filter(Q(data__Name__icontains=search_term))
return queryset, use_distinct
Empty file.
2 changes: 1 addition & 1 deletion src/persistence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Character(models.Model):
)

def __str__(self):
return f"{self.character_name} by {self.account.unique_identifier}"
return f'"{self.character_name}" by {self.account.unique_identifier}'

@property
def character_name(self) -> str:
Expand Down

0 comments on commit 23a23bb

Please sign in to comment.