From 23a23bb3d327f0dcede4ef6a16ad8eac1a1099d1 Mon Sep 17 00:00:00 2001 From: Gilles <43683714+corp-0@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:14:19 -0300 Subject: [PATCH] feat: add logging configuration (#97) * 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 --- src/central_command/settings.py | 52 +++++++++++++++++++ src/persistence/admin.py | 12 +++++ .../create_test_duplicated_characters.py | 0 src/persistence/models.py | 2 +- ....py => test_nuke_duplicated_characters.py} | 0 5 files changed, 65 insertions(+), 1 deletion(-) delete mode 100644 src/persistence/management/commands/create_test_duplicated_characters.py rename src/tests/persistence/commands/{nuke_duplicated_characters.py => test_nuke_duplicated_characters.py} (100%) diff --git a/src/central_command/settings.py b/src/central_command/settings.py index 09aec74..8fe78b7 100644 --- a/src/central_command/settings.py +++ b/src/central_command/settings.py @@ -11,6 +11,7 @@ """ import os +import sys from datetime import timedelta from pathlib import Path @@ -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 diff --git a/src/persistence/admin.py b/src/persistence/admin.py index 596bbba..53fb3bf 100644 --- a/src/persistence/admin.py +++ b/src/persistence/admin.py @@ -1,4 +1,8 @@ +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 @@ -6,3 +10,11 @@ @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 diff --git a/src/persistence/management/commands/create_test_duplicated_characters.py b/src/persistence/management/commands/create_test_duplicated_characters.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/persistence/models.py b/src/persistence/models.py index 175613c..fc245b2 100644 --- a/src/persistence/models.py +++ b/src/persistence/models.py @@ -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: diff --git a/src/tests/persistence/commands/nuke_duplicated_characters.py b/src/tests/persistence/commands/test_nuke_duplicated_characters.py similarity index 100% rename from src/tests/persistence/commands/nuke_duplicated_characters.py rename to src/tests/persistence/commands/test_nuke_duplicated_characters.py