def addWish(request): _userId= request.GET['userId'] _categoryId = request.GET['categoryId'] _minPrice = request.GET['minPrice'] _maxPrice= request.GET['maxPrice'] _brand= request.GET['brand'] record=Wish(userId=_userId,categoryId=_categoryId,minPrice=_minPrice,maxPrice=_maxPrice,brand=_brand) record.save() wishId = record.id return JSONResponse({'wishId':wishId})
def wishes(userid): iid = random.randint(1000, 9999) if (request.method == "POST"): iname = request.form['iname'] url = request.form['url'] details = request.form['details'] why_url = request.form['sav_url'] userid = session['uid'] wish = Wish(itemid=iid, userid=userid, item_name=iname, details=details, url=why_url, item_url=url) db.session.add(wish) db.session.commit() flash("Item added") return "OK" else: wish = Wish.query.filter_by(userid=userid) url = [] names = [] img_ids = [] dets = [] for u in wish: url += [u.item_url] names += [u.item_name] img_ids += [u.itemid] dets += [u.details] return jsonify({ "status": "OK", "error": None, "names": names, "ids": img_ids, "details": dets, "urls": url })
def apiadd(userid): if request.method == "POST": new_wish = Wish(wish_name_url=request.json['url'], wish_id=session['current_user'], wish_descript=request.json['description'], title=request.json['title'], thumbnail=request.json['image']) db.session.add(new_wish) db.session.commit() return redirect(url_for('wishers_page')) else: user = Person.query.filter_by(id=session['current_user']).first() userwishes = Wish.query.filter_by(wish_id=userid) return render_template('wishers_page.html', loggedUser=user, wishes=userwishes)
def create(self, title: str, price: str = None, link: str = None, description: str = None): if not title: raise Exception("Empty title!") try: price = float(price) except TypeError: price = None wish = Wish(title=title, price=price, link=link, description=description) self.session.add(wish) self.session.commit()
def apiadd(userid): if request.method == "POST": new_wish= Wish(wish_url=request.json['url'], user_id=userid , wish_descript=request.json['description'], wish_title=request.json['title'], thumbnail=request.json['image'], added=str(datetime.now())); db.session.add(new_wish) db.session.commit() response = jsonify({"error":"null","data":{},"message":"Success"}) return response else: user = Person.query.filter_by(id=userid).first() userwishes = Wish.query.filter_by(user_id=userid) wishlist = [] for wish in userwishes: wishlist.append({'id':wish.wish_id,'title': wish.wish_title,'description':wish.wish_descript,'url':wish.wish_url,'thumbnail':wish.thumbnail, 'added': wish.added}) if len(wishlist)>0: response = jsonify({"error":"null","data":{"wishes":wishlist}}) elif len(wishlist)==0: response = jsonify({"error":"null","data":{"wishes":[]}}) else: response = jsonify({"error":"1","message": "Failed. Please try again"}) return response
def apiadd(userid): if request.method == "POST": new_wish= Wish(wish_url=request.json['url'], user_id=userid , wish_descript=request.json['description'], wish_title=request.json['title'], thumbnail=request.json['image'], added=str(datetime.now())); db.session.add(new_wish)
def delete_wish(id): Wish.delete_wish(id) return redirect("/wishes")
def addwish(userid): if request.method == "POST": users = UserT.query.filter_by(id=wishid).first() jsonD = json.loads(request.data) wish = Wish(users.id, websiteaddr=jsonD.get('websiteaddr'), thumbnail=jsonD.get('thumbnail'), title=jsonD.get('title'), description=jsonD.get('description'), added_on=datetime.now().strftime("%Y-%m-%d")) if wish: db.session.add(wish) db.session.commit() response = jsonify({ "error": None, "data": { 'userid': userid, 'url': jsonD.get('websiteaddr'), 'thumbnail': wish.thumbnail, 'title': jsonD.get('title'), 'description': jsonD.get('description') }, "message": "Success" }) else: response = jsonify({ "error": "1", "data": {}, 'message': 'wish not made' }) elif request.method == "DELETE": users = UserT.query.filter_by(id=wishid).first() jsonD = json.loads(request.data) wish = Wish(users.id, websiteaddr=jsonD.get('websiteaddr'), thumbnail=jsonD.get('thumbnail'), title=jsonD.get('title'), description=jsonD.get('description'), added_on=datetime.now().strftime("%Y-%m-%d")) if wish: db.session.delete(wish) db.session.commit() response = jsonify({ "error": None, "data": { 'userid': userid, 'url': jsonD.get('websiteaddr'), 'thumbnail': wish.thumbnail, 'title': jsonD.get('title'), 'description': jsonD.get('description') }, "message": "Success" }) else: response = jsonify({ "error": "1", "data": {}, 'message': 'wish not made' }) else: users = UserT.query.filter_by(id=userid).first() wishes = Wish.query.filter_by(userid=users.id).all() wishl = [] for wish in wishes: wishl.append({ 'title': wish.name, 'websiteaddr': wish.websiteaddr, 'thumbnail': wish.thumbnail, 'description': wish.description, 'added_on': timeI(wish.added_on) }) if (len(wishl) > 0): response = jsonify({ "error": "null", "data": { "user": users.firstname + " " + users.lastname, "wishes": wishl }, "message": "Success" }) else: response = jsonify({ "error": "1", "data": {}, "message": "Unable to get wishes" }) return response
def wishlist(userid): form = WishForm() form2 = LoginForm() if request.method == "POST": if form.validate_on_submit(): user = db.session.query(UserProfile).filter_by(id=userid).first() url = form.url.data thumbnail = form.thumbnail.data title = form.thumbnail.data description = form.description.data wish = Wish(url=url, thumbnail=thumbnail, title=title, description=description, userid=user.id) if wish: db.session.add(wish) db.session.commit() flash('' + title + ' was added to your wishlist', 'success') response = jsonify({ "error": "null", "data": { 'userid': userid, 'url': url, 'thumbnail': thumbnail, 'title': title, 'description': description }, "message": "Success" }) return redirect(url_for('wishlist', userid=user.id)) else: response = jsonify({ "error": "1", "data": {}, "message": "Wish not created" }) flash('Invalid item data, please try again', 'danger') return redirect(url_for('wishlist', userid=user.id)) else: user = db.session.query(UserProfile).filter_by(id=userid).first() wishes = db.session.query(Wish).filter_by(userid=user.id).all() wishlist = [] for wish in wishes: wishlist.append({ 'title': wish.title, 'url': wish.url, 'thumbnail': wish.thumbnail, 'description': wish.description }) if (len(wishlist) > 0): response = jsonify({ "error": "null", "data": { "user": user.firstname + " " + user.lastname, "wishes": wishlist }, "message": "Success" }) else: response = jsonify({ "error": "1", "data": {}, "message": "Unable to get wishes" }) return render_template('wishlist.html', wishes=wishes, userid=userid, form=form, form2=form2)