25 lines
708 B
Python
25 lines
708 B
Python
"""
|
|
Middleware classes used throughout the project.
|
|
|
|
See https://docs.djangoproject.com/en/2.1/topics/http/middleware/
|
|
"""
|
|
|
|
class SetApplicationName(object):
|
|
"""
|
|
Set request.current_app to the name of the app the current
|
|
view belongs to. This ends up being the first component
|
|
of the package name.
|
|
|
|
See:
|
|
https://stackoverflow.com/questions/12596722/django-identify-app-in-template
|
|
"""
|
|
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
return self.get_response(request)
|
|
|
|
def process_view(self, request, view_func, view_args, view_kwargs):
|
|
request.current_app = view_func.__module__.split('.')[0]
|