Ticket #5457: doc.diff

File doc.diff, 1.5 KB (added by Florian Apolloner, 17 years ago)

I added some docs. Please apologize my bad English.

  • docs/authentication.txt

     
    10411041                return User.objects.get(pk=user_id)
    10421042            except User.DoesNotExist:
    10431043                return None
     1044
     1045Optionally the Backend allows you to specify any of the permission methods of
     1046the ``User`` object (except from ``has_perms`` which calls ``has_perm`` for each
     1047perm in the list, and ``has_perm`` can be specified in the backend).
     1048This will allow your backend to handle the permissions, if one backend return
     1049``True`` in a permission check, the user will have the permission.
     1050
     1051Here is an sample implementation for ``has_perm`` extending the above exmaple::
     1052       
     1053        # The permission functions all take the user_obj as first (besides the self of
     1054        # the backend, of course) argument and the rest
     1055        # is as you would call it with ``User.*``
     1056        def has_perm(self, user_obj, perm):
     1057            # we give the user admin the right to do everything.
     1058            if user_obj.username == "admin":
     1059                return True
     1060            else:
     1061                return False
     1062
     1063A full implementation can be found in ``django/contrib/auth/backends.py`` _, which is the
     1064default backend and queries the ``auth_permission``-table most of the time.
     1065
     1066.. _django/contrib/auth/backends.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py
Back to Top