Skip to content

Middleware

MedUX provides custom middleware that enriches the request object with context used throughout the application.

Configuration

Add the MedUX middleware to your MIDDLEWARE setting:

MIDDLEWARE = [
    # ... Django and Conjunto middleware ...
    "medux.employees.middleware.EmployeeMiddleware",
    "medux.core.middleware.DeviceMiddleware",
]

DeviceMiddleware

medux.core.middleware.DeviceMiddleware

A middleware that adds the current device to the request.

A device commonly is a computer in this context. Add medux.core.middleware.DeviceMiddleware to your MIDDLEWARE dict in settings.py. You can use the device in a template to your needs:

<span>Device: {{ request.device }}</span>

Or in a view:

logger.debug(f"Request originating from device {request.device}.")

The DeviceMiddleware identifies the device (workstation, tablet, etc.) making the request and attaches it to request.device. This is used by the scoped settings system (the "Device" scope level) and can be used by plugins to provide device-specific behavior.

EmployeeMiddleware

medux.employees.middleware.EmployeeMiddleware

Adds .employee attribute to request objects.

If current user is no employee, it is set to None.

The EmployeeMiddleware attaches the Employee record (if one exists) for the current user to request.employee. This allows views and templates to access employee-specific data without additional queries.