def ca_nhan(): if "token" in session: user = session["token"] info = User.objects(username=user).first() att = Attribute.objects(username=user).first() hstr_list = All_history.objects(user=user) qt_list = Quote.objects(username=user) if request.method == "GET": return render_template("ca_nhan.html", info=info, att=att, quotes=qt_list, history=hstr_list) else: form = request.form quote = form["quote"] author = form["author"] if author == "": q = Quote(username=user, quote=quote) else: q = Quote(username=user, quote=quote, author=author) q.save() return render_template("ca_nhan.html", info=info, att=att, quotes=qt_list, history=hstr_list) else: return redirect(url_for("sign_in"))
def hoat_dong(): if request.method == "GET": act_list = Activities.objects() return render_template("hoat_dong.html", act = act_list) else: if "token" in session: user = session["token"] form = request.form act_list = Activities.objects() att_list = Attribute.objects(username = user).first() hstr_list = All_history.objects(user = user) for att in att_list: sort = form.get(att) if sort != None: return redirect("/hoat-dong-sx-ttt-" + att) for act in act_list: action = form.get(act["tit"]) if action != None: hstr = All_history(user = user, tit = act["tit"], cre = act["cre"], st = act["st"], knl = act["knl"], per = act["per"], soc = act["soc"] ) for att in att_list : if att in act and att != "id": att_list[att] = att_list[att] + act[att] if att_list[att] < 0: att_list[att] = 0 att_list.save() hstr.save() break return redirect("/save_post") else: return redirect(url_for("sign_in"))
def hoat_dong_sx_ttt(sort): if request.method == "GET": act_list = Activities.objects() return render_template("hoat_dong_sx_ttt.html", acts = act_list, sort = sort,name = session["token"],avt="https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png") else: if "token" in session: user = session["token"] form = request.form att_list = Attribute.objects(username = user).first() act_list = Activities.objects() toan_bo = form.get("all") if toan_bo != None: return redirect("/hoat-dong") for att in att_list: if att in form: return redirect("/hoat-dong-sx-ttt-" + att) else: pass for act in act_list: act_tit = form.get(act["tit"]) if act_tit != None: hstr_list = All_history.objects(user = user) des = form["description"] img = form["image"] share = form["share"] for att in att_list : if att in act and att != "id": att_list[att] = att_list[att] + act[att] if att_list[att] < 0: att_list[att] = 0 st = act["st"] cre = act["cre"] soc = act["soc"] knl = act["knl"] per = act["per"] att_list.save() All_history(tit = act["tit"], img=img,user=session["token"], des = des, soc = soc, cre = cre, knl = knl, st = st, per = per, time = str(datetime.now().strftime("%Y%m%d"))).save() if share == "yes": post = Post(tit = act["tit"] ,img = img, user = session["token"], descript = des) post.save() break return render_template("hoat_dong_sx_ttt.html", acts = act_list) else: return redirect(url_for("sign_in"))
def hoat_dong_sx_ttt(sort): if request.method == "GET": act_list = Activities.objects() return render_template("hoat_dong_sx_ttt.html", act=act_list, sort=sort) else: if "token" in session: user = session["token"] form = request.form act_list = Activities.objects() att_list = Attribute.objects(username=user).first() hstr_list = All_history.objects(user=user).first toan_bo = form.get("all") if toan_bo != None: return redirect("/hoat-dong") for att in att_list: sort = form.get(att) if sort != None: return redirect("/hoat-dong-sx-ttt-" + att) for act in act_list: action = form.get(act["tit"]) if action != None: hstr_list.tit.append(act["tit"]) for att in att_list: if att in act and att != "id": att_list[att] = att_list[att] + act[att] if att_list[att] < 0: att_list[att] = 0 att_list.save() hstr_list.save() break return render_template("hoat_dong_sx_ttt.html", act=act_list) else: return redirect(url_for("sign_in"))
def habit(): if "token" in session: user = session["token"] habit_list = Habit.objects(username=user) hstr_list = All_history.objects(user=user) act_list = Activities.objects() acts = [] habits = [] for hstr in hstr_list: if hstr["tit"] not in acts: acts.append(hstr["tit"]) for habit in habit_list: if habit["tit"] not in habit: habits.append(habit["tit"]) for a in acts: act_in_hstr = All_history.objects(user=user, tit=a) combo = 1 if a not in habits: if len(act_in_hstr) >= 3: for i in range(len(act_in_hstr) - 1): if int(act_in_hstr[i + 1].time[6:8]) != int( act_in_hstr[i].time[6:8]) + 1: combo = 0 combo += 1 if i == len(act_in_hstr) - 2: x_data = Activities.objects(tit=a).first() soc = x_data["soc"] per = x_data["per"] st = x_data["st"] knl = x_data["knl"] cre = x_data["cre"] Habit(username=user, tit=a, streak=combo, soc=soc, per=per, knl=knl, st=st, cre=cre).save() else: c_habit = Habit.objects(tit=a).first() if c_habit["streak"] < len(act_in_hstr): if len(act_in_hstr) >= 3: for i in range(len(act_in_hstr) - 1): if int(act_in_hstr[i + 1].time[6:8]) != int( act_in_hstr[i].time[6:8]) + 1: combo = 0 combo += 1 if combo > c_habit["streak"]: c_habit["streak"] = combo c_habit.save() if request.method == "GET": habit_list = Habit.objects(username=user) return render_template("habit.html", habits=habit_list) else: att_list = Attribute.objects(username=user).first() form = request.form for act in act_list: act_tit = form.get(act["tit"]) if act_tit != None: hstr_list = All_history.objects(user=user) des = form["description"] img = form["image"] share = form["share"] for att in att_list: if att in act and att != "id": att_list[att] = att_list[att] + act[att] if att_list[att] < 0: att_list[att] = 0 st = act["st"] cre = act["cre"] soc = act["soc"] knl = act["knl"] per = act["per"] att_list.save() All_history(tit=act["tit"], img=img, user=session["token"], des=des, soc=soc, cre=cre, knl=knl, st=st, per=per, time=str( datetime.now().strftime("%Y%m%d"))).save() if share == "yes": post = Post(tit=act["tit"], img=img, user=session["token"], descript=des) post.save() break return redirect("/ca_nhan") else: return redirect("/sign_in")
mlab.connect() contribute_list = Contribute.objects() for contribute in contribute_list: print("title: ",contribute.tit) if contribute.st != 0: print("strength: ",contribute.st) if contribute.knl != 0: print("knowledge: ",contribute.knl) if contribute.per != 0: print("personality: ",contribute.per) if contribute.cre != 0: print("creative: ",contribute.cre) if contribute.st != 0: print("social: ",contribute.soc) choose = input("add?") if choose == "y": Activities(tit=contribute.tit,st=contribute.st,knl=contribute.knl,cre=contribute.cre,per=contribute.per,soc=contribute.soc).save() plus_user = Attribute.objects(username=contribute.user).first() plus_user.cre += 2 plus_user.save() print("saved") contribute.delete()