1def auth(request):
2    """
3    Returns context variables required by apps that use Django's authentication
4    system.
5
6    If there is no 'user' attribute in the request, uses AnonymousUser (from
7    django.contrib.auth).
8    """
9    if hasattr(request, 'user'):
10        user = request.user
11    else:
12        from seahub.auth.models import AnonymousUser
13        user = AnonymousUser()
14
15    return {
16        'user': user,
17        'perms': None,
18    }
19