Skip to main content

Django app with common code and assets for Money to Prisoners serivces

Project description

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 = (
    ...
    # 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

https://circleci.com/gh/ministryofjustice/money-to-prisoners-common/tree/master.svg?style=svg
  • Test using ./run.py test or python setup.py test

  • Update the version with ./run.py set_version --version [?.?.?]

  • Commit and push changes to github

  • Submit to PyPi with ./run.py upload

Translating

Update translation files with ./run.py make_messages – you need to do this every time any translatable text is updated.

Compile messages ./run.py compile_messages – only needed during local testing or development, it happens automatically during build or upload.

Pull updates from Transifex with ./run.py translations --pull. You’ll need to update translation files afterwards and manually check that the merges occurred correctly.

Push latest English to Transifex with ./run.py translations --push. NB: you should pull updates before pushing to merge correctly.

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.

SCSS, JavaScript, images

Assets that need compiling are in mtp_common/assets-src/(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).

There is a separate guide to the various visual elements defined in this repository and used by the various MTP apps.

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

money-to-prisoners-common-9.2.0.tar.gz (573.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

money_to_prisoners_common-9.2.0-py3-none-any.whl (654.3 kB view details)

Uploaded Python 3

File details

Details for the file money-to-prisoners-common-9.2.0.tar.gz.

File metadata

File hashes

Hashes for money-to-prisoners-common-9.2.0.tar.gz
Algorithm Hash digest
SHA256 11eb4a2716e9095cdc0f1931cbf3b7aa4da5a18afeacd1f25049cb44dc7dd8db
MD5 0077d77b29e9633cac98cc3b5b411b0e
BLAKE2b-256 fa2c3d282603cd8c73c81f6056f90d576e43140ac70ea3c577af703f1945cb14

See more details on using hashes here.

File details

Details for the file money_to_prisoners_common-9.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for money_to_prisoners_common-9.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95c557da81a596bc6788dc540dff2dcc940a72b738e3a97e818ad19a3c2582e0
MD5 ef8b63e39b817a2dd56a218c0b0e47cd
BLAKE2b-256 c4df1a4d9d78d03915b08bfe271dbf658571fe930c6e82f8ba016b195baf8ef2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page