本文整理汇总了Python中django.contrib.auth.models.User.profile方法的典型用法代码示例。如果您正苦于以下问题:Python User.profile方法的具体用法?Python User.profile怎么用?Python User.profile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.models.User
的用法示例。
在下文中一共展示了User.profile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getUserProfile
# 需要导入模块: from django.contrib.auth.models import User [as 别名]
# 或者: from django.contrib.auth.models.User import profile [as 别名]
def _getUserProfile(self):
if not self.is_authenticated:
return UserProfile()
profile, created = UserProfile.objects.get_or_create(user=self)
if created:
profile.tz = get_user_timezone(self.username)
if self.first_name:
if self.last_name:
profile.realname = "%s %s" % (self.first_name, self.last_name)
else:
profile.realname = self.first_name
if self.email:
h = hashlib.md5()
h.update(bytearray(profile.user.email, "utf8"))
profile.avatar = (
"https://www.gravatar.com/avatar/%s.jpg?d=mm" % h.hexdigest()
)
profile.save()
return profile
示例2: is_complete
# 需要导入模块: from django.contrib.auth.models import User [as 别名]
# 或者: from django.contrib.auth.models.User import profile [as 别名]
def is_complete(self):
"""Checks if a user's profile is completed"""
for field in self._meta.get_all_field_names():
try:
fieldattr = getattr(self, field)
if fieldattr == '':
return False
if type(fieldattr) == User:
if fieldattr.first_name == '' or fieldattr.last_name == '':
return False
except:
pass
return True
示例3: create_user_profile
# 需要导入模块: from django.contrib.auth.models import User [as 别名]
# 或者: from django.contrib.auth.models.User import profile [as 别名]
def create_user_profile(sender, instance, created, **kwargs):
"""Creates the user profile for a given User instance.
Args: sender, instance, created,
Sender: The model class,
Instance: The actual instance being saved,
Created: Boolean that defaults to True if user is created
"""
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User,
dispatch_uid=create_user_profile)
示例4: steam_info
# 需要导入模块: from django.contrib.auth.models import User [as 别名]
# 或者: from django.contrib.auth.models.User import profile [as 别名]
def steam_info(self):
steam = self.user.social_auth.get(provider='steam')
# Have we updated this profile recently?
if 'last_updated' in steam.extra_data:
# Parse the last updated date.
last_date = parse_datetime(steam.extra_data['last_updated'])
seconds_ago = (now() - last_date).seconds
# 3600 seconds = 1 hour
if seconds_ago < 3600:
return steam.extra_data['player']
try:
player = requests.get(USER_INFO, params={
'key': settings.SOCIAL_AUTH_STEAM_API_KEY,
'steamids': steam.uid
}).json()
if len(player['response']['players']) > 0:
steam.extra_data = {
'player': player['response']['players'][0],
'last_updated': now().isoformat(),
}
steam.save()
except:
pass
return steam.extra_data['player']
示例5: get_absolute_url
# 需要导入模块: from django.contrib.auth.models import User [as 别名]
# 或者: from django.contrib.auth.models.User import profile [as 别名]
def get_absolute_url(self):
if self.has_steam_connected():
return reverse('users:player', kwargs={
'platform': 'steam',
'player_id': self.user.social_auth.get(provider='steam').uid
})
return reverse('users:profile', kwargs={
'username': self.user.username
})