Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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_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 ./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.

Release History

Release History

This version
History Node

5.28.0

History Node

5.27.0

History Node

5.26.0

History Node

5.25.0

History Node

5.24.0

History Node

5.23.0

History Node

5.22.0

History Node

5.21.0

History Node

5.20.0

History Node

5.19.0

History Node

5.18.1

History Node

5.18.0

History Node

5.17.0

History Node

5.16.0

History Node

5.15.0

History Node

5.14.1

History Node

5.14.0

History Node

5.13.0

History Node

5.12.0

History Node

5.11.0

History Node

5.10.0

History Node

5.9.3

History Node

5.9.2

History Node

5.9.1

History Node

5.9.0

History Node

5.8.0

History Node

5.7.0

History Node

5.6.0

History Node

5.5.1

History Node

5.4.0

History Node

5.3.0

History Node

5.2.1

History Node

5.1.1

History Node

5.0.8

History Node

5.0.7

History Node

5.0.6

History Node

5.0.5

History Node

5.0.4

History Node

4.42.0

History Node

3.19.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
money_to_prisoners_common-5.28.0-py3-none-any.whl (614.7 kB) Copy SHA256 Checksum SHA256 3.4 Wheel Aug 31, 2017
money-to-prisoners-common-5.28.0.tar.gz (553.5 kB) Copy SHA256 Checksum SHA256 Source Aug 31, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting