本文整理汇总了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
示例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