def show_todo_list(page=None): if not page: page = 1 form = TodoListForm() if request.method == 'GET' and current_user.id == 1: # todolists = TodoList.query.all() todolists = TodoList.query.filter_by(user_id=1).order_by( TodoList.create_time.desc()).paginate(page=page, per_page=5) return render_template('index.html', todolists=todolists.items, pagination=todolists, form=form) elif current_user.id != 1: tdl = TodoList.query.filter_by(user_id=current_user.id).order_by( TodoList.create_time.desc()).paginate(page=page, per_page=5) return render_template('index.html', todolists=tdl.items, pagination=tdl, form=form) else: if form.validate_on_submit(): todolist = TodoList(current_user.id, form.title.data, form.content.data, form.status.data, current_user.username) db.session.add(todolist) db.session.commit() flash('新内容添加成功!') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def add(): #form=request.form #直接使用前端request传来的数据实例化form #form=TodoListForm(request.form) form = TodoListForm() #form.content=request.form['content'] if form.validate_on_submit(): form.content = request.form['content'] todolist = TodoList() todolist.content = form.content db.session.add(todolist) db.session.commit() # todolists=TodoList.query.order_by(TodoList.create_time.desc()) # todolists=todolists.all() # return render_template('index.html', todolists=todolists, form=form) #翻页的时候会报错 # page_index = request.args.get('page', 1, type=int) # query = TodoList.query.order_by(TodoList.create_time.desc()) # pagination = query.paginate(page_index, per_page=10, error_out=False) # todolists = pagination.items # return render_template('index.html',todolists=todolists,form=form, # pagination=pagination) return redirect(url_for('index'))
def show_todo_list(): form = TodoListForm() if request.method == 'GET': todolists = TodoList.query.all() if current_user: flag = 1 else: flag = 0 print(flag) return render_template('index.html', todolists=todolists, flag=flag, form=form) else: if form.validate_on_submit(): print(form.title.data + '-----' + form.status.data + "----" + form.time.data) todolist = TodoList(current_user.id, form.title.data, form.status.data, form.time.data) # print(todolist) db.session.add(todolist) db.session.commit() flash('You have add a new todo list') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def change_todo_list(id): form = TodoListForm() if request.method == 'GET': sql = 'select id, user_id, title, status, create_time from todolist where id={0}'.format( id) with g.db as cur: cur.execute(sql) for row in cur.fetchall(): todo_list = dict(id=row[0], user_id=row[1], title=row[2], status=bool(row[3]), create_time=row[4]) form = TodoListForm() form.title.data = todo_list['title'] if todo_list['status']: form.status.data = '1' else: form.status.data = '0' # print(form.status.data) return render_template('modify.html', form=form) else: form = TodoListForm() if form.validate_on_submit(): with g.db as cur: sql = """update todolist set title='{0}', status='{1}' where id='{2}' """.format(form.title.data, form.status.data, id) # print(sql) cur.execute(sql) flash('You have modify a todolist') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def show_todo_list(): if not session.get('logged_in'): return redirect(url_for('login')) form = TodoListForm() if request.method == 'GET': sql = 'select id, user_id, title, status, create_time from todolist' with g.db as cur: cur.execute(sql) todo_list = [ dict(id=row[0], user_id=row[1], title=row[2], status=bool(row[3]), create_time=row[4]) for row in cur.fetchall() ] return render_template('index.html', todo_list=todo_list, form=form) else: if form.validate_on_submit(): title = form.title.data status = form.status.data with g.db as cur: sql = """insert into todolist(`user_id`, `title`, `status`, `create_time`) values ({0}, '{1}', {2}, {3})""".format( 1, title, status, int(time.time())) cur.execute(sql) flash('You have add a new todo list') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def show_todo_list(): form = TodoListForm() if request.method == 'GET': todolists = TodoList.query.all() return render_template('index.html', todolists=todolists, form=form) else: if form.validate_on_submit(): todolist = TodoList(current_user.id, form.title.data, form.status.data) db.session.add(todolist) db.session.commit() flash('You have add a new todo list') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def show_todo_list(): todoListform = TodoListForm() if request.method == 'GET': todolists = TodoList.query.all() return render_template("index_follow.html", todo_list=todolists, form=todoListform, title=u"首页") elif request.method == 'POST': if todoListform.validate_on_submit(): todolist = TodoList(user_id=current_user.id, title=todoListform.title.data, status=todoListform.status.data) db.session.add(todolist) db.session.commit() flash('记录新增成功!') else: flash(todoListform.errors) return redirect(url_for('main.show_todo_list'))
def add_todo_list(): form = TodoListForm() if request.method == 'POST': date = form.wrk_date.data.strftime('%Y-%m-%d') print(date) if form.validate_on_submit(): todolist = TodoList(current_user.id, date, form.title.data, form.content.data, form.status.data, current_user.username) db.session.add(todolist) db.session.commit() flash(current_user.username + '添加了一条新的工作内容') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def show_todo_list(): form = TodoListForm() if request.method == 'GET': todolists = TodoList.query.all() return render_template('index.html', todolists=todolists, form=form) else: if form.validate_on_submit(): todolist = TodoList(current_user.id, form.title.data, form.status.data) db.session.add(todolist) db.session.commit() flash('Сіз жаңа todo тізімін қосдыңыз') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def index(): form = TodoListForm() if request.method == 'GET': todolists = TodoList.query.filter_by(name=session['username']).all() return render_template('index.html', todolists=todolists, form=form) else: if form.validate_on_submit(): todolist = TodoList(str(uuid1()), session['username'], form.title.data, form.status.data) db.session.add(todolist) db.session.commit() flash('You have add a new todo list') else: flash('validate string!') return redirect(url_for('test.index'))
def change_todo_list(id): if request.method == 'GET': todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoListForm() form.title.data = todolist.title form.status.data = str(todolist.status) return render_template('modify.html', form=form) else: form = TodoListForm() if form.validate_on_submit(): todolist = TodoList.query.filter_by(id=id).first_or_404() todolist.title = form.title.data todolist.status = form.status.data db.session.commit() flash('You have modify a todolist') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def change_todo_list(id): if request.method == 'GET': todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoListForm() form.title.data = todolist.title form.status.data = str(todolist.status) return render_template('modify.html', form=form) else: form = TodoListForm() if form.validate_on_submit(): todolist = TodoList.query.filter_by(id=id).first_or_404() todolist.title = form.title.data todolist.status = form.status.data db.session.commit() flash('You have modify a todolist') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def modify(id): if request.method == 'GET': todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoListForm() form.title.data = todolist.title form.status.data = todolist.status return render_template("modify_follow.html", form=form) elif request.method == 'POST': todoListForm = TodoListForm() if todoListForm.validate_on_submit(): todolist = TodoList.query.filter_by(id=id).first_or_404() todolist.title = todoListForm.title.data todolist.status = todoListForm.status.data db.session.add(todolist) db.session.commit() flash('任务修改成功!') else: flash(todoListForm.errors) return redirect(url_for("main.show_todo_list"))
def change_todo_list(id): if request.method == 'GET': todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoListForm() form.wrk_date.data = todolist.wrk_date form.title.data = todolist.title form.content.data = todolist.content form.status.data = str(todolist.status) return render_template('modify.html', form=form) else: form = TodoListForm() if form.validate_on_submit(): todolist = TodoList.query.filter_by(id=id).first_or_404() todolist.wrk_date = form.wrk_date.data.strftime('%Y-%m-%d') todolist.title = form.title.data todolist.status = form.status.data todolist.content = form.content.data todolist.upd_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) db.session.commit() flash(current_user.username + '修改了第' + str(id) + '条记录') else: flash(form.errors) return redirect(url_for('show_todo_list'))
def add_todo_list(): form = TodoListForm() if request.method == 'GET': todolists = TodoList.query.filter_by(user_id=current_user.id).filter( TodoList.status >= 1).all() if len(todolists) < 1: flash("没有家务日志,请添加") return render_template('newadd.html', todolists=todolists, form=form) else: if form.validate_on_submit(): if form.bz.data == '1': todolist = TodoList(current_user.id, form.title.data + " (额外)", form.status.data, form.score.data, form.bz.data) else: todolist = TodoList(current_user.id, form.title.data, form.status.data, form.score.data, form.bz.data) db.session.add(todolist) db.session.commit() flash('新增了一个家务') else: flash(form.errors) return redirect(url_for('add_todo_list'))
def show_todo_list(): if not session.get('logged_in'): return redirect(url_for('login')) form = TodoListForm() if request.method == 'GET': if (session["type"] == "student"): publishes = [] with g.db as cur: sql3 = "select title,class_name from publishes" cur.execute(sql3) publishes = [ dict(title=row[0], class_name=row[1]) for row in cur.fetchall() ] for publish in publishes: with g.db as cur: sql4 = "select distinct user_id,class_name from class_table where user_id='{0}'".format( session["id"]) cur.execute(sql4) students = [ dict(user_id=row[0], class_name=row[1]) for row in cur.fetchall() ] for student in students: if student["class_name"] == publish["class_name"]: flash(publish["class_name"] + "的课程通知:" + publish["title"]) sql = 'select id,class_order, class_weekday, class_name, class_teacher, class_place ,class_weekbeg,class_weekend,class_weekparity ' \ 'from class_table where user_id="{0}"'.format(session["id"]) with g.db as cur: cur.execute(sql) classtable = [ dict(id=int(row[0]), class_order=int(row[1]), class_weekday=int(row[2]), class_name=row[3], class_teacher=row[4], class_place=row[5], class_weekbeg=int(row[6]), class_weekend=int(row[7]), class_weekparity=int(row[8])) for row in cur.fetchall() ] ctable = [[""] * 7 for i in range(4)] for i in range(3): for j in range(7): ctable[i].append("") if request.args.get("whichweek"): whichweek = int(request.args.get("whichweek")) else: whichweek = current_week() for c in classtable: if c["class_weekparity"] == 2: if c["class_weekbeg"] <= whichweek and c[ "class_weekend"] >= whichweek: ctable[c["class_order"] - 1][c["class_weekday"] - 1] = c["class_name"] + "|" + c[ "class_teacher"] + "|" + c["class_place"] if c["class_weekparity"] == 1 and whichweek % 2 == 0: if c["class_weekbeg"] <= whichweek and c[ "class_weekend"] >= whichweek: ctable[c["class_order"] - 1][c["class_weekday"] - 1] = c["class_name"] + "|" + c[ "class_teacher"] + "|" + c["class_place"] if c["class_weekparity"] == 0 and whichweek % 2 == 1: if c["class_weekbeg"] <= whichweek and c[ "class_weekend"] >= whichweek: ctable[c["class_order"] - 1][c["class_weekday"] - 1] = c["class_name"] + "|" + c[ "class_teacher"] + "|" + c["class_place"] sql2 = 'select id, user_id, title, status, create_time from todolist where user_id="{0}"'.format( session["id"]) with g.db as cur: cur.execute(sql2) todo_list = [ dict(id=row[0], user_id=row[1], title=row[2], status=bool(row[3]), create_time=time.asctime(time.localtime(int(row[4])))) for row in cur.fetchall() ] return render_template('index.html', ctable=ctable, form=form, todo_list=todo_list, whichweek=whichweek, current_week=current_week()) else: if form.validate_on_submit(): title = form.title.data status = form.status.data with g.db as cur: sql = """insert into todolist(user_id, title, status, create_time) values ('{0}', '{1}', {2}, {3})""".format( session["id"], title, status, int(time.time())) cur.execute(sql) flash('You have add a new todo list') else: flash(form.errors) return redirect(url_for('show_todo_list'))