Example #1
0
 def selleraddCpinOk_view(self):
     request = self.request
     sid = self.request.params['sid']
     price = self.request.params['price']
     caiName = self.request.params['caiName']
     pic = self.request.params['pic']
     if not pic.name:
         return {'error': u'请选择文件后再上传'}
     file = pic.file
     ext = pic.filename.split('.').pop()
     # ../这样的目录却发现文件上传到workspace目录下,于是就出现了如下的目录结构
     save_path = '../canyin/canyin/upload/'
     save_path = PROJECT_PATH + '/static/upload/'
     print save_path
     date_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
     print date_time
     new_file = (date_time + '.' + ext.lower())
     destination = open(save_path + new_file, 'wb+')
     while True:
         data = file.read(2 << 16)
         if not data:
             break
         destination.write(data)
     destination.close()
     # 上传成功后将数据保存到数据库
     picPath = '../static/upload/' + new_file
     print picPath
     params = {'sid': sid, 'price': price, 'caiName': caiName, 'pic': date_time}
     Seller.sellerAdd(self.mongodb, **params)
     return {'one': 'yes'}
Example #2
0
 def sellerRegist_view(self):
     if self.request.method == 'POST':
         form = Form(self.request,
                     schema=RegistForm, defaults={},
                     state=State(request=self.request))
         if form.validate():
             request = self.request
             sName = form.data['sname']
             pwd = form.data['pwd']
             tel = form.data['tel']
             email = form.data['email']
             address = form.data['address']
             sDetail = form.data['sDetail']
             params = {'sName': sName, 'pwd': encrypt(pwd), 'tel': tel, 'email': email, 'address': address,
                       'sDetail': sDetail}
             result = Seller.sellerRegist(self.mongodb, **params)
             if result is not None:
                 param = {'sName': sName, 'pwd': encrypt(pwd)}
                 user = Seller.sellerlogin(self.mongodb, **param)
                 self.request.session['user'] = user
                 headers = remember(self.request, ['id'])
                 return HTTPFound('/seller/show', headers=headers)
             else:
                 return {'form': form}
     return {'regist': 'test'}
Example #3
0
 def sellerlogin_view(self):
     if self.request.method == 'POST':
         form = Form(self.request,
                     schema=LoginForm, defaults={},
                     state=State(request=self.request))
         vcode = self.request.POST['validateCode']
         _csrf = self.request.POST['_csrf']
         ret = requests.get("http://open.weidianbao.com/validate/code/json?vcode=" + vcode + "&token=" + _csrf)
         retJson = json.loads(ret.content)
         if not retJson['success']:
             form.errors.update({"hint": u'验证码不正确!'})
             return {"form": form}
         if form.validate():
             sName = form.data['sname']
             pwd = form.data['pwd']
             params = {'sName': sName, 'pwd': encrypt(pwd)}
             result = Seller.sellerlogin(self.mongodb, **params)
             print result
             if result is not None:
                 self.request.session['user'] = result
                 headers = remember(self.request, result['id'])
                 return HTTPFound('/seller/show', headers=headers)
     return {'form': 'beiju'}
Example #4
0
 def sellershow_view(self):
     request = self.request
     params = 1
     mongodb = self.mongodb
     result = Seller.sellershow(mongodb, params)
     return {'result': result}