def index(page = 1): form = RecordForm(request.form) friends = sorted([(c.id, c.nickname) for c in g.user.valid_friends()], key=lambda friend: friend[0]) valid =[] for f in friends: if not int(f[0]) == int(g.user.id): valid.append(f) form.lender.choices = valid time = datetime.utcnow() if form.validate_on_submit(): borrower = g.user lender = User().from_id(form.lender.data) if dq.new_record(borrower, lender, amount) is True: flash('Your record is now live!') return redirect(url_for('index')) else: flash('Your record is not successful') return redirect(url_for('index')) #borrow records and lend records borrow_records = g.user.borrow_records()#.paginate(page, RECORDS_PER_PAGE, False) lend_records = g.user.lend_records()#.paginate(page, RECORDS_PER_PAGE, False) return render_template("index.html", title = 'Home', form = form, borrow_records = borrow_records, lend_records = lend_records,)
def add_record(): add_department = True form = RecordForm() if form.validate_on_submit(): record = Record(name=form.name.data, day=form.day.data, production=form.production.data, opening=form.opening.data, closing=form.closing.data) try: # add department to the database db.session.add(record) db.session.commit() flash('You have successfully added a new department.') except: # in case department name already exists flash('Error: department name already exists.') # redirect to departments page return redirect(url_for('admin.list_departments')) # load department template return render_template('home/record.html', action="Add", add_record=add_record, form=form, title="Add Record")
def edit(id): form = RecordForm() if form.validate_on_submit(): for item in RECORDS: if str(item.id) == id: item.value = request.form['value'] item.timestamp = datetime.now() break return redirect(url_for('home')) return render_template('edit.html', id=id, form=form)
def add(): form = RecordForm() if form.validate_on_submit(): record = Record() record.id = uuid.uuid4() record.value = request.form['value'] record.timestamp = datetime.now() RECORDS.append(record) return redirect(url_for('home')) return render_template('add.html', form=form)
def write(): form = RecordForm() content = request.form.get('record') print(content) print(form.validate_on_submit()) # if request.method == 'POST': if form.validate_on_submit(): print("1111\n") content = request.form.get('record') time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') user = current_user.user_email print(content, time, user) record = Record(user) record.create_new_record(time, content) return redirect(request.args.get('next') or url_for('index')) # time = time.strftime('%Y.%m.%d', time.localtime(time.time())) return render_template('write.html', title="write diary", form=form, user_info_global=user_info_global)