Django Book 翻译
菜单>:
TOC
返回
原文:
.. table:: Table 12-4. Methods on ``User`` Objects +-------------------------------+--------------------------------------------------+ |Method |Description | +===============================+==================================================+ |``is_authenticated()`` |Always returns ``True`` for real ``User`` objects.| | |This is a way to tell if the user has been | | |authenticated. This does not imply any | | |permissions, and it doesnt check if the user is | | |active. It only indicates that the user has | | |sucessfully authenticated. | +-------------------------------+--------------------------------------------------+ |``is_anonymous()`` |Returns ``True`` only for ``AnonymousUser`` | | |objects (and ``False`` for real ``User`` objects).| | |Generally, you should prefer using | | |``is_authenticated()`` to this method. | +-------------------------------+--------------------------------------------------+ |``get_full_name()`` |Returns the ``first_name`` plus the ``last_name`` | | |, with a space in between. | +-------------------------------+--------------------------------------------------+ |``set_password(passwd)`` |Sets the users password to the given raw string, | | |taking care of the password hashing. This doesnt | | |actually save the ``User`` object. | +-------------------------------+--------------------------------------------------+ |``check_password(passwd)`` |Returns ``True`` if the given raw string is the | | |correct password for the user. This takes care of | | |the password hashing in making the comparison. | +-------------------------------+--------------------------------------------------+ |``get_group_permissions()`` |Returns a list of permission strings that the user| | |has through the groups he or she belongs to. | +-------------------------------+--------------------------------------------------+ |``get_all_permissions()`` |Returns a list of permission strings that the user| | |has, both through group and user permissions. | +-------------------------------+--------------------------------------------------+ |``has_perm(perm)`` |Returns ``True`` if the user has the specified | | |permission, where ``perm`` is in the format | | |``"package.codename"`` . If the user is inactive, | | |this method will always return ``False`` . | +-------------------------------+--------------------------------------------------+ |``has_perms(perm_list)`` |Returns ``True`` if the user has *all* of the | | |specified permissions. If the user is inactive, | | |this method will always return ``False`` . | +-------------------------------+--------------------------------------------------+ |``has_module_perms(app_label)``|Returns ``True`` if the user has any permissions | | |in the given ``app_label`` . If the user is | | |inactive, this method will always return ``False``| | |. | +-------------------------------+--------------------------------------------------+ |``get_and_delete_messages()`` |Returns a list of ``Message`` objects in the users| | |queue and deletes the messages from the queue. | +-------------------------------+--------------------------------------------------+ |``email_user(subj, msg)`` |Sends an email to the user. This email is sent | | |from the ``DEFAULT_FROM_EMAIL`` setting. You can | | |also pass a third argument, ``from_email`` , to | | |override the From address on the email. | +-------------------------------+--------------------------------------------------+ |``get_profile()`` |Returns a site-specific profile for this user. See| | |the Profiles section for more on this method. | +-------------------------------+--------------------------------------------------+
翻译:
.. table:: 表 12-4. ``User`` 对象方法 +-------------------------------+--------------------------------------------------+ |方法 |描述 | +===============================+==================================================+ |``is_authenticated()`` |如果是真正的 ``User`` 对象,返回值恒为 ``True`` 。| | |用于检查用户是否已经通过了认证。通过认证并不意味着| | |用户拥有任何权限,甚至也不检查该用户是否处于激活状| | |态,这只是表明用户成功的通过了认证。 | +-------------------------------+--------------------------------------------------+ |``is_anonymous()`` |如果是个 ``AnonymousUser`` ,返回值为 ``True`` , | | |如果是 ``User`` 对象,返回值为 ``False`` 。一般来 | | |说, ``is_authenticated()`` 会比这个方法更常用些。| +-------------------------------+--------------------------------------------------+ |``get_full_name()`` |返回值为: ``first_name`` 加上 ``last_name`` ,以 | | |空格分隔。 | +-------------------------------+--------------------------------------------------+ |``set_password(passwd)`` |将用户的密码设置为给定的字符串,实际密码已被哈希 | | |处理。这时并不会真正保存 ``User`` 对象。 | +-------------------------------+--------------------------------------------------+ |``check_password(passwd)`` |如果给定的字符串通过了密码检查,返回 ``True`` 。 | | |密码比较已进行了哈希处理。 | +-------------------------------+--------------------------------------------------+ |``get_group_permissions()`` |返回用户通过所属组获得的权限列表 | +-------------------------------+--------------------------------------------------+ |``get_all_permissions()`` |返回用户通过所属组和用户自身权限所获得的所有权限 | | |列表。 | +-------------------------------+--------------------------------------------------+ |``has_perm(perm)`` |如果用户拥有给定的权限,返回 ``True`` , ``perm`` | | |应形如 ``"package.codename"`` 的格式。如果用户处于| | |非激活状态,则总是返回 ``False`` 。 | +-------------------------------+--------------------------------------------------+ |``has_perms(perm_list)`` |如果用户拥有所有给定的权限,返回 ``True`` 。 | | |如果用户处于非激活状态,则总是返回 ``False`` 。 | +-------------------------------+--------------------------------------------------+ |``has_module_perms(app_label)``|如果用户拥有任何给定 ``app_label`` 的权限,返回 | | |``True`` 。如果用户处于非激活状态,则总是返回 | | |``False`` | +-------------------------------+--------------------------------------------------+ |``get_and_delete_messages()`` |返回用户的 ``Message`` 对象列表,并从队列中删除。 | +-------------------------------+--------------------------------------------------+ |``email_user(subj, msg)`` |给用户发送电子邮件,用 ``DEFAULT_FROM_EMAIL`` 的设| | |置作为发件人。也可以用第3个参数 ``from_email`` 来 | | |覆盖设置。 | +-------------------------------+--------------------------------------------------+ |``get_profile()`` |返回用户的网站自定义profile,详见Profile章节 | +-------------------------------+--------------------------------------------------+
备注:
译者: