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


Python User.avatar方法代码示例

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


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

示例1: newuser

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import avatar [as 别名]
 def newuser(*args, **kwargs):
     '''
     Usage : newuser()
     The only method to create a new user
     call this method first, modify the return value which is a database row instance,then call self.register()
     '''
     user_new = User('newuser', 'asdf1234')
     user_new.user_group = 'primary'
     user_new.avatar = 'default.png'
     return user_new
开发者ID:Puppy95,项目名称:docklet,代码行数:12,代码来源:userManager.py

示例2: newuser

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import avatar [as 别名]
 def newuser(*args, **kwargs):
     '''
     Usage : newuser()
     The only method to create a new user
     call this method first, modify the return value which is a database row instance,then call self.register()
     '''
     user_new = User('newuser', 'asdf1234')
     quotafile = open(fspath+"/global/sys/quotainfo",'r')
     quotas = json.loads(quotafile.read())
     quotafile.close()
     user_new.user_group = quotas['default']
     user_new.avatar = 'default.png'
     return user_new
开发者ID:DreamReaver,项目名称:docklet,代码行数:15,代码来源:userManager.py

示例3: __get_attributes

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import avatar [as 别名]
  def __get_attributes(self, res):
    if res.status_code != 200:
      return

    main = BeautifulSoup(res.content)('div', id='viewprofile')
    if len(main) == 0:
      return

    profile_str = str(main[0])
    profile_str = profile_str \
                  .replace('Настоящее имя:', 'username') \
                  .replace('Пол:', 'sex') \
                  .replace('Женский', 'female') \
                  .replace('Мужской', 'male') \
                  .replace('Возраст:', 'birthday') \
                  .replace('Местонахождение:', 'location') \
                  .replace('Зарегистрирован:', 'registered') \
                  .replace('Провел на форуме:', 'on_board') \
                  .replace('ICQ:', 'icq') \
                  .replace('Skype:', 'skype') \
                  .replace('Mail Agent:', 'mail_agent') \
                  .replace('Обо мне:', 'about') \
                  .replace('Сообщений:', 'posts_num') \
                  .replace('Интересы:', 'interests')

    profile = BeautifulSoup(profile_str)

    # self.response.out.write(profile.extract())
    # return
    fields = [
      'nickname',
      'rolename',
      'username',
      'sex',
      'birthday',
      'location',
      'registered',
      'avatar',
      'signature',
      'icq',
      'skype',
      'mail_agent',
      'about',
      'posts_num',
      'interests'
    ]

    lis = profile('li')
    nickname = lis.pop(0).strong.string
    rolename = lis.pop(0).strong.string
    avatar = lis.pop(0)
    signature = profile('div', id='profile-signature')

    def get_attr(li):
      if li.span:
        if li.span.string == 'posts_num':
          return ('posts_num', re.search('\d+', str(li.strong)).group())
        return (li.span and li.span.string, li.strong.string)
      return ('', '')

    attributes = dict(map(get_attr, lis))

    attributes['nickname'] = nickname
    attributes['rolename'] = rolename
    attributes['avatar'] = avatar.div and avatar.div.img['src']
    attributes['signature'] = signature and signature[0]('p')[0]

    user = User()
    for key in fields:
      val = attributes.get(key)
      if val:
        if key == 'birthday':
          birthday = re.search(r'\((.*)\)', val).group(1)
          user.birthday = datetime.strptime(birthday, '%Y-%m-%d').date()
        elif key == 'registered':
          user.registered = datetime.strptime(val, '%Y-%m-%d').date()
        elif key == 'posts_num':
          user.posts_num = int(val)
        elif key == 'avatar':
          if val:
            avatar = urlfetch.fetch('http://uarat.3bb.ru/' + val).content
            if avatar:
              user.avatar = db.Blob(avatar)
        else:
          user.__dict__['_' + key] = unicode(val)
    return user
开发者ID:ignovak,项目名称:uarat,代码行数:88,代码来源:admin.py


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