diff options
| author | 2019-10-11 19:53:21 +0200 | |
|---|---|---|
| committer | 2019-10-11 19:53:21 +0200 | |
| commit | 6fa19e09823680c93acd795c52f6f511a1ae9663 (patch) | |
| tree | 28d949d11333753a68d3dca7ad4087da16e234d5 | |
| parent | Pluralize properly. (diff) | |
Use multi-column output from Django.
| -rw-r--r-- | pydis_site/apps/api/admin.py | 1 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/log_entry.py | 11 | ||||
| -rw-r--r-- | pydis_site/apps/api/tests/test_models.py | 21 | 
3 files changed, 1 insertions, 32 deletions
| diff --git a/pydis_site/apps/api/admin.py b/pydis_site/apps/api/admin.py index 2c41d624..8a9b6051 100644 --- a/pydis_site/apps/api/admin.py +++ b/pydis_site/apps/api/admin.py @@ -18,6 +18,7 @@ from .models import (  class LogEntryAdmin(admin.ModelAdmin):      """Allows viewing logs in the Django Admin without allowing edits.""" +    list_display = ('timestamp', 'application', 'level', 'message')      readonly_fields = (          'application',          'logger_name', diff --git a/pydis_site/apps/api/models/log_entry.py b/pydis_site/apps/api/models/log_entry.py index cb7275f9..9717c700 100644 --- a/pydis_site/apps/api/models/log_entry.py +++ b/pydis_site/apps/api/models/log_entry.py @@ -6,10 +6,6 @@ from django.utils import timezone  from pydis_site.apps.api.models.utils import ModelReprMixin -# Used to shorten the timestamp length in the Django Admin. -TIMESTAMP_WITH_SECONDS_LENGTH = len('YYYY-MM-DD HH:MM:SS') - -  class LogEntry(ModelReprMixin, models.Model):      """A log entry generated by one of the PyDis applications.""" @@ -55,13 +51,6 @@ class LogEntry(ModelReprMixin, models.Model):          help_text="The textual content of the log line."      ) -    def __str__(self) -> str: -        timestamp = str(self.timestamp)[:TIMESTAMP_WITH_SECONDS_LENGTH] -        message = textwrap.shorten(self.message, width=140) -        level = self.level[:4].upper() - -        return f'{timestamp} | {self.application} | {level} | {message}' -      class Meta:          """Customizes the default generated plural name to valid English.""" diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 6011ba21..6a3ef085 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -7,7 +7,6 @@ from ..models import (      DeletedMessage,      DocumentationLink,      Infraction, -    LogEntry,      Message,      MessageDeletionContext,      ModelReprMixin, @@ -33,26 +32,6 @@ class ReprMixinTests(SimpleTestCase):          self.assertEqual(repr(self.klass), expected) -class LogEntryStringDunderTests(SimpleTestCase): -    def setUp(self): -        self.entry = LogEntry( -            application='bot', -            logger_name='bot.rules.antispam', -            timestamp=timezone.now(), -            level='debug', -            module='bot.rules.antispam', -            line=44, -            message="One day computers might become useful." -        ) - -    def test_str_shows_content(self): -        tokens = str(self.entry).split(' | ') -        _timestamp, app, level, message = tokens -        self.assertEqual(app, 'bot') -        self.assertEqual(level, 'DEBU'), -        self.assertEqual(message, "One day computers might become useful.") - -  class StringDunderMethodTests(SimpleTestCase):      def setUp(self):          self.objects = ( | 
