示例#1
0
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'))
示例#2
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'))
示例#3
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)
示例#4
0
def add_login_plan(user_id, request_dict):
    plan = Plan.add(user_id)
    plan.data.update(href=url_for('ins.plan.consulting', plan_id=plan.id),
                     is_completed=False)
    plan.update_plan(request_dict, url_for('ins.plan.planning',
                                           plan_id=plan.id))
    session['plan_id'] = plan.id
    if len(Plan.get_user_plan_dict(g.user.id)) == 1 and \
            plan.data.owner.decode('utf-8') == u'配偶':
        add_myself(g.user.id, plan.data.gender.decode('utf-8'))
    return plan
示例#5
0
    def test_get_plan_by_user(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_by_user_id(a.id)[0]

        self.assertTrue(plan)
        self.assertEqual(plan.id, pid)
示例#6
0
def update_session_to_plan(user_id, session_str):
    if Plan.get_user_plan_dict(user_id):
        session.pop('ins_plan', None)
        # session.pop('uuid', None)
        return
    session_dict = json.loads(session_str)
    plan = Plan.add(user_id)
    plan.data.update(is_completed=False,
                     href=url_for('ins.plan.consulting', plan_id=plan.id))
    plan.update_plan(session_dict, url_for('ins.plan.planning',
                                           plan_id=plan.id))
    session.pop('ins_plan', None)
    # session.pop('uuid', None)
    if session_dict.get('owner') and session_dict.get('owner') == u'配偶':
        add_myself(user_id, session_dict.get('gender'))
示例#7
0
def products_zhongmin():
    redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
        'source=21013&url=http://www.zhongmin.cn/accid/Product/accident662.html'

    redirect_url_1 = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
        'source=21013&url=http://www.zhongmin.cn/Travel/Product/travel12-18d1.html'

    redirect_url_2 = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
        'source=21013&url=http://www.zhongmin.cn/Travel/Product/travel9-18d1.html'

    if request.user_agent.is_mobile:
        redirect_url = 'http://wap.zhongmin.cn/AutoRedirect_1.aspx?' \
                       'url=http://m.zhongmin.cn/WAP/GoodsDetail.aspx?bId=4&pId=662&source=21013'

        redirect_url_1 = 'http://wap.zhongmin.cn/AutoRedirect_1.aspx?' \
            'url=http://m.zhongmin.cn/WAP/GoodsDetail.aspx?bId=11&pId=12&source=21013'

        redirect_url_2 = 'http://wap.zhongmin.cn/AutoRedirect_1.aspx?' \
            'url=http://m.zhongmin.cn/WAP/GoodsDetail.aspx?bId=11&pId=9&source=21013'

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
            'source=25997&url=http://www.zhongmin.cn/accid/Product/accident662.html'

    return render_template('/childins/A001.html', zhongmin_url=redirect_url,
                           redirect_url_1=redirect_url_1, redirect_url_2=redirect_url_2)
示例#8
0
def products_a002():
    redirect_url = 'https://ssl.700du.cn/prod/slsywzx.html?inviter=0000025993'

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'https://ssl.700du.cn/prod/slsywzx.html?inviter=0000028825'

    return render_template('/childins/A002.html', redirect_url=redirect_url)
示例#9
0
def products_ci001():
    redirect_url = 'https://ssl.700du.cn/prod/xhijk.html?inviter=0000025993'

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'https://ssl.700du.cn/prod/xhijk.html?inviter=0000028825'

    return render_template('/childins/CI001.html', redirect_url=redirect_url)
示例#10
0
def add_mate_plan(user_id, owner):
    plan_dict = Plan.get_user_plan_dict(user_id)
    plan = Plan.add(g.user.id)
    plan.data.update(
        is_completed=False,
        href=url_for('ins.plan.consulting', plan_id=plan.id),
        id=plan.id,
        marriage=u'已婚',
        gender=u'男性' if plan_dict[0]['gender'] == u'女性' else u'女性',
        owner=owner,
    )
    return jsonify(is_login=True,
                   id=plan.id,
                   href=plan.data.href,
                   is_completed=plan.data.is_completed,
                   gender=plan.data.gender), 200
示例#11
0
def products_t001():
    redirect_url = ('http://www.zhongmin.cn/AutoRedirect_1.aspx?'
                    'source=21013&url=http://www.zhongmin.cn''/Travel/Product/travel11-18d1.html')

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
            'source=25997&url=http://www.zhongmin.cn/Travel/Product/travel11-18d1.html'

    return render_template('/childins/T001.html', redirect_url=redirect_url)
示例#12
0
def add_myself(user_id, mate_gender):
    p = Plan.add(user_id)
    my_gender = u'男性' if mate_gender == u'女性' else u'女性'
    p.data.update(owner=u'自己',
                  marrige=u'已婚',
                  gender=my_gender,
                  href=url_for('ins.plan.consulting', plan_id=p.id),
                  is_completed=False,
                  accident_coverage='',
                  id=p.id)
示例#13
0
def products_l002():
    redirect_url = ('http://www.zhongmin.cn/AutoRedirect_1.aspx?source=21013&url='
                    'http://www.zhongmin.cn/Regular/Product/RegularDetail13.html')

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
            'source=25997&url=http://www.zhongmin.cn/Regular/Product/RegularDetail13.html'

    return render_template('/childins/L002.html',
                           redirect_url=redirect_url)
示例#14
0
def add_plan():
    request_dict = request.form.to_dict()
    stage = None
    if request_dict.get('stage', None):
        stage = int(request_dict.get('stage', None))
    request_dict.pop('stage', None)

    if not g.user:
        if not session.get('uuid'):
            session['uuid'] = str(uuid.uuid4())
        if not session.get('ins_plan'):
            session['ins_plan'] = json.dumps(request_dict)
            return_dict = {}
        else:
            origin_plan = json.loads(session.get('ins_plan'))
            updated_plan, return_dict = update_plan_with_stage(
                request_dict, stage, origin_plan)
            origin_plan.update(updated_plan)
            session['ins_plan'] = json.dumps(origin_plan)
        rsyslog.send(session['uuid'] + '\t' + format_plan(session['ins_plan']),
                     tag='ins_plan')
        return jsonify(**return_dict), 200

    else:
        user_id = g.user.id
        plan_id = session.get('plan_id')
        if len(Plan.get_user_plan_dict(user_id)) > 2:
            abort(401)
        if request_dict.keys() == ['owner']:
            if len(Plan.get_user_plan_dict(user_id)) == 1:
                return add_mate_plan(user_id, request_dict.get('owner'))
            else:
                abort(401)
        if plan_id:
            return update_login_plan(user_id, request_dict, plan_id, stage)
        else:
            if not Plan.get_user_plan_dict(user_id):
                plan = add_login_plan(user_id, request_dict)
                session['plan_id'] = plan.id
                return jsonify(islogin=True), 200
            else:
                abort(401)
示例#15
0
def products_ci003():
    redirect_url = ('http://www.zhongmin.cn/AutoRedirect_1.aspx?'
                    'source=21013&url=http://www.zhongmin.cn/Health/product/AccidProduct.aspx?'
                    'id=75&age=0&sex=1&span=20&money=50000')

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?source=25997&' \
            'url=http://www.zhongmin.cn/Health/product/AccidProduct.aspx?' \
            'id=75&age=0&sex=1&span=20&money=50000'

    return render_template('/childins/CI003.html', redirect_url=redirect_url)
示例#16
0
def products_a003():
    redirect_url = (
        'http://www.zhongmin.cn/AutoRedirect_1.aspx?'
        'source=21013&url=http://www.zhongmin.cn/Health/Product/'
        'HospitalProductT574-0-50-0.html')

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?source=25997' \
            '&url=http://www.zhongmin.cn/Health/Product/HospitalProductT574-0-50-0.html'

    return render_template('/childins/A003.html', redirect_url=redirect_url)
示例#17
0
def products_ca003():
    redirect_url = ('http://www.zhongmin.cn/AutoRedirect_1.aspx'
                    '?source=21013&url=http://www.zhongmin.cn/Health/Product/'
                    'HospitalProductT354-0-3-0.html')
    redirect_url_1 = 'http://cps.hzins.com/yk30459/product/detail-1198.html'

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?source=25997&' \
            'url=http://www.zhongmin.cn/Health/Product/HospitalProductT354-0-3-0.html'

    return render_template('/childins/CA003.html', redirect_url=redirect_url,
                           redirect_url_1=redirect_url_1)
示例#18
0
def products_ca001():
    redirect_url = ('http://www.zhongmin.cn/AutoRedirect_1.aspx'
                    '?source=21013&url=http://www.zhongmin.cn/'
                    'accid/Product/accident626.html')
    redirect_url_1 = 'http://cps.hzins.com/yk30459/product/detail-1198.html'

    if g.user and Plan.get_user_plan_dict(g.user.id):
        redirect_url = 'http://www.zhongmin.cn/AutoRedirect_1.aspx?' \
            'source=25997&url=http://www.zhongmin.cn/accid/Product/accident626.html'

    return render_template('/childins/CA001.html', redirect_url=redirect_url,
                           redirect_url_1=redirect_url_1)
示例#19
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)
示例#20
0
def index():
    if not g.user:
        if not session.get('uuid'):
            session['uuid'] = str(uuid.uuid4())
        if not session.get('ins_plan_index_log'):
            rsyslog.send(session['uuid'] + '\t' + request.remote_addr,
                         tag='ins_plan_index')
            session['ins_plan_index_log'] = 'logged'
        return render_template('ins/plan.html')
    else:
        user_id = g.user.id
        if session.get('ins_plan'):
            register_log = format_plan(session['ins_plan'],
                                       is_regiester='yes',
                                       user_id=user_id)
            register_log = session['uuid'] + '\t' + register_log
            rsyslog.send(register_log, tag='ins_plan')
            update_session_to_plan(user_id, session.get('ins_plan'))
        if Plan.get_user_plan_dict(user_id):
            planners_dict = Plan.get_user_plan_dict(user_id)
            return render_template('ins/plan_management.html',
                                   planners=planners_dict)
        return render_template('ins/plan.html')
示例#21
0
 def test_plan_secret_data_with_big_data(self):
     a = self.add_account()
     plan = Plan.add(a.id)
     plan.data.update(key='value',
                      haha='this is a very long text',
                      content='100' * 1000,
                      int_data=100,
                      some_key='some_key',
                      some_chinese_key='你好',
                      some_photo='asd' * 1024)
     plan.data.update(some_dict=dict(key='value'),
                      some_list=[1, 2])
     self.assertFalse(plan.data.invalid)
     self.assertEqual(plan.data.key, 'value')
     self.assertEqual(plan.data.some_chinese_key, '你好')
     self.assertEqual(plan.data.some_photo, 'asd' * 1024)
     self.assertEqual(plan.data.some_dict.get('key'), 'value')
     self.assertTrue(1 in plan.data.some_list)
     self.assertTrue(2 in plan.data.some_list)
示例#22
0
 def test_add_plan(self):
     a = self.add_account()
     plan = Plan.add(a.id)
     self.assertTrue(plan)
     self.assertEqual(plan.user_id, a.id)