Example #1
0
def init_note_db():
    note1 = Note(title="test-刘慈欣访谈")

    cat1 = NoteCategory(name="人物访谈类")
    cat2 = NoteCategory(name="心得体会类")
    cat3 = NoteCategory(name="生活类")

    note1.category = cat1

    db.session.add_all([note1])
    db.session.add_all([cat1, cat2, cat3])
    db.session.commit()
Example #2
0
def create_note(cat_id):
    if request.method == 'GET':
        cat_all = classify_by_rank(NoteCategory.query.filter().order_by(
            NoteCategory.cat_rank).all())
        note_cat = NoteCategory.query.filter(
            NoteCategory.id == int(cat_id)).first()

        dicts = {'cat_all': cat_all, 'note_cat': note_cat, 'catid': cat_id}
        return render_template('notes/create_note.html', **dicts)
    else:
        title = request.form.get('docTitle')
        if title:
            new_note = Note(title=title)
            username = session.get('username')
            # 指定用户
            if username:
                user = User.query.filter(User.username == username).first()
            else:
                user = User.query.filter().first()
            new_note.user = user
            # 设定类别
            note_cat = NoteCategory.query.filter(
                NoteCategory.id == int(cat_id)).first()
            new_note.category = note_cat

            # 记录内容
            content = request.form.get('docContent')
            path = FILESERVER + PATHSEP + 'notes' + PATHSEP + cat_id + secure_filename(
                ''.join(lazy_pinyin(note_cat.name))) + PATHSEP
            full_filename = path + secure_filename(''.join(
                lazy_pinyin(title))) + '.md'
            if not os.path.exists(path):
                os.makedirs(path)
            sec_writefile(full_filename, content)
            new_note.content_path = full_filename
            # 更新数据库
            db.session.add(new_note)
            db.session.commit()

        return redirect(url_for('main.notes_cat', note_catid=int(cat_id)))
Example #3
0
 def delete(note_id):
     del_msg = Note.delete(note_id)
     return jsonify(del_msg)
Example #4
0
 def patch(note_id):
     note = Note.update(note_id)
     return jsonify(note)
Example #5
0
 def get(note_id):
     note = Note.find_one(note_id)
     return jsonify(note)
Example #6
0
 def post(current_user_id, task_id):
     data = request.get_json()
     note = Note.add(current_user_id, task_id, data)
     return jsonify(note)
Example #7
0
 def get(task_id):
     notes = Note.find_all(task_id)
     return jsonify(Notes=notes)