當前位置: 首頁>>代碼示例>>Python>>正文


Python User.profile方法代碼示例

本文整理匯總了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 
開發者ID:GetTogetherComm,項目名稱:GetTogether,代碼行數:26,代碼來源:profiles.py

示例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 
開發者ID:andela,項目名稱:troupon,代碼行數:15,代碼來源:models.py

示例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) 
開發者ID:andela,項目名稱:troupon,代碼行數:15,代碼來源:models.py

示例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'] 
開發者ID:rocket-league-replays,項目名稱:rocket-league-replays,代碼行數:32,代碼來源:models.py

示例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
        }) 
開發者ID:rocket-league-replays,項目名稱:rocket-league-replays,代碼行數:12,代碼來源:models.py


注:本文中的django.contrib.auth.models.User.profile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。