Пример #1
0
def new():
    pcfg = {"title": "New note"}

    form = NoteForm()

    if form.validate_on_submit():
        a = Note()
        a.title = form.title.data
        a.cat = form.cat.data
        a.note = form.note.data
        a.user_id = current_user.id

        db.session.add(a)
        db.session.commit()

        flash("Success updating note: {0}".format(a.title), "success")
        return redirect(url_for("bp_notes.notes"))

    logbooks = (db.session.query(Logbook.id, Logbook.name, func.count(
        Log.id)).join(Log).filter(Logbook.user_id == current_user.id).group_by(
            Logbook.id).all())
    return render_template("notes/new.jinja2",
                           pcfg=pcfg,
                           form=form,
                           logbooks=logbooks)
Пример #2
0
def finish_plan_api():
    pk = flask.request.form.get('pk')
    user_id = flask.session['user_id']
    plan = Plan.fetchone(pk=pk)
    if not plan:
        raise error.PlanNoteFound()

    plan_log = PlanLog()
    plan_log.user_id = user_id
    plan_log.plan_id = plan.pk
    plan_log.create_at = datetime.now()
    plan_log.update_at = datetime.now()
    plan_log.is_enable = 1
    plan_log.save(commit=False)

    for item in plan.plan_items:
        note = Note()
        note.kind_id = item.kind.pk
        note.user_id = user_id
        note.quantity = item.quantity
        note.plan_log_id = plan_log.pk
        note.create_at = datetime.now()
        note.update_at = datetime.now()
        note.save()

    return {'pk': pk}
Пример #3
0
def create_note_api():
    kind_id = flask.request.form.get('kind_id')
    quantity = flask.request.form.get('quantity')
    content = flask.request.form.get('content')
    user_id = int(flask.session['user_id'])

    # Check kind owner
    note_kind = NoteKind.fetchone(pk=kind_id, user_id=user_id)
    if not note_kind:
        raise error.KindNotExistError()

    note = Note()
    note.kind_id = kind_id
    note.user_id = user_id
    note.content = content
    note.quantity = quantity
    note.save()
    return {'pk': note.pk}