intranet.middleware package¶
Submodules¶
intranet.middleware.access_log module¶
intranet.middleware.ajax module¶
- class intranet.middleware.ajax.AjaxNotAuthenticatedMiddleWare(get_response)[source]¶
Bases:
object
Django doesn’t handle login redirects with AJAX very nicely, so we have to work around the default behavior a little.
If a user’s session has expired, but they still have a window open, they client may send AJAX requests to a view wrapped in @login_required or something similar. When this happens, Django
302
redirects to something like/login?next=/eighth/signup
, which will show up to the client as a200 OK
GET
request and proceed as if everything worked. To avoid this, we need to detect these types of requests and change their status code to401
to let the client know that the request actually failed.
intranet.middleware.dark_mode module¶
intranet.middleware.monitoring module¶
intranet.middleware.profiler module¶
- class intranet.middleware.profiler.ProfileMiddleware[source]¶
Bases:
object
Displays timing or profiling for any view. http://yoursite.com/yourview/?time or http://yoursite.com/yourview/?prof
Record the time taken by Django and the project code to generate the web page and by the database to make the queries. Accumulate repeated web page visits and display the accumulated statistics in the web browser in place of the normal web page. The availability of this middleware is controlled by the DEBUG flas in settings.py. To time a page, add ‘?time’ (or ‘&time’). To clear out accumulated timings, add ‘&reset’.
Alternatively, profile the python function calls executed to create the web page and display the profiling statistics in the web browser. To profile a page, add ‘?prof’ (or ‘&prof’) to the url. By default the statistics are sorted by cumulative time. To specify an alternative sort, add one or more ‘sort’ parameters, e.g., ‘&sort=time&sort=calls’. By default the display is limited to the first 40 function calls. To specify an alternative, add a limit parameter, e.g., ‘&limit=.50’. To write the profile data to a permanent file in PROFILE_LOG_BASE add ‘&log’. To strip the directory paths from the profile statistics, add ‘&strip’. (Note that the file and group summaries are also removed by ‘strip’.)
- intranet.middleware.profiler.stdev(x)[source]¶
Calculate standard deviation of data x[]: std = sqrt(sum_i (x_i - mean)^2 over n-1) https://wiki.python.org/moin/NumericAndScientificRecipes
intranet.middleware.same_origin module¶
intranet.middleware.session_management module¶
intranet.middleware.templates module¶
- class intranet.middleware.templates.AdminSelectizeLoadingIndicatorMiddleware(get_response)[source]¶
Bases:
object
Automatically add a loading placeholder for Selectize inputs in admin templates.
This is probably not a good practice, but it really needs to be done server-side for the loading indicators to show up instantly.