当前位置: 首页>>代码示例>>Python>>正文


Python User.is_staff方法代码示例

本文整理汇总了Python中accounts.models.User.is_staff方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_staff方法的具体用法?Python User.is_staff怎么用?Python User.is_staff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在accounts.models.User的用法示例。


在下文中一共展示了User.is_staff方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _user_from_ldap

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import is_staff [as 别名]
    def _user_from_ldap(self, entity, password=None):
        is_new = False
        try:
            user = User.objects.get(username=entity["uid"][0])
        except User.DoesNotExist:
            is_new = True
            user = User(username=entity["uid"][0])
            user.is_staff = True
            user.is_superuser = False
            user.save()

        if password and user.check_password(password) is False:
            user.set_password(password)
        user.is_staff = True
        for k, kmap in (
                ("first_name", "givenName"),
                ("last_name", "sn"),
                ("email", "mail"),
                ("gid", "gidnumber"),
                ("uid", "uidnumber"),
                ("date_joined", "whencreated"),
                ("country", "co"),
                ("department", "department"),
                ("photo", "thumbnailphoto"),
                ):
            if k == "date_joined":
                val = datetime.strptime(entity.get(kmap)[0][:-3], "%Y%m%d%H%M%S")
            elif k == "photo" and is_new == True:
                photo_data = entity.get(kmap)[0]
                photo_io_origin = StringIO(photo_data)
                photo_img = Image.open(photo_io_origin)
                photo_side = min(photo_img.size)
                photo_croped = photo_img.crop((0, 0, photo_side, photo_side))
                photo_croped.thumbnail(settings.THUMBNAIL_SIZE_HEAD, Image.ANTIALIAS)
                photo_io_processed = StringIO()
                photo_croped.save(photo_io_processed, 'png')
                photo_io_origin.close()
                photo_io_processed.seek(0)

                val = InMemoryUploadedFile(
                        photo_io_processed,
                        None,
                        "{0}_{1}.png".format(user.first_name.lower(), user.last_name.lower()),
                        "image/png",
                        len(photo_data),
                        None
                    )
            else:
                val = entity.get(kmap)[0]
            if not val:
                continue
            setattr(user, k, val)
        user.save()
        return user
开发者ID:dreampuf,项目名称:deliverman,代码行数:56,代码来源:admin.py

示例2: authenticate

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import is_staff [as 别名]
    def authenticate(self, token):
        response_profile = requests.get(
            'https://graph.facebook.com/me/',
            params={
                'access_token': token,
            }
        )

        facebook_profile = response_profile.json()

        if 'error' in facebook_profile:
            return None

        try:
            user = User.objects.get(facebook_id=facebook_profile.get('id'))
        except User.DoesNotExist:
            user = User(facebook_id=facebook_profile.get('id'))

        if facebook_profile.get('id') in settings.FACEBOOK_ADMINS:
            user.is_staff = True
            user.is_superuser = True

        user.username = facebook_profile.get('id')
        user.set_unusable_password()
        user.facebook_access_token = token
        user.email = facebook_profile.get('email', '')
        user.first_name = facebook_profile.get('first_name')
        user.last_name = facebook_profile.get('last_name')
        user.save()

        return user
开发者ID:DjangoLover,项目名称:djangodash2013,代码行数:33,代码来源:backends.py


注:本文中的accounts.models.User.is_staff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。