def editUser(form): if form.validate_on_submit(): session = DBSession() user = session.query(User).filter(User.id == current_user.id).update({ 'title': form.title.data, 'fname': form.fname.data, 'lname': form.lname.data, 'username': form.username.data, 'email': form.email.data, 'password': generate_password_hash(form.newpassword.data), 'address': form.address.data, 'state': form.state.data, 'is_Admin': False }) if user is not None: session.commit() return redirect(url_for('editaccount')) return render_template('editaccount.html', form=form)
def get_all_ip(): """ 获取所有IP :return: """ session = DBSession() ip_list = session.query(ProxyPool).all() result = [item.to_dict() for item in ip_list] return result
def authenticate(form): if form.validate_on_submit(): try: session = DBSession() user = session.query(User).filter(User.email == formLogin.email.data).first() except :# models.DoesNotExist: flash("Your email or password does not match !", "error") else : if user is not None: if check_password_hash(user.password,form.password.data): login_user(user, remember = form.remember.data) flash("You've been logged in", "success") return render_template('index') else : flash("Your email or password does not match !", "error") return render_template('login.html',formLogin = form) return render_template('login.html',formLogin = form)
def authenticate(form): if form.validate_on_submit(): try: session = DBSession() user = session.query(User).filter( User.email == formLogin.email.data).first() except: # models.DoesNotExist: flash("Your email or password does not match !", "error") else: if user is not None: if check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) flash("You've been logged in", "success") return render_template('index') else: flash("Your email or password does not match !", "error") return render_template('login.html', formLogin=form) return render_template('login.html', formLogin=form)
def editUser(form): if form.validate_on_submit(): session = DBSession() user = session.query(User).filter(User.id == current_user.id).update({ 'title' : form.title.data, 'fname' : form.fname.data, 'lname' : form.lname.data, 'username' : form.username.data, 'email' : form.email.data, 'password' : generate_password_hash(form.newpassword.data), 'address' : form.address.data, 'state' : form.state.data, 'is_Admin' : False }) if user is not None : session.commit() return redirect(url_for('editaccount')) return render_template('editaccount.html',form= form)
def collections(self): print 'The userid is %d' % g.user.id session = DBSession() #products = session.query(Product).filter(Product.user_id == g.user.id).all() products = session.query(User) \ .join(User.products) \ .join(Product.productitems) \ .group_by(Product.id,Product.created_date,Product.title) \ .order_by(Product.created_date) \ .values( Product.id.label('product_id'), Product.title.label('title'), Product.created_date.label('created_date'), (func.row_number().over(order_by='products.created_date').label('number')), (func.count(ProductItem.id)).label('total')) if products is not None: if(self.request.method =='GET'): return render_template('user_collections.html',products=products) return render_template('user_collections.html',products=products)
def collections(self): print 'The userid is %d' % g.user.id session = DBSession() #products = session.query(Product).filter(Product.user_id == g.user.id).all() products = session.query(User) \ .join(User.products) \ .join(Product.productitems) \ .group_by(Product.id,Product.created_date,Product.title) \ .order_by(Product.created_date) \ .values( Product.id.label('product_id'), Product.title.label('title'), Product.created_date.label('created_date'), (func.row_number().over(order_by='products.created_date').label('number')), (func.count(ProductItem.id)).label('total')) if products is not None: if (self.request.method == 'GET'): return render_template('user_collections.html', products=products) return render_template('user_collections.html', products=products)
def update_ip(item): """ 更新代理IP :param item: :return: """ ip_item = ProxyPool(item) session = DBSession() try: session.merge(ip_item) session.commit() except Exception as e: session.rollback() raise e
def insert_into_proxypool(item): """ 插入代理IP :param item: :return: None """ ip_item = ProxyPool(item) session = DBSession() try: session.add(ip_item) session.commit() except Exception as e: session.rollback() raise e
def delete_ip(item): """ 删除代理IP :param item: :return: """ session = DBSession() ip_item = session.query(ProxyPool).filter(ProxyPool.id == item['id']).first() if ip_item: try: session.delete(ip_item) session.commit() except Exception as e: raise e
def get_collection(): product_id = urllib.quote_plus(request.args.get('product_id')) print product_id session = DBSession() product = session.query(Product).filter(Product.id == product_id).first() session = DBSession() productItems = session.query(ProductItem).filter( ProductItem.product_id == product_id).all() #collectionData = ([product.serialize for product in productItems]) return jsonify( productItems=[product.serialize for product in productItems])
def editCollection(self): product_id = self.request.args.get('product_id') session = DBSession() product = session.query(Product).filter(Product.id == product_id).first() print 'the new w wwwwww is %s' %product_id session = DBSession() productItem = session.query(ProductItem).filter(ProductItem.product_id == product_id).all() if(product is not None): if(self.request.method == 'GET'): print 'it comes here' return render_template('editCollection.html',product=product, productItem = productItem) elif (self.request.method == 'POST') : print 'Its post' jsonData = json.loads(self.request.data) newProduct = None for data in jsonData : if ('collection_title' in data): session = DBSession() newProduct = session.query(Product).filter(Product.id == product_id).update({ 'title' : data['collection_title'], 'description' : data['collection_description'] } ) session.commit() if (newProduct is not None): print 'Its deleting ' print productItem session = DBSession() session.query(ProductItem).filter(ProductItem.product_id == product_id).delete() session.commit() elif(newProduct is not None): prodItem = ProductItem( image_url = data['image_url'], image_description = data['image_description'], product_id = product_id ) Item_id =InsertRow(prodItem) return json.dumps({'success': True}) return render_template('editCollection.html',product=product)
def load_user(userid): session = DBSession() return session.query(User).get(int(userid))
def editCollection(self): product_id = self.request.args.get('product_id') session = DBSession() product = session.query(Product).filter( Product.id == product_id).first() print 'the new w wwwwww is %s' % product_id session = DBSession() productItem = session.query(ProductItem).filter( ProductItem.product_id == product_id).all() if (product is not None): if (self.request.method == 'GET'): print 'it comes here' return render_template('editCollection.html', product=product, productItem=productItem) elif (self.request.method == 'POST'): print 'Its post' jsonData = json.loads(self.request.data) newProduct = None for data in jsonData: if ('collection_title' in data): session = DBSession() newProduct = session.query(Product).filter( Product.id == product_id).update({ 'title': data['collection_title'], 'description': data['collection_description'] }) session.commit() if (newProduct is not None): print 'Its deleting ' print productItem session = DBSession() session.query(ProductItem).filter( ProductItem.product_id == product_id).delete() session.commit() elif (newProduct is not None): prodItem = ProductItem( image_url=data['image_url'], image_description=data['image_description'], product_id=product_id) Item_id = InsertRow(prodItem) return json.dumps({'success': True}) return render_template('editCollection.html', product=product)