示例#1
0
文件: models.py 项目: kiennt/jupo
    def avatar(self):
        avatar = self.info.get('avatar')

        if avatar and isinstance(avatar, str) or isinstance(avatar, unicode):
            return avatar
        elif avatar:
            attachment = api.get_attachment_info(avatar, db_name=self.db_name)
            filename = '%s_60.jpg' % attachment.md5
            if attachment.md5 and api.is_s3_file(filename,
                                                 db_name=self.db_name):
                return 'https://%s.s3.amazonaws.com/%s' % (
                    settings.S3_BUCKET_NAME, filename)

            return '/img/' + str(avatar) + '.jpg'

        # try gravatar

        default = "https://5works.s3.amazonaws.com/images/user2.png"
        if not self.email:
            return default

        email = self.email.strip().lower()
        size = 50
        gravatar_url = "https://secure.gravatar.com/avatar/" + md5(
            email.lower()).hexdigest() + "?"
        gravatar_url += urlencode({'d': default, 's': str(size)})
        return gravatar_url
示例#2
0
文件: models.py 项目: Coderic/jupo
 def avatar(self):
   avatar = self.info.get('avatar')
   
   if avatar and isinstance(avatar, str) or isinstance(avatar, unicode):
     if 'googleusercontent' in avatar:
       avatar = avatar.replace('/photo.jpg', '/s60-c/photo.jpg')
     return avatar
   elif avatar:
     attachment = api.get_attachment_info(avatar, db_name=self.db_name)
     filename = '%s_60.jpg' % attachment.md5
     if attachment.md5 and api.is_s3_file(filename, db_name=self.db_name):
       return 'http://%s.s3.amazonaws.com/%s' % (settings.S3_BUCKET_NAME, filename)
     
     return '/img/' + str(avatar) + '.jpg'
   
   # try gravatar
   
   default = "http://jupo.s3.amazonaws.com/images/user2.png"
   if not self.email:
     return default
   
   email = self.email.strip().lower()
   size = 50
   gravatar_url = "http://www.gravatar.com/avatar/" + md5(email.lower()).hexdigest() + "?"
   gravatar_url += urlencode({'d':default, 's':str(size)})
   return gravatar_url
示例#3
0
文件: models.py 项目: duyminh215/jupo
 def avatar(self):
   avatar = self.info.get('avatar')
   if isinstance(avatar, str) or isinstance(avatar, unicode):
     return avatar
   elif avatar:
     attachment = api.get_attachment_info(avatar)
     filename = '%s_60.jpg' % attachment.md5
     if attachment.md5 and api.is_s3_file(filename):
       return 'https://%s.s3.amazonaws.com/%s' % (settings.S3_BUCKET_NAME, filename)
     
     return '/img/' + str(avatar) + '.jpg'
   
   # try gravatar
   email = self.email.strip().lower()
   default = "https://5works.s3.amazonaws.com/images/user2.png"
   size = 50
   gravatar_url = "https://secure.gravatar.com/avatar/" + md5(email.lower()).hexdigest() + "?"
   gravatar_url += urlencode({'d':default, 's':str(size)})
   return gravatar_url