def planning(plan_id): if g.user: if Plan.belong_to_user(plan_id, g.user.id): return render_template('ins/plan_planning.html', **Plan.get_user_plan_by_id(plan_id)) else: return redirect(url_for('ins.plan.index'))
def update_login_plan(user_id, request_dict, plan_id, stage): if Plan.belong_to_user(plan_id, user_id): plan = Plan.get(plan_id) session_plan_key = 'login_ins_plan' + str(plan_id) if not session.get(session_plan_key): session[session_plan_key] = json.dumps(request_dict) plan.data.update(**request_dict) return_dict = {} else: origin_plan = Plan.get_user_plan_by_id(plan_id) updated_plan, return_dict = update_plan_with_stage( request_dict, stage, origin_plan) origin_plan.update(updated_plan) session[session_plan_key] = json.dumps(origin_plan) plan.data.update(**updated_plan) if stage == 6: plan.data.update(is_completed=True) plan.data.update( href=url_for('ins.plan.planning', plan_id=plan.id)) session.pop(session_plan_key, None) session.pop('plan_id', None) return jsonify(**return_dict), 200 return abort(401)