def post(self, tag): group = Group.objects(tag=tag)[0] title = self.get_argument('title') content = self.get_argument('content') now = datetime.datetime.now() mode = self.get_argument('type').decode() if mode == 'new': try: if not title: raise Exception('title is none') post = Post(group=group, author=self.get_curent_user_model(), title=title, content=content, create_at=now, update_at=now ) post.save() return self.redirect("/group/" + tag + "/" + str(post.id)) except Exception as ex: app_log.error(ex) return self.redirect("/group/" + tag) elif mode == 'update': id = self.get_argument('id') try: app_log.debug(id) app_log.debug(title) app_log.debug(content) post = Post.objects(id=id)[0] post.title = title post.content = content post.save() except Exception as ex: app_log.error(ex) return self.redirect("/group/" + tag + "/" + id)
def post(self, tag): group = Group.objects(tag=tag)[0] title = self.get_argument('title') content = self.get_argument('content') now = datetime.datetime.now() mode = self.get_argument('type').decode() if mode == 'new': try: if not title: raise Exception('title is none') post = Post(group=group, author=self.get_curent_user_model(), title=title, content=content, create_at=now, update_at=now) post.save() return self.redirect("/group/" + tag + "/" + str(post.id)) except Exception as ex: app_log.error(ex) return self.redirect("/group/" + tag) elif mode == 'update': id = self.get_argument('id') try: app_log.debug(id) app_log.debug(title) app_log.debug(content) post = Post.objects(id=id)[0] post.title = title post.content = content post.save() except Exception as ex: app_log.error(ex) return self.redirect("/group/" + tag + "/" + id)
def save_share(): if request.method == "GET": return render_template("save_share.html") else: form = request.form des = form["description"] img = form["image"] share = form["share"] if share == "yes": post = Post(img=img, user=session["token"], descript=des) post.save() All_history(img=img, user=session["token"], des=des).save() return redirect(url_for("home"))
def save_share(): if request.method == "GET": user = User.objects(username=session["token"]).first() return render_template("save_share.html",name = session["token"],avt=user.avt) else: form = request.form des = form["description"] img = form["image"] share = form["share"] if share == "yes": post = Post(img=img,user=session["token"],descript=des) post.save() All_history(img=img,user=session["token"],des=des).save() return redirect(url_for("ca_nhan"))
def new_post(self, title, content, date=datetime.datetime.utcnow()): """new_post(str, str, str) -> return(None) title : The title of the new post content: The content regarding the new post date : The date the post was created Return : None New post method enables the user to create a new blog post. """ new_post = Post(blog_id = self._id, title = title, content = content, author = self._author, created_date = date) new_post.save() # save post
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 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")