def get_reviews(request): try: session = dbsession.Session() columns = ['reg_id','customer_id','customer_name','customer_gender','customer_phone','customer_username','customer_password','customer_type','customer_status'] docsql = text('SELECT * FROM demodb.user_signup') reviewList = session.execute(docsql).fetchall() review_list = [dict(row) for row in reviewList] review_list = json.dumps(review_list, cls=AlchemyEncoder) review_list = pd.read_json(review_list) if columns: review_list.columns = columns review_list = review_list.to_json(orient='records') session.close() return Response({'response': 'Success', 'reviews_list': json.loads(review_list)}) except SQLAlchemyError as e: session.rollback() session.close() return Response({'response': 'Error occured'})
def get_category(request): try: session = dbsession.Session() columns = ['cat_id','cat_name','cat_imageurl','cat_status'] docsql = text('SELECT * FROM demodb.product_categoery;') reviewList = session.execute(docsql).fetchall() review_list = [dict(row) for row in reviewList] review_list = json.dumps(review_list, cls=AlchemyEncoder) review_list = pd.read_json(review_list) if columns: review_list.columns = columns review_list = review_list.to_json(orient='records') session.close() return Response({'response': 'Success', 'reviews_list': json.loads(review_list)}) except SQLAlchemyError as e: session.rollback() session.close() return Response({'response': 'Error occured'})
def get_home(request): try: session = dbsession.Session() cardnumber = request.GET.get('cust_cardnmbr') columns = ['home_id','home_heading','home_tablename','home_subcategoryname','home_categoryname','home_suburl','home_offer','home_background','home_cardnumber'] docsql = text('SELECT * FROM demodb.User_home where home_cardnumber='"+cardnumber+"'') reviewList = session.execute(docsql).fetchall() review_list = [dict(row) for row in reviewList] review_list = json.dumps(review_list, cls=AlchemyEncoder) review_list = pd.read_json(review_list) if columns: review_list.columns = columns review_list = review_list.to_json(orient='records') session.close() return Response({'response': 'Success', 'reviews_list': json.loads(review_list)}) except SQLAlchemyError as e: session.rollback() session.close() return Response({'response': 'Error occured'})
def saveRegister(request): try: session = dbsession.Session() idd = request.data['customer_id'] name=request.data['Name'] gender= request.data['gender'] phone = request.data['phone'] username =request.data['username'] password = request.data['password'] types = request.data['type'] status = request.data['status'] email_check = session.query(Login).filter(Login.customer_username==username).all() if(len(email_check) > 0): return Response({'status': 'email Id exists','message':'email Id already exists'}) phno_check = session.query(Login).filter(Login.customer_phone==phone).all() if(len(phno_check) > 0): return Response({'status': 'phone num exists','message':'phone num already exists'}) user_signup = Login() user_signup.customer_id = idd user_signup.customer_name= name user_signup.customer_gender= gender user_signup.customer_phone = phone user_signup.customer_username = username user_signup.customer_password = password user_signup.customer_type = types user_signup.customer_status = status session.add(user_signup) session.commit() session.close() return Response({'response': 'Data saved success fully'}) except SQLAlchemyError as e: print(e) session.rollback() session.close() return Response({'response': 'Error occured'}) # //////////Adv @api_view(['GET','POST']) @permission_classes([AllowAny, ]) def get_adv(request): try: session = dbsession.Session() columns = ['adv_id','adv_name','adv_imageurl','adv_status'] docsql = text('SELECT * FROM demodb.first_advertisement') reviewList = session.execute(docsql).fetchall() review_list = [dict(row) for row in reviewList] review_list = json.dumps(review_list, cls=AlchemyEncoder) review_list = pd.read_json(review_list) if columns: review_list.columns = columns review_list = review_list.to_json(orient='records') session.close() return Response({'response': 'Success', 'reviews_list': json.loads(review_list)}) except SQLAlchemyError as e: session.rollback() session.close() return Response({'response': 'Error occured'}) # /////////categoryview # //////////Adv @api_view(['GET','POST']) @permission_classes([AllowAny, ]) def get_category(request): try: session = dbsession.Session() columns = ['cat_id','cat_name','cat_imageurl','cat_status'] docsql = text('SELECT * FROM demodb.product_categoery;') reviewList = session.execute(docsql).fetchall() review_list = [dict(row) for row in reviewList] review_list = json.dumps(review_list, cls=AlchemyEncoder) review_list = pd.read_json(review_list) if columns: review_list.columns = columns review_list = review_list.to_json(orient='records') session.close() return Response({'response': 'Success', 'reviews_list': json.loads(review_list)}) except SQLAlchemyError as e: session.rollback() session.close() return Response({'response': 'Error occured'})