def profile(request): from application.models import Plans data=check_cookie(request) if data==None: return redirect("/u/") else: import json # from contracts.models import Contracts dd= json.loads(data) u = User.objects.get(email=dd["e"]) ud = {} ud["email"] = u.email ud["fn"] = u.first_name ud["ln"] = u.last_name ud["pav"] = True ud["phno"] = u.phone_number ud["gender"] = u.gender ud["pp"] = u.profile_image if ud["pp"]=="No": ud["pav"] = False ud["fullname"] = u.first_name + " " + u.last_name ud["addr"] = u.address # c = Contracts.objects.get(contract_name=u.contract_name) ud["col"] = u.contract_name.contract_name ud["coladdr"] = u.contract_name.contract_address p = Plans.objects.get(user = u) if p.plan=="None": ud["plan"] = "Currently you have no plan." else: ud["plan"] = p.plan + " Kit." print(ud) ud["tot"] = u.order_dashboard.total_orders qr = u.qr_code_data return render(request,"profile.html",{"data":data,"ud":ud,"qr_code":qr.decode('utf-8')})
def render_track(request): data=check_cookie(request) if data==None: return render(request,"/u/") else: from tracking_system.models import Tracker from user.models import User from dashboard.models import Order_DashBoard import json d = json.loads(data) res = {} try: u = User.objects.get(email=d["e"]) dash = Order_DashBoard.objects.get(email=u) if(dash.recent_date==""): res["status"] = "" else: t = Tracker.objects.get(track_id = u,date = dash.recent_date,time=dash.recent_time) tt= json.loads(t.completed_status) res["status"] = t.type_op res["odate"] = str(t.created_date.strftime("%Y-%m-%d %H:%M:%S %p")) res["date"] = str(t.completion_date.strftime("%Y-%m-%d %H:%M:%S %p")) res["data"] = tt except Exception as exp: print(exp) res["status"]="" return render(request,"trackOrder.html",{"data":data,"cdata":json.dumps(res)})
def user_login_page(request): data=check_cookie(request) if data==None: return render(request,"user.html",{"data":False}) else: return redirect("/dashboard")
def start_transaction(request): e="" res = {} u=None try: # appId= request.user[] # orderId= request. # try: # print("1") e = check_cookie(request) if e==None: res["status"] = False res["err"] = "You have logged out." res["log"] = True return render(request,"check-billing.html",{"data":res}) # except: # print(request.user) except: res["status"] = False res["err"] = "You have logged out." res["log"] = True return render(request,"check-billing.html",{"data":res}) try: e = json.loads(e) e=e["e"] print(e) from user.models import User u = User.objects.get(email=str(e)) print(u) except Exception as err: print(err) res["status"] = False res["err"] = "You have logged out." res["log"] = True return render(request,"check-billing.html",{"data":res}) if(check_amount(request.POST["amount"],u,request.POST["plan"])): postData = { "aid" : cust_set.appId, "oid" : createOrderId(u,request.POST["plan"],request.POST["amount"]), "oa" : request.POST["amount"], "oc" : request.POST["cur"], "on" : create_random_note(), "cn" : u.first_name+" "+u.last_name, "sk":cust_set.secret_key, "ce" : u.email, "cp" : u.phone_number, "rurl":"http://*****:*****@cashfree.com", "9999999999", "aakjakjakja") postData["status"] = True if(req.status_code==200): return render(request,"check-billing.html",{"data":postData}) res["status"] = False res["err"] = "Error conneting to the payment gatway. Try later." res["log"] = False return render(request,"check-billing.html",{"data":res})
def open_dashboard_page(request): print(request.POST) data = check_cookie(request) print("dash",data) if data==None: return redirect("/u/") else: # try: from application.models import Plans data = json.loads(data) print(type(data)) u = User.objects.get(email=data["e"]) # print("got and saving") # u.order_dashboard.process_ordered_dates({"shirts":3,"pants":4,"s":3,"c":4,"f":1,"t":3}) # u.order_dashboard.save() mr = {"1": "January","2":"February","3":"March","4":"April","5":"May","6":"June","7":"July","8":"August","9":"September","10":"October","11":"November","12":"December"} year = u.order_dashboard.get_years() month = u.order_dashboard.get_starting_month() d = str(datetime.strptime(datetime.now(tz=settings.ist_info).strftime("%Y-%m-%d %H:%M:%S %p"),"%Y-%m-%d %H:%M:%S %p")) y = d.split()[0].split("-")[0] d = d.split()[0].split("-")[1] month = [ month, int(d) ] if(int(y)!=int(year["years"][0])): year["years"].insert(0,int(y)) print("year added") year["years"].sort(reverse=True) u.order_dashboard.years = json.dumps(year["years"]) u.order_dashboard.save() # for i in year: # years = json.loads(u.order_dashboard.years) # months = u.order_dashboard.get_months() # # data = u.order_dashboard.get_ordered_date() # orders_month = u.order_dashboard.get_month_data(months[0],years[0]) # orders_completion = u.order_dashboard.get_all_completion_details(months[0],years[0]) # if u.order_dashboard.overflown == True: # res = Overflown_Orders_Data.objects.get(email=u) # for item in res: # if orders_month==None: # orders = od.process_ordered_dates({"shirts":3,"pants":4}) # od.ordered_dates = json.dumps(orders['orders']) # print("Od : ",od.ordered_dates) # od.save() # orders = od.get_ordered_date() # except Exception as e: # print(e) # da = {"data":{"months":months,"years":years,"month_data":orders_month,"completion_data":orders_completion}} # print(da) # da = json.dumps(da) pdata = {"notify":False,"cavailable":False} try: p = Plans.objects.get(user=u) print(datetime.strptime(datetime.now(tz=settings.ist_info).strftime("%Y-%m-%d %H:%M:%S %p"),"%Y-%m-%d %H:%M:%S %p")) diff = p.end_date - datetime.strptime(datetime.now(tz=settings.ist_info).strftime("%Y-%m-%d %H:%M:%S %p"),"%Y-%m-%d %H:%M:%S %p") pdata["diff"] = str(diff) pdata["cavailable"] = True pdata["c"] = p.extra_amount if diff.days<0: pdata["over"] = True p.plan = "None" p.save() elif diff.days==0: pdata["over"] = True p.plan = "None" p.save() else: # if diff.hours>=12: # pdata["diff"] = pdata["diff"] + " PM" # else: # pdata["diff"] = pdata["diff"] + " AM" pdata["over"] = False if p.notified==True: pdata["notify"] = True p.notified = False p.save() print("over") except: pdata["over"] = True if pdata["over"]==True: pdata["plans"] = [] from wasche.custom_settings import settings as sett for i in sett.plan.keys(): pdata["plans"].append((i,sett.plan[i])) print(pdata) rtc = 0 if u.plans.plan!="None": rtc = settings.regular_count[u.plans.plan] return render(request,"dash.html",{"data":json.dumps(data),"ud":json.dumps({"y":year,"m":month}),"pdata":pdata,"rcount":u.plans.regular_count,"ocount":u.plans.other_count,"rtcount":rtc,"otcount":settings.other_count})