Skip to content

Commit

Permalink
fix: support django 3.2 and patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
agusmakmun committed Jul 6, 2021
1 parent bfdb894 commit 607b5e4
Show file tree
Hide file tree
Showing 46 changed files with 744 additions and 944 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github: [agusmakmun]
patreon:
ko_fi:
liberapay:
Expand Down
55 changes: 37 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@ sudo: false

matrix:
include:
- python: 2.7
env: DJANGO=1.10.*
- python: 2.7
env: DJANGO=1.11.*

- python: 3.5
env: DJANGO=1.10.*
- python: 3.5
env: DJANGO=1.11.*
- python: 3.5
env: DJANGO=2.0.*
- python: 3.5
env: DJANGO=2.1.*
- python: 3.5
env: DJANGO=2.2.*
- python: 3.5
env: DJANGO=3.0.*
- python: 3.5
env: DJANGO=3.1.*
- python: 3.5
env: DJANGO=3.2.*

- python: 3.6
env: DJANGO=1.10.*
- python: 3.6
env: DJANGO=1.11.*
- python: 3.6
env: DJANGO=2.0.*
- python: 3.6
Expand All @@ -33,11 +26,9 @@ matrix:
env: DJANGO=3.0.*
- python: 3.6
env: DJANGO=3.1.*
- python: 3.6
env: DJANGO=3.2.*

- python: 3.7
env: DJANGO=1.10.*
- python: 3.7
env: DJANGO=1.11.*
- python: 3.7
env: DJANGO=2.0.*
- python: 3.7
Expand All @@ -48,10 +39,38 @@ matrix:
env: DJANGO=3.0.*
- python: 3.7
env: DJANGO=3.1.*
- python: 3.7
env: DJANGO=3.2.*

- python: 3.8
env: DJANGO=2.0.*
- python: 3.8
env: DJANGO=2.1.*
- python: 3.8
env: DJANGO=2.2.*
- python: 3.8
env: DJANGO=3.0.*
- python: 3.8
env: DJANGO=3.1.*
- python: 3.8
env: DJANGO=3.2.*

- python: 3.9
env: DJANGO=2.0.*
- python: 3.9
env: DJANGO=2.1.*
- python: 3.9
env: DJANGO=2.2.*
- python: 3.9
env: DJANGO=3.0.*
- python: 3.9
env: DJANGO=3.1.*
- python: 3.9
env: DJANGO=3.2.*

- os: osx
language: generic
env: DJANGO=3.1.*
env: DJANGO=3.2.*

# Perform the manual steps on OSX to install Python3 and activate venv:
# Since Python versions have been tested on Linux and it is only a matter of
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Quick start

::

path('admin/log_viewer/', include('log_viewer.urls')),
path('logs/', include('log_viewer.urls')),


4. In your ``settings.py`` file create the following value
Expand All @@ -48,7 +48,7 @@ Quick start
LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, '../logs')
LOG_VIEWER_MAX_READ_LINES = 1000 # total log lines will be read
LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page
LOG_VIEWER_PATTERNS = [']OFNI[', ']GUBED[', ']GNINRAW[', ']RORRE[', ']LACITIRC[']
LOG_VIEWER_PATTERNS = ['[INFO]', '[DEBUG]', '[WARNING]', '[ERROR]', '[CRITICAL]']

# Optionally you can set the next variables in order to customize the admin:

Expand All @@ -73,7 +73,7 @@ Quick start
python manage.py collectstatic


7. Start the development server and visit http://127.0.0.1:8000/admin/log_viewer/
7. Start the development server and visit http://127.0.0.1:8000/logs/


.. |pypi version| image:: https://img.shields.io/pypi/v/django-log-viewer.svg
Expand Down
Empty file removed log_viewer/__init__.py
Empty file.
29 changes: 15 additions & 14 deletions log_viewer/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-30 17:54+0700\n"
"POT-Creation-Date: 2021-07-06 21:39+0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -18,35 +18,36 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: templates/log_viewer/logfile_viewer.html:6
msgid "Home"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:8
#: templates/log_viewer/logfile_viewer.html:39
#: templates/log_viewer/logfile_viewer.html:3
#: templates/log_viewer/logfile_viewer.html:9
#: templates/log_viewer/logfile_viewer.html:35
msgid "Django Log Viewer"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:32
msgid "Log Files"
#: templates/log_viewer/logfile_viewer.html:7
msgid "Home"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:41
#: templates/log_viewer/logfile_viewer.html:37
msgid "Download all Log Files"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:42
#: templates/log_viewer/logfile_viewer.html:38
msgid "Download this Log File"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:48
#: templates/log_viewer/logfile_viewer.html:44
msgid "No."
msgstr ""

#: templates/log_viewer/logfile_viewer.html:49
#: templates/log_viewer/logfile_viewer.html:45
msgid "Log entries"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:53
#: templates/log_viewer/logfile_viewer.html:49
msgid "No entries!"
msgstr ""

#: templates/log_viewer/logfile_viewer.html:55
msgid "Log Files"
msgstr ""
31 changes: 16 additions & 15 deletions log_viewer/locale/id/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-30 17:54+0700\n"
"POT-Creation-Date: 2021-07-06 21:39+0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -18,35 +18,36 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"

#: templates/log_viewer/logfile_viewer.html:6
msgid "Home"
msgstr "Beranda"

#: templates/log_viewer/logfile_viewer.html:8
#: templates/log_viewer/logfile_viewer.html:39
#: templates/log_viewer/logfile_viewer.html:3
#: templates/log_viewer/logfile_viewer.html:9
#: templates/log_viewer/logfile_viewer.html:35
msgid "Django Log Viewer"
msgstr "Penampil Log Django"

#: templates/log_viewer/logfile_viewer.html:32
msgid "Log Files"
msgstr "File log"
#: templates/log_viewer/logfile_viewer.html:7
msgid "Home"
msgstr "Beranda"

#: templates/log_viewer/logfile_viewer.html:41
#: templates/log_viewer/logfile_viewer.html:37
msgid "Download all Log Files"
msgstr "Unduh seluruh File Log"

#: templates/log_viewer/logfile_viewer.html:42
#: templates/log_viewer/logfile_viewer.html:38
msgid "Download this Log File"
msgstr "Unduh File Log ini"

#: templates/log_viewer/logfile_viewer.html:48
#: templates/log_viewer/logfile_viewer.html:44
msgid "No."
msgstr "No."

#: templates/log_viewer/logfile_viewer.html:49
#: templates/log_viewer/logfile_viewer.html:45
msgid "Log entries"
msgstr "Entri log"

#: templates/log_viewer/logfile_viewer.html:53
#: templates/log_viewer/logfile_viewer.html:49
msgid "No entries!"
msgstr "Tidak ada entri!"

#: templates/log_viewer/logfile_viewer.html:55
msgid "Log Files"
msgstr "File log"
6 changes: 2 additions & 4 deletions log_viewer/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os

from django.conf import settings

LOG_VIEWER_FILES = getattr(settings, 'LOG_VIEWER_FILES', [])
Expand All @@ -12,5 +10,5 @@
LOG_VIEWER_MAX_READ_LINES = getattr(settings, 'LOG_VIEWER_MAX_READ_LINES', 1000)
LOG_VIEWER_FILE_LIST_TITLE = getattr(settings, 'LOG_VIEWER_FILE_LIST_TITLE', None)
LOG_VIEWER_FILE_LIST_STYLES = getattr(settings, 'LOG_VIEWER_FILE_LIST_STYLES', None)
LOG_VIEWER_PATTERNS = getattr(settings, 'LOG_VIEWER_PATTERNS', [']OFNI[', ']GUBED[', ']GNINRAW[',
']RORRE[', ']LACITIRC['])
LOG_VIEWER_PATTERNS = getattr(settings, 'LOG_VIEWER_PATTERNS', ['[INFO]', '[DEBUG]', '[WARNING]',
'[ERROR]', '[CRITICAL]'])
15 changes: 8 additions & 7 deletions log_viewer/templates/log_viewer/logfile_viewer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "admin/base_site.html" %}
{% load static i18n %}
{% block title %}{% trans "Django Log Viewer" %} - {{ block.super }}{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
Expand All @@ -25,15 +26,10 @@
{% endblock %}

{% block content %}
<div class="django__log__viewer">
<div class="django__log__viewer ">
<div id="content-main">
<div class="module filtered" id="changelist">
<div id="changelist-filter">
<h2>{% trans 'Log Files' %}</h2>
<div id="log-files-list">
</div>
</div>
<form id="changelist-form">
<form id="changelist-form" class="changelist-form-container">
<div class="results">
<div class="headers">
<h1 class="pull-left">{% if custom_file_list_title %}{{ custom_file_list_title }}{% else %}{% trans "Django Log Viewer" %}{% endif %}</h1>
Expand All @@ -55,6 +51,11 @@ <h1 class="pull-left">{% if custom_file_list_title %}{{ custom_file_list_title }
</table>
</div>
</form>
<div id="changelist-filter">
<h2>{% trans 'Log Files' %}</h2>
<div id="log-files-list">
</div>
</div>
</div>
</div>
</div>
Expand Down
32 changes: 29 additions & 3 deletions log_viewer/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
from django.test import TestCase
from django.urls import reverse
from django.test import TestCase, Client
from django.contrib.auth import get_user_model

User = get_user_model()

class SimpleTest(TestCase):

class TestLogsViewer(TestCase):

def setUp(self):
self.user = User.objects.create_user(
username='john',
password='Foobar@1234',
is_active=True,
is_staff=True,
is_superuser=True
)
self.client_login = Client()
self.client_login.force_login(self.user)
self.client_anon = Client()
self.url = reverse('log_file_view')

def test_redirection(self):
response = self.client.get('/')
response = self.client_anon.get(self.url)
self.assertEqual(response.status_code, 302)

def test_logs_viewer(self):
# response = self.client_login.get(self.url)
# self.assertEqual(response.status_code, 200)
# self.assertContains(response, 'Django Log Viewer')
# self.assertTemplateUsed(response, 'log_viewer/logfile_viewer.html')

# FIXME: django.urls.exceptions.NoReverseMatch: 'admin' is not a registered namespace
...
10 changes: 6 additions & 4 deletions log_viewer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ def readlines_reverse(qfile, exclude=''):
"""
Read file lines from bottom to top
"""
# support custom patterns (fixed issue #4)
patterns = settings.LOG_VIEWER_PATTERNS
reversed_patterns = [x[::-1] for x in patterns]

qfile.seek(0, os.SEEK_END)
position = qfile.tell()
line = ''

while position >= 0:
qfile.seek(position)
next_char = qfile.read(1)
Expand All @@ -48,10 +53,7 @@ def readlines_reverse(qfile, exclude=''):

# modified
if next_char == '\n' and line:
# support custom patterns (fixed issue #4)
patterns = settings.LOG_VIEWER_PATTERNS

if any([line.endswith(p) for p in patterns]):
if any([line.endswith(p) for p in reversed_patterns]):
if exclude in line[::-1]:
line = ''
else:
Expand Down
16 changes: 16 additions & 0 deletions log_viewer_demo/log_viewer_demo/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for log_viewer_demo project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'log_viewer_demo.settings')

application = get_asgi_application()
Loading

0 comments on commit 607b5e4

Please sign in to comment.