Django app with common code and assets for Money to Prisoners serivces
Project description
Money to Prisoners
A Django app containing utilities and assets common to all Money to Prisoners services/applications.
Features
Reusable templates for form fields and errors
Base sass and static assets
Base templates
Authentication utilities and views for connecting to the MTP api
User account management forms and views
REST utilities for retrieving information from money-to-prisoners-api
Integration and accessibility testing with selenium
Python code style testing
Log formatting for shipping to ELK
Usage
Add money-to-prisoners-common==<version> to the Money to Prisoners application’s requirements.txt. There are two variations as setuptools extras:
Use money-to-prisoners-common[testing]==<version> for environments requiring testing
Use money-to-prisoners-common[monitoring]==<version> for the deployed version
Add url patterns:
from django.conf.urls import url
from mtp_common.auth import views
urlpatterns = [
url(r'^login/$', views.login, {
'template_name': 'login.html',
}, name='login'),
url(
r'^logout/$', views.logout, {
'template_name': 'login.html',
'next_page': reverse_lazy('login'),
}, name='logout'
),
]
Configure Django settings:
MIDDLEWARE_CLASSES = (
...
# instead of django.middleware.csrf.CsrfViewMiddleware
'mtp_common.auth.csrf.CsrfViewMiddleware',
...
# instead of django.contrib.auth.middleware.AuthenticationMiddleware
'mtp_common.auth.middleware.AuthenticationMiddleware',
...
)
AUTHENTICATION_BACKENDS = (
'mtp_common.auth.backends.MojBackend',
)
CSRF_FAILURE_VIEW = 'mtp_common.auth.csrf.csrf_failure'
If you wish for additional interface methods, you can extend mtp_common.auth.models.MojUser, and specify your subclass as MOJ_USER_MODEL. An example would be adding a property to access a key in the user_data dict.
MOJ_USER_MODEL = 'myapp.models.MyCustomUser'
Specify the parameters of the API authentication. API_CLIENT_ID and API_CLIENT_SECRET should be unique to your application.
API_CLIENT_ID = 'xxx'
API_CLIENT_SECRET = os.environ.get('API_CLIENT_SECRET', 'xxx')
API_URL = os.environ.get('API_URL', 'http://localhost:8000')
OAUTHLIB_INSECURE_TRANSPORT = True
Developing
Test using python setup.py test or ./run_tests.py [arguments]
Update VERSION tuple in mtp_common/__init__.py
Git tag with version
Submit to PyPi with python setup.py sdist bdist_wheel upload
Common assets
All shared assets used for money-to-prisoners-cashbook, money-to-prisoners-bank-admin, money-to-prisoners-prisoner-location-admin and money-to-prisoners-send-money are kept in this package.
Each application’s build scripts install this package automatically.
This repository has a dependency on mojular/moj-elements, which provides the assets and scripts for MOJ sites. The mojular repositories are shared across multiple departments, and any change should be checked by members of the organization.
Sass, javascript, images
Assets that need compiling are in mtp_common/assets/(images|javascripts|scss). The base sass file, _mtp.scss, is used to include the sass includes from this packge into each frontend app.
Static assets are in mtp_common/static/(images|javascripts|css).
Django templates
Common templates used by the client applications are kept in mtp_common/templates.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for money-to-prisoners-common-3.19.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08da84a218b24906b56b55736a58c9a2de40f23c870db75d0fb12a8be2043928 |
|
MD5 | 3e83e03ec89a54eb5359931c238f80f5 |
|
BLAKE2b-256 | 2365cedadeddb8ffc8dfd5c8825781b8de50603243404b1d626d0016566943b8 |
Hashes for money_to_prisoners_common-3.19.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ce1666c88748822bbf4fef486a3ea346ce00748f601cadc42be6c32a6ab5e4 |
|
MD5 | 60238d2cd9c34c8f4c7858e8d1117bc9 |
|
BLAKE2b-256 | 63ef207f69bebe8bf7df9d81a678f25970c10816a23de843318472c4bc33fb8c |