Exemplo n.º 1
0
def insert_data():
    print 'request',request
    if request.method == 'POST':
        c_ids = request.get_json().get('c_ids')  #数组
        name = request.get_json().get('name')
        phone = request.get_json().get('telphone')
        departure = request.get_json().get('departure')
        a_id = request.get_json().get('a_id')
        # time = request.get_json().get('time')
        insert_time = curtime()
        passenger = request.get_json().get('passenger')
        print 'c_ids',c_ids
        # r = True
        r = check(phone,a_id)
        print 'r', r
        if r:
            return jsonify({'code': '0', 'msg': '该号码 '+phone+' 已经参加此次活动!'})
        #以下未完成,
        #更新person_info表(有则按phone更新,无则插入)
        text = "insert into person_info (name,phone,start_position) values ('%s','%s','%s') on conflict(phone) do update set name=EXCLUDED.name , start_position=EXCLUDED.start_position"  % (name,phone,departure)
        db_session.execute(text)
        db_session.commit()
        #插入join_content表
        has_car = ''
        if passenger != '无':
            has_car = 'yes'
        else:
            has_car = 'no'
        for c_id in c_ids:
            text = "insert into join_act_cont (phone,c_id,drive_people,drive_car,insert_time) " \
                   "values ('%s','%s','%s','%s','%s')" % (phone,c_id,passenger,has_car,insert_time)
            db_session.execute(text)
            db_session.commit()
        return jsonify({'code':'1', 'msg':'报名成功!'})
Exemplo n.º 2
0
 def patch(self):
     args = highscorePostParser.parse_args()
     score = args.score
     jwt_encoded = args['Authorization'][7:]
     jwt_payload = jwt.decode(jwt_encoded, JWT_SECRET, algorithms=['HS256'])
     user_highscore = db_session.query(Highscore).filter_by(
         user_id=jwt_payload['user_id']).first()
     if (user_highscore is not None):
         if (user_highscore.score < score):
             user_highscore.score = score
             db_session.commit()
             return {
                 'status': 200,
                 'updated': True,
                 'message': 'Highscore updated.'
             }, 200
         else:
             return {
                 'status': 200,
                 'updated': False,
                 'message': 'Highscore could not be updated.'
             }, 200
     else:
         return {
             'status': 404,
             'message': 'The server could not find your user account.'
         }, 404
     pass
Exemplo n.º 3
0
def create_a2c_relationship(a_id, c_ids):
    """创建活动与活动内容的关联"""
    if a_id and c_ids:
        for c_id in c_ids:
            sql = """insert into act_has_cont (a_id, c_id) values (:a_id, :c_id)"""
            try:
                db_session.execute(sql, {'a_id': a_id, 'c_id': c_id})
            except Exception as e:
                print 'create_a2c_relationship=>ERROR,str(e): ', str(e)
        db_session.commit()
Exemplo n.º 4
0
    def post(self):
        username = request.form.get('username', None)
        password = request.form.get('password', None)

        if username and password:
            enc_password = AESCipher().encrypt(password)
            set_account = User(username, enc_password)
            conn.add(set_account)
            conn.commit()
            return redirect(url_for('Accounts.accounts'))
Exemplo n.º 5
0
def create_act_cont(a_id, cont_form):
    '''创建活动内容'''
    # 创建活动
    print 'create_act_cont=>a_id', a_id
    latest_cid = get_latest_content_id()  # 已存在的最大c_id  c4
    c_ids = []  # 此a_id的所有活动内容的id
    activates = cont_form.get('activates')
    step = 1
    for act_cont in activates:
        c_id = 'c' + str(int(latest_cid[1:])+step)
        c_ids.append(c_id)
        charger = act_cont.get('charger')
        company = act_cont.get('company')
        start_time = act_cont.get('start_time')
        end_time = act_cont.get('end_time')
        bus_station = act_cont.get('bus_station')
        gps = act_cont.get('gps')
        address = act_cont.get('address')
        print 'c_id', c_id
        print 'type(charger)', type(charger), 'charger', charger
        print 'type(company)', type(company), 'company', company
        print 'type(start_time)', type(start_time), 'start_time', start_time
        print 'type(bus_station)', type(bus_station), 'bus_station', bus_station
        print 'type(end_time)', type(end_time), 'end_time', end_time
        print 'type(gps)', type(gps), 'gps', gps
        print 'type(address)', type(address), 'address', address
        # 插入活动
        sql = """insert into act_content (c_id,charger,company,time_start,time_end,addr,gps,bus_station) 
        values (:c_id,:charger,:company,:time_start,:time_end,:addr,:gps,:bus_station)"""
        try:
            db_session.execute(sql, {
             'c_id': c_id, 'charger': charger, 'company': company, 'time_start': start_time,
                'time_end': end_time, 'addr': address, 'gps': gps, 'bus_station': bus_station
            })
        except Exception as e:
            print 'create_act_cont=>ERROR,str(e): ', str(e)
        step += 1
    # 全部插入后才提交
    db_session.commit()
    # 创建活动与活动内容的关联
    create_a2c_relationship(a_id, c_ids)
Exemplo n.º 6
0
 def post(self):
     args = userParser.parse_args()
     print(args)
     errors = UserRegistrationSchema().validate(args)
     if any(errors):
         error_string = ""
         for i in errors:
             error_string += ";".join(errors[i]) + ";"
         return {'code': 'VALIDATION_ERROR', "error": True, 'errors': error_string[0:-1]}, 400
     user = User(username=args.username, hash=args.password)
     highscore = Highscore(user=user)
     try:
         db_session.add(user)
         db_session.add(highscore)
         db_session.commit()
     except IntegrityError as err:
         return {'code': 'BAD_REQUEST', "error": True,'errors': "Username already exists."}, 403
     except Exception:
         return {'code': 'INTERNAL_ERROR', "error": True, 'errors': 'An unknown error occurred, try again later.'}, 500
     return {'code': 'SUCCESS', "error": False, 'message': 'User was created.'}, 201
     pass
Exemplo n.º 7
0
def create_act():
    '''创建活动'''
    if request.method == 'POST':
        latest_id = get_latest_act_id()
        a_id = 'a' + str(int(latest_id[1:]) + 1) #自动设置最新的活动id
        print "request.get_json().get('actForm')", request.get_json().get('actForm')
        print "request.get_json().get('contForm')", request.get_json().get('contForm')
        # 活动内容列表
        cont_form = request.get_json().get('contForm')
        # 创建活动
        act_form = request.get_json().get('actForm')
        act_title = act_form.get('act_title')
        act_desc = act_form.get('act_desc')
        date_start = act_form.get('date_start').split('T')[0]
        date_end = act_form.get('date_end').split('T')[0]
        act_contact = act_form.get('act_contact')  # 活动联系人
        is_all = act_form.get('is_all')
        print 'type(a_id)', type(a_id), 'a_id',a_id
        print 'type(act_title)', type(act_title), 'act_title',act_title
        print 'type(act_desc)', type(act_desc), 'act_desc',act_desc
        print 'type(date_start)', type(date_start), 'date_start',date_start
        print 'type(date_end)', type(date_end), 'date_end',date_end
        print 'type(act_contact)', type(act_contact), 'act_contact',act_contact
        print 'type(is_all)', type(is_all), 'is_all',is_all
        try:
            # 新建活动
            sql = "insert into activities (a_id,act_title,act_desc,date_start,date_end,act_contact,is_all)" \
                  "values (:a_id,:act_title,:act_desc,:date_start,:date_end,:act_contact,:is_all)"
            db_session.execute(sql, {'a_id':a_id,'act_title':act_title,'act_desc':act_desc,'date_start':date_start,
                                     'date_end':date_end,'act_contact':act_contact,'is_all':is_all})
            db_session.commit()
            # 新建活动内容
            create_act_cont(a_id, cont_form)
            return jsonify({'code': '1', 'msg': '创建活动成功!'})
        except Exception as e:
            print 'create_act=>ERROR,str(e): ', str(e)
            return jsonify({'code': '0', 'msg': '创建活动失败,请联系管理员!'})