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


Python Member.set_flag方法代码示例

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


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

示例1: post

# 需要导入模块: from model import Member [as 别名]
# 或者: from model.Member import set_flag [as 别名]
 def post(self):
     errors = []
     username = str(self.get_cookie('username',''))
     userflag = str(self.get_cookie('userflag',''))
     if not username or not userflag:
         self.write('403')
         return
     myfile = self.request.files.get('myfile',[0])[0]
     if myfile:
         im = Image.open(StringIO(myfile['body']))
         max_w = 73
         max_h = 73
         if im.size[0] > max_w or im.size[1] > max_w:
             ss = max(float(im.size[0])/max_w, float(im.size[1])/max_h)
             im = im.resize((int(im.size[0]/ss), int(im.size[1]/ss)), Image.ANTIALIAS)
         
         output = StringIO()
         im.convert('RGB').save(output, 'JPEG', quality = 95)#95
         img_data = output.getvalue()
         output.close()
         
         #self.set_header('Content-Type','image/jpeg')
         #self.write(img_data)
         #return
         
         if IMG_STORAGE=='sae':
             file_path_name = '%s.jpg'% username
             avatar = put_obj2storage(file_name = file_path_name, data = img_data, domain_name = DOMAIN_NAME_AVATAR)
         elif IMG_STORAGE=='upyun':
             u = UpYun(DOMAIN_NAME_AVATAR, UPYUN_USER, UPYUN_PW)
             file_path_name = '/avatar/%s.jpg'% username
             avatar = u.writeFile( file_path_name, img_data, True)
         
         if avatar:
             if username == 'admin':
                 Member.set_flag(username, '99')
             if userflag == '1':
                 if Member.set_flag(username, '2'):
                     self.set_cookie('userflag', '2', path="/", expires_days = 365 )
                     clear_cache_multi(['cur_user:' + username])
                     self.redirect('/setavatar')
                     return
                 else:
                     errors.append('服务器暂时出错,请稍后再试')
             else:
                 self.redirect('/setavatar')
                 return
         else:
             errors.append('保存图片出错,请稍后再试')
     else:
         errors.append('图片没有正确上传')
         
     self.echo('setavatar.html', {
         'title': "设置头像",
         'errors':errors,
         'wb_avatar_large': '',
     }, layout='_layout.html')
开发者ID:QiaoHaiZhong,项目名称:rebang,代码行数:59,代码来源:view.py

示例2: get

# 需要导入模块: from model import Member [as 别名]
# 或者: from model.Member import set_flag [as 别名]
 def get(self):
     #尝试读取QQ空间头像
     wb_avatar_large = ''
     qq = self.get_argument('qq', '')
     if qq=='1':
         username = str(self.get_cookie('username',''))
         open_id = str(self.get_cookie('open_id',''))
         access_token = str(self.get_cookie('access_token',''))
         userflag = str(self.get_cookie('userflag',''))
         if username and open_id and access_token and userflag:
             qq_user = qqclient.get_user_info(access_token, open_id)
             #qq_user { "ret":0, "msg":"", "nickname":"qq nicke name", "figureurl_2":"http://qzapp.qlogo.cn/qzapp/100254539/5BDCA5E6321B273E44720E532B1379ED/100" }
             #保存有用的信息
             #id = str(open_id)
             #name = en_code(qq_user['nickname'])
             wb_avatar_large = str(qq_user.get('figureurl_2',''))
             
             headers = {
                 'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',
                 'Referer':wb_avatar_large,
             }
             req = urllib2.Request(
                 url = wb_avatar_large,
                 headers = headers
             )
             data = urllib2.urlopen(req).read()
             if data:
                 im = Image.open(StringIO(data))
                 if im.size[0] > 73 or im.size[1] > 73:
                     ss = max(float(im.size[0])/73, float(im.size[1])/73)
                     box = (int(im.size[0]/ss), int(im.size[1]/ss))
                     im = im.resize(box, Image.ANTIALIAS)
                     output = StringIO()
                     im.convert('RGB').save(output, 'JPEG', quality = 95)#95
                     img_data = output.getvalue()
                     output.close()
                     
                 else:
                     img_data = data
                 
                 if IMG_STORAGE=='sae':
                     file_path_name = '%s.jpg'% username
                     avatar = put_obj2storage(file_name = file_path_name, data = img_data, domain_name = DOMAIN_NAME_AVATAR)
                 elif IMG_STORAGE=='upyun':
                     u = UpYun(DOMAIN_NAME_AVATAR, UPYUN_USER, UPYUN_PW)
                     file_path_name = '/avatar/%s.jpg'% username
                     avatar = u.writeFile( file_path_name, img_data, True)
                 
                 if avatar:
                     if userflag == '1':
                         if Member.set_flag(username, '2'):
                             self.set_cookie('userflag', '2', path="/", expires_days = 365 )
                             clear_cache_multi(['cur_user:' + username])
                             #self.redirect('/')
                             #return
     
     self.echo('setavatar.html', {
         'title': "设置头像",
         'errors':[],
         'newest_node': Node.get_newest(),
         'wb_avatar_large': wb_avatar_large,
     }, layout='_layout.html')
开发者ID:QiaoHaiZhong,项目名称:rebang,代码行数:64,代码来源:view.py


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