예제 #1
0
def consulting():
    if not g.user:
        if not session.get('uuid'):
            session['uuid'] = str(uuid.uuid4())
        if not session.get('ins_plan_consulting_log'):
            rsyslog.send(session['uuid'] + '\t' + request.remote_addr,
                         tag='ins_plan_consulting')
            session['ins_plan_consulting_log'] = 'logged'
        session_dict = {}
        if session.get('ins_plan'):
            session_dict = json.loads(session.get('ins_plan'))
        session_dict['is_login'] = False
        return render_template('ins/plan_consulting.html',
                               plan=json.dumps(session_dict))
    else:
        user_id = g.user.id
        plan_id = request.args.get('plan_id')
        if not plan_id and not Plan.get_user_plan_dict(user_id):
            return render_template('ins/plan_consulting.html',
                                   plan=session.get('ins_plan', '{}'))
        if plan_id and Plan.belong_to_user(plan_id, g.user.id):
            plan_dict = Plan.get(plan_id).data.data
            plan_json_str = session.get('login_ins_plan' + str(plan_id))
            if plan_json_str:
                session_plan = json.loads(plan_json_str)
                plan_dict.update(session_plan)
            plan_dict['is_login'] = True
            plan_json = json.dumps(plan_dict)
            session['plan_id'] = plan_id
            return render_template('ins/plan_consulting.html', plan=plan_json)
        return redirect(url_for('ins.plan.index'))
예제 #2
0
def delete_plan():
    if not g.user:
        return jsonify(is_login=False, error='not login'), 400
    plan = Plan.get(request.form.get('id'))
    if plan and Plan.belong_to_user(plan.id, g.user.id):
        plan.remove()
        session.pop('login_ins_plan' + str(plan.id), None)
        return jsonify(is_login=True), 200
    else:
        abort(401)
예제 #3
0
    def test_get_plan(self):
        a = self.add_account()
        plan = Plan.add(a.id)
        self.assertTrue(plan)
        self.assertEqual(plan.user_id, a.id)

        pid = plan.id
        plan = Plan.get(pid)

        self.assertTrue(plan)
        self.assertEqual(plan.id, pid)
예제 #4
0
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)