示例#1
0
def del_member(id):
    user = current_identity
    member = Members.query.filter_by(id=id, user_id=user.id).first()
    Tickets.query.filter_by(member_id=id).delete()
    db.session.delete(member)
    db.session.commit()
    return jsonify(get_model_dict(member))
示例#2
0
def regist_user():
    data = request.data.decode('utf-8')
    user = json.loads(data)
    user['password'] = user['password'].encode('utf-8')
    user['password'] = hashlib.sha512(user['password']).hexdigest()
    user = Users(user['username'], user['password'])
    db.session.add(user)
    db.session.commit()
    return jsonify(get_model_dict(user))
示例#3
0
def regist_concert():
    user = current_identity
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')
    concert = json.loads(data)['concert']
    if 'id' in concert.keys():
        print('update')
        obj = Concerts.query.get(concert['id'])
        obj.name = concert['name']
        print(get_model_dict(obj))
        concert = jsonify(get_model_dict(obj))
    else:
        print('create')
        concert = Concerts(concert['name'], user.id)
        db.session.add(concert)
        concert = jsonify(get_model_dict(concert))
    db.session.commit()
    return concert
示例#4
0
def save_ticket():
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')
    ticket = json.loads(data)['ticket']
    print('update')
    obj = Tickets.query.get(ticket['id'])
    obj.number = ticket['num']
    obj.status = ticket['status']
    obj.modified = datetime.now()
    db.session.commit()
    ticket = jsonify(get_model_dict(obj))
    return ticket
示例#5
0
def regist_member():
    user = current_identity
    print(user)
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')
    member = json.loads(data)['member']
    if 'id' in member.keys():
        print('update')
        obj = Members.query.get(member['id'])
        obj.name = member['name']
        obj.application = member['application']
        obj.winning = member['winning']
        print(get_model_dict(obj))
        member = jsonify(get_model_dict(obj))
    else:
        print('create')
        member = Members(member['name'], user.id)
        db.session.add(member)
        member = jsonify(get_model_dict(member))
    db.session.commit()
    return member
示例#6
0
def save_scheule():
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')
    sch = json.loads(data)['schedule']
    print('update')
    obj = Schedules.query.get(sch['id'])
    obj.date = sch['date']
    obj.time = sch['time']
    obj.place = sch['place']
    obj.modified = datetime.now()
    db.session.commit()
    schedule = jsonify(get_model_dict(obj))
    return schedule
示例#7
0
def regist_scheule():
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')
    sch = json.loads(data)['schedule']
    if 'id' in sch.keys():
        print('update')
        obj = Schedules.query.get(sch['id'])
        obj.date = sch['date']
        obj.time = sch['time']
        obj.place = sch['place']
        obj.modified = datetime.now()
        schedule = obj
    else:
        print('create')
        schedule = Schedules(sch['concert']['id'], sch['date'], sch['time'], sch['place'])
        db.session.add(schedule)
    db.session.commit()
    schedule = jsonify(get_model_dict(schedule))
    return schedule
示例#8
0
def ticket():
    data = request.data.decode('utf-8')
    data = json.loads(data)
    member_id = data['member_id']
    schedule_id = data['schedule_id']
    tickets = Tickets.query.filter_by(member_id=member_id, schedule_id=schedule_id).all()
    tickets = [get_model_dict(ticket) for ticket in tickets]
    ret = {}
    for ticket in tickets:
        schedule_id = ticket['schedule_id']
        obj = {}
        obj['ID'] = ticket['id']
        obj['date'] = ticket['created']
        obj['status'] = ticket['status']
        if schedule_id in ret.keys():
            ret[schedule_id].append(obj) 
        else:
            ret[schedule_id] = [obj]
    return jsonify(ret)
示例#9
0
def regist_ticket():
    print(request.data.decode('utf-8'))
    data = request.data.decode('utf-8')

    ticket = json.loads(data)['ticket']
    if 'id' in ticket.keys():
        print('update')
        obj = Tickets.query.get(ticket['id'])
        obj.number = ticket['num']
        obj.status = ticket['status']
        obj.modified = datetime.now()
        ticket = obj
    else:
        print('create')
        ticket = Tickets(ticket['member']['id'], ticket['schedule']['id'], ticket['status'], ticket['number'])
        db.session.add(ticket)
    db.session.commit()
    ticket = jsonify(get_model_dict(ticket))
    return ticket
示例#10
0
def dict_schedules(member_id):
    schedules = Schedules.query.all()
    schedules = [get_model_dict(schedule) for schedule in schedules]
    ret = {}
    for schedule in schedules:
        concert_id = schedule['concert_id']
        ticket = Tickets.query.filter_by(member_id=member_id, schedule_id=schedule['id']).first()
        obj = {}
        obj['schedule_id'] = schedule['id']
        obj['date'] = '%s %s'%(schedule['date'], schedule['time'])
        obj['place'] = schedule['place']
        if ticket is None: continue
        obj['ticket_id'] = ticket.id
        obj['status'] = ticket.status
        obj['num'] = ticket.number
        if concert_id in ret.keys():
            ret[concert_id].append(obj) 
        else:
            ret[concert_id] = [obj]
    print(ret)
    return jsonify(ret)
示例#11
0
def concerts():
    user = current_identity
    concerts = Concerts.query.filter_by(user_id=user.id).all()
    concerts = [get_model_dict(concert) for concert in concerts]
    concerts = sorted(concerts, key=lambda x:x['id'], reverse=True)
    return jsonify(concerts)
示例#12
0
def del_concert(id):
    user = current_identity
    concert = Concerts.query.filter_by(id=id, user_id=user.id).first()
    db.session.delete(concert)
    db.session.commit()
    return jsonify(get_model_dict(concert))
示例#13
0
def member(id):
    user = current_identity
    member = Members.query.filter_by(id=id, user_id=user.id).first()
    return jsonify(get_model_dict(member))
示例#14
0
def members():
    user = current_identity
    members = Members.query.filter_by(user_id=user.id).all()
    members = [get_model_dict(member) for member in members]
    return jsonify(members)
示例#15
0
def schedules():
    schedules = Schedules.query.all()
    schedules = [get_model_dict(schedule) for schedule in schedules]
    return jsonify(schedules)
示例#16
0
def del_schedule(id):
    user = current_identity
    schedule = Schedules.query.filter_by(id=id, user_id=user.id).first()
    db.session.delete(schedule)
    db.session.commit()
    return jsonify(get_model_dict(schedule))
示例#17
0
def del_ticket(id):
    ticket = Tickets.query.filter_by(id=id).first()
    db.session.delete(ticket)
    db.session.commit()
    return jsonify(get_model_dict(ticket))
示例#18
0
def concert(id):
    user = current_identity
    concert = Concerts.query.filter_by(id=id, user_id=user.id).first()
    return jsonify(get_model_dict(concert))