https://github.com/venhance/evans_django_tools
Discord logging and unit test components for Django
https://github.com/venhance/evans_django_tools
discord logging python
Last synced: 2 months ago
JSON representation
Discord logging and unit test components for Django
- Host: GitHub
- URL: https://github.com/venhance/evans_django_tools
- Owner: vEnhance
- License: mit
- Created: 2021-09-03T21:39:14.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T23:19:04.000Z (over 1 year ago)
- Last Synced: 2025-07-06T22:59:47.105Z (12 months ago)
- Topics: discord, logging, python
- Language: Python
- Homepage:
- Size: 120 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# evans_django_tools
This repository is now archived because its functionality has been split off.
- [Testing shortcuts were moved into a separate file](https://github.com/vEnhance/otis-web/blob/main/otisweb_testsuite/testcase.py).
- [Discord webhooks were split off](https://github.com/vEnhance/django-discordo)
- CI is now usually done via [Makefile](https://github.com/vEnhance/otis-web/blob/main/Makefile)
for a simpler [ci.yml](https://github.com/vEnhance/otis-web/blob/main/.github/workflows/ci.yml).
## Old description
This is a submodule containing a bunch of stuff that I use between multiple
Django projects.
Things here were originally written for use with
[OTIS-WEB](https://github.com/vEnhance/otis-web),
but I then found myself copy-pasting this code in other
Python web applications I was writing. Hence this repository.
(Right now, I am assuming I am the sole user of this package.
If any person other than me expresses interest in using this,
open an issue, and I will (eventually) submit it to PyPi.)
## Discord webhook handler
This is a wrapper script that implements a handler
for logging commands to send Discord webhooks.
For web applications running Django, it will additionally
provide some `request` information in the webhook embed.
1. This package needs the `requests` and `python-dotenv` packages.
2. Add this repository as a submodule of your project.
3. Import it using `from evans_django_tools import DiscordWebhookHandler`.
4. Add standard `logging` commands. For example,
```python
import logging
from evans_django_tools import DiscordWebhookHandler
logger = logging.getLogger('root')
logger.setLevel(logging.INFO)
logger.addHandler(DiscordWebhookHandler())
logger.addHandler(logging.StreamHandler())
```
5. You should set environment variable `WEBHOOK_URL` to the target webhook URL.
6. If you want different channels for different error levels,
use `WEBHOOK_CRITICAL_URL`, `WEBHOOK_ERROR_URL`, etc.
Otherwise `WEBHOOK_URL` is used by default.
7. The package adds three new log levels: `VERBOSE_LOG_LEVEL = 15`,
`SUCCESS_LOG_LEVEL = 25`, `ACTION_LOG_LEVEL = 35`.
## Test suite
The file `evans_django_tools/testsuite.py` has a bunch of homemade helper
functions for writing Django tests.
## Bash scripts for local checks
To use the `lint.sh` automatically on `git push`, create an executable file
`.git/hooks/pre-push` with content `./evans_django_tools/lint.sh`.
This will run the `lint.sh` script automatically before pushing anything (and
abort the push if any issues are detected).
Running `./evans_django_tools/bypass-lint.sh` causes
`./evans_django_tools/lint.sh` to do nothing for the current commit, hence the
name.
## GitHub workflow
This repository has a Github reusable workflow that you can use that runs
essentially the same checks as `lint.sh`. To use it, create
`.github/workflows/django-audit.yml` in your main repository and include
something like the following:
```yaml
name: Django Audit
on:
push:
branches: ["*"]
pull_request:
branches: ["*"]
jobs:
audit:
uses: vEnhance/evans_django_tools/.github/workflows/django-audit.yml@main
```