Esempio n. 1
0
def create_journal():
    form = JournalForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        new_journal = Journal(name=form.data['name'],
                              color=form.data['color'],
                              user=current_user)
        db.session.add(new_journal)
        db.session.commit()
        return new_journal.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
Esempio n. 2
0
def create_journal():
    form = JournalForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    print('----------')
    if form.validate_on_submit():
        data = Journal()
        print(data, '----------')
        form.populate_obj(data)
        data.userId = current_user.id
        db.session.add(data)
        db.session.commit()
        return data.to_dict()
    return 'invalid info'