Middleware

This package contains custom middlewares, see Middleware and Middleware.

Access Control Middleware

class integreat_cms.core.middleware.access_control_middleware.AccessControlMiddleware(get_response: Callable)[source]

Bases: object

Middleware class that performs a basic access control. For urls that are whitelisted (see whitelist), no additional rules are enforced. For all other urls, the user has to be either superuser or staff, or needs access to the current region.

Parameters:

get_response (Callable)

__init__(get_response: Callable) None[source]

Initialize the middleware for the current view

Parameters:

get_response (Callable) – A callable to get the response for the current request

Return type:

None

whitelist: Final[list[str]] = ['api', 'public', 'sitemap', 'i18n', 'media_files', 'pdf_files', 'xliff_files', 'djdt'][source]

The namespaces that are whitelisted and don’t require access control

Region Middleware

class integreat_cms.core.middleware.region_middleware.RegionMiddleware(get_response: Callable)[source]

Bases: object

Middleware class that adds the current region to the request variable

Parameters:

get_response (Callable)

__init__(get_response: Callable) None[source]

Initialize the middleware for the current view

Parameters:

get_response (Callable) – A callable to get the response for the current request

Return type:

None

static get_available_regions(request: HttpRequest, user_regions: QuerySet) QuerySet[source]

This method returns the regions available to the user based on the current request. Staff members and superusers have access to all regions, whereas all other users have access to their selected regions.

Parameters:
  • request (HttpRequest) – Django request

  • user_regions (QuerySet) – Prefetched regions of the user

Returns:

The regions available to the user of this request

Return type:

QuerySet

static get_current_region(request: HttpRequest) Region | None[source]

This method returns the current region based on the current request. If the request path contains a region slug, the corresponding Region object is queried from the database.

Parameters:

request (HttpRequest) – Django request

Raises:

Http404 – When the current request has a region_slug parameter, but there is no region with that slug.

Returns:

The current region of this request

Return type:

Region | None

static get_quick_access_regions(request: HttpRequest, user_regions: QuerySet) list[Region][source]

This method returns the regions that are available for quick access in this request. For non-staff members, the region selection consists of the regions they have access to. For staff members with non-empty regions field, it is used as a favorite setting. Staff members without favorite regions just have quick access to the regions that have been last updated. The current region is excluded. The list is truncated to the first NUM_REGIONS_QUICK_ACCESS elements.

Parameters:
  • request (HttpRequest) – The current HTTP request

  • user_regions (QuerySet) – Prefetched regions of the user

Returns:

The regions that are available for quick access in the dropdown menu

Return type:

list[Region]

Timezone Middleware

class integreat_cms.core.middleware.timezone_middleware.TimezoneMiddleware(get_response: Callable)[source]

Bases: object

Middleware class that sets the current time zone like specified in settings.py

Parameters:

get_response (Callable)

__init__(get_response: Callable) None[source]

Initialize the middleware for the current view

Parameters:

get_response (Callable) – A callable to get the response for the current request

Return type:

None