django-jutil
============
Collection of small utilities for Django and Django REST framework projects.
Django 3.0 compatible.
[![codecov](https://codecov.io/gh/kajala/django-jutil/branch/master/graph/badge.svg)](https://codecov.io/gh/kajala/django-jutil)
[![Build Status](https://travis-ci.org/kajala/django-jutil.svg?branch=master)](https://travis-ci.org/kajala/django-jutil)
Features
========
* Simplified admin changes history logging (admin_log)
* ModelAdmin with length limited history view (ModelAdminBase)
* Simplified object URL/link generation within admin (admin_obj_link and admin_obj_url)
* Extended admin log mixin of changed fields (AdminLogEntryMixin)
* Admin file download mixin with file permission checks (AdminFileDownloadMixin)
* User authentication helpers (require_auth, AuthUserMixin)
* Mixin for cached model fields management (CachedFieldsMixin)
* BaseCommand extension which catches, logs and emails errors (SafeCommand)
* Command options for simplified handling of date ranges (add_date_range_arguments, parse_date_range_arguments)
* Various utilities for date ranges generation and iteration (dates.py)
* Utilities for dict sorting and formatting, choices list label fetching (dict.py)
* Simplified email sending via SendGrid API (send_email)
* Various formatting utilities (e.g. XML, timedelta, Decimal)
* Decimal encoder for encoding JSON objects/dictionaries containing Decimal instances (SimpleDecimalEncoder)
* Django middleware for exception logging/emailing (LogExceptionMiddleware)
* Django middleware for language cookie handling (EnsureLanguageCookieMiddleware)
* Django middleware for user.profile.timezone based timezone activation
* Utilities or Django Model handling (e.g. clone_model, get_object_or_none)
* Utilities for parsing booleans and datetime values (using pytz)
* Simple user field based permission checking for REST APIs (permissions.py)
* Geo IP / IP info functions using IPStack API (request.py)
* Download responses (FileSystemFileResponse and CsvFileResponse)
* Simple SMS sending (send_sms)
* Mixin for basic test user setup (DefaultTestSetupMixin)
* Pretty good unit test coverage (tests.py)
* URL modifying/comparison functions (urls.py)
* Validators and filters for various types (validators.py)
* XML Element to/from dict conversions (dict_to_element, xml_to_dict)
* XML file/content pretty formatting (format_xml, format_xml_bytes, format_xml_file, FormattedXmlResponse)
Install
=======
pip install django-jutil
Static Code Analysis
====================
The library passes both prospector and mypy checking. To install:
pip install prospector
pip install mypy
To analyze:
prospector
mypy .
Test Code Coverage
==================
* `coverage run manage.py; coverage report`
Changes
=======
3.7.4:
* Stricter get_media_full_path and is_media_full_path
3.7.3:
* Unit tests
* Get media full path cleanup
3.7.2:
* Cleanup
3.7.1:
* Requirements.txt: deleted optional dependency sendgrid, add sendgrid on project level sendgrid>=6.3.1,<7.0.0
* Deleted deprecated auth.require_auth, use auth.get_auth_user and auth.get_auth_user_or_none
* Deleted deprecated dict.choices_label and dict.dict_to_html, use format.choices_label and format.format_dict_as_html
* Deleted deprecated logs.*, use logging directly
* Deleted deprecated object.*, use type-safer alternatives
* Deleted deprecated url_equals and url_host, use urlparse directly
* Removed deprecated testing.*
* Cleaned up parse_datetime, parse_bool, parse_datetime_or_none and parse_bool_or_none
* Simpler cleaned up testing mixin TestSetupMixin
3.6.11:
* Deprecated object.get/set obj attr functions
* Deprecated url equals and url host
* Deprecated testing.DefaultTestSetupMixin
* Separated parse functions /w xxx or none versions for better typing support
* Dropped python-dateutil dependency, added unit tests for get time steps
* Deprecated log event
* Updated send_email_sendgrid docs
* Refactored choices label and dict to html in dict and format, added deprecation warnings
* Added --this-month, --this-week, --this-year to add date range arguments, get date range by name, parse date range arguments
* Require auth refactoring
* Removed AdminFileDownloadMixin - Django 3.1 has new logic for uploaded file URL format making the mixin obsolete
* (origin/master, origin/HEAD, master) README update
3.6.10:
* Unit test fix
* Log entry ordering fix
3.6.9:
* Minor refactoring
3.6.8:
* API testing client to support non-json content
* Parse bool unit test
3.6.7:
* Added format as html json and unit tests
3.6.6:
* Millisecond handling to format timedelta
* Deploy cleanup
* Python-dotenv
3.6.5:
* API testing tweaks
3.6.4:
* Mypy fix
* Unit test improvements, added support for FI ssns before 1900 and after 2000
* Test-coverage tweak
3.6.3:
* Code QA / Prospector fixes
* Added wait object or none and unit test
3.6.2:
* Added .env to ignore
3.6.1:
* Cleanup
* Dropped parse sftp connection (as redundant)
* Docs
3.5.3:
* Tweaks to usage of ipware
3.5.2:
* Minor refactoring
3.5.1:
* Upgrade of ipware to newer version
* Dev requirements change of psycopg2
3.4.9:
* Mypy fix
* Added get_ip() wrapper for ipware
3.4.8:
* Usage cleanup of ipware
3.4.7:
* Minor refactoring, added unit tests
3.4.6:
* More relaxed typing to admin log
* DB check to build process
3.4.5:
* Format table max col setting fix
* Fixed format table bug, added docs
3.4.4:
* Added User as explicit opt parameter to admin log
3.4.3:
* Minor refactoring
3.4.2:
* Added strip tag fields and unit tests
3.4.1:
* Type checking fixes
* Added middleware unit tests
* Changed ActivateUserProfileTimezone -> ActivateUserProfileTimezoneMiddleware to conform Django naming conventions
* Cleanup, docs
* Test-coverage script tweaks
* Added dependency-check to requirements-dev.txt
* .gitignore tweaks
3.3.6:
* Unit test fix
* Build process cleanup
* Cleanup
* Test-coverage script update
* Added htmlcov to ignore
3.3.5:
* Test fixes
* Admin obj url fix
3.3.4:
* Admin log type fix
3.3.3:
* Code QA
* Unit test improvements
* Updated travis test to python 3.8
3.3.2:
* Added camel case conversion funcs
3.3.1:
* Format timedelta cleanup
* Test-coverage script update
* Unit test fixes
* Re-enabled pytype
3.2.21:
* Email fix
3.2.20:
* Unit test coverage update
* Sendgrid email format fix
3.2.19:
* Added end_of_month() (as in Excel) and unit tests
* L10n
3.2.18:
* Type checking fixes
3.2.17:
* Type checking fixes
3.2.16:
* Type checking fixes
3.2.15:
* CachedFieldsMixin save() TYPE CHECKING fix
3.2.14:
* Type checking fix
* Readme updates
* MANIFEST tweaks
* Pre-release script tweaks
3.2.13:
* Added py.typed marker file
3.2.12:
* Mypy / cleanup
3.2.11:
* Test coverage update
* Added twine to dev reqs
* Deploy script update
3.2.10:
* Test coverage update
* Mypy support
3.2.9:
* Test coverage update
* Pre-release script tweaks
* Test coverage script tweaks
3.2.8:
* Travis sys import
* Added vanity icons to readme
3.2.7:
* Added sudo apt-get install -y libxml2-utils to travis
3.2.6:
* Travis log changes
3.2.5:
* Added travis config
3.2.4:
* Codecov tests
3.2.3:
* Added codecov.yml
3.2.2:
* Test coverage update
3.2.1:
* Dependency cleanup
3.1.4:
* Test coverage update
* Language cookie to use secure and httponly settings
* Updated LICENSE.txt
3.1.3:
* Test coverage update
* Cleanup
* IBAN generation
3.1.2:
* Test coverage update
* Config tweaks / pytype
3.1.1:
* Test coverage update
3.0.16:
* Test coverage update
* Code QA pytype tool integration to build process
3.0.15:
* Formatting options to format timedelta as 3h40min14s
3.0.14:
* Test coverage update
* Added helpers for media path handling
3.0.13:
* BIC validator
* Added body and subject to test email
3.0.12:
* Test coverage update
* CsvFileResponse -> CsvResponse to be consistent with naming of other responses
* Separate XmlResponse and XmlFileResponse
3.0.11:
* Test coverage update
* Cleanup
3.0.10:
* Test coverage update
* Cleanup
* Xml formatting error