Code Description

class global_login_required.GlobalLoginRequiredMiddleware(get_response=None)

Bases: django.utils.deprecation.MiddlewareMixin

Main idea from Julien Phalip

Note

Compatible with django 1.11+

check_decorator(view)

Checks is the view function decorated or not

Parameters:view – view function
Return type:bool
get_view(view_path)

returns callable instance of view from view path :param view_path: view path, like ‘django.contrib.auth.views.login’ :return: a callable instance of view, in this example login

matches_public_path(path)

Checks is the request path is listed in PUBLIC_PATHS, so it is not login required.

Parameters:path (string) – the request path
Returns:true if view was listed in PUBLIC_PATHS.
Return type:bool
matches_public_view(view)

Checks is the view is listed in PUBLIC_VIEWS, so it is not login required.

Parameters:view (callable) – the view
Returns:true if view was listed in PUBLIC_VIEWS.
Return type:bool
process_view(request, view_func, view_args, view_kwargs)

checks if this view is not in excluded views (by PUBLIC_VIEWS, PUBLIC_PATHS or login_not_required decorator), adds login_required decorator for view, otherwise run the view it self.

Note

read the documentation at djangoproject

Parameters:
  • request (HttpRequest) – this will be passed to next process_view and finally will be passed to view.
  • view_func (callable) – the view function
  • view_args – the arguments that will be passed to view
  • view_kwargs – the keyword arguments that will be passed to view
Returns:

None in order to continue processing process_view in middleware chain or ` HttpResponse` for braking middleware chain.

global_login_required.login_not_required(the_view)

Decorator which marks the given view as public (not login required).

This decorator adds a read only property `` LOGIN_NOT_REQUIRED`` to the view, and if it’s value be True, the middleware will not force for login.

If you combine this with a login_required decorator, your view will be login required.