示例#1
0
文件: app.py 项目: jie/sportsapp
def create_plan_item_api():
    plan_id = flask.request.form.get('plan_id')
    kind_id = flask.request.form.get('kind_id')
    quantity = flask.request.form.get('quantity')
    user_id = flask.session['user_id']
    plan = Plan.fetchone(pk=plan_id)

    if not plan:
        raise error.PlanNoteFound()

    item = PlanItem()
    item.kind_id = kind_id
    item.user_id = user_id
    item.plan_id = plan_id
    item.quantity = quantity
    item.create_at = datetime.now()
    item.update_at = datetime.now()
    item.is_enable = 1
    item.save()
    return {'pk': item.pk}
示例#2
0
文件: app.py 项目: jie/sportsapp
def remove_plan_item_api():
    pk = flask.request.form.get('pk')
    user_id = flask.session['user_id']

    plan = Plan.fetchone(pk=pk, user_id=user_id)
    if not plan:
        raise error.PlanNoteFound()

    item = PlanItem.fetchone(pk=pk)
    if not item:
        raise error.PlanItemNoteFound()

    item.is_enable = 0
    item.save()
    return {'pk': item.pk}