views.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:CNX_Flip 作者: tian-lan 项目源码 文件源码
def api_textbook(request):
    method, params, url_param = get_params(request)
    if method == 'OPTIONS':
        return preflight_handler(request)

    # Get a deck from database
    if method == "POST":
        params = json.loads(params)
        deckid = int(params['deckid'])
        userid = url_param['userid']
        uuid_list = params['uuids']

        with transaction.manager:
            for uuid in uuid_list:
                importCardsFromCnxDb(uuid, deckid, CNXDB_HOST)
            target_deck = DBSession.query(Deck).filter(
                Deck.id == deckid and Deck.user_id == userid).first()
            deck = card2dict(target_deck.cards)
            deck['title'] = str(target_deck.title)
            deck['color'] = str(target_deck.color)
            deck['id'] = deckid

        response = update_header(body=json.dumps(deck))
        return response


# @view_config(route_name='api_textbook', renderer='json')
# def api_textbook(request):
#     method, params, url_param = get_params(request)
#     if method == 'OPTIONS':
#         return preflight_handler(request)
#
#     # Get a deck from database
#     if method == "GET":
#         params = json.loads(params)
#         deckid = int(params['deckid'])
#         uuid_list = params['uuids']
#     for uuid in uuid_list:
#         importCardsFromCnxDb(uuid, deckid, cnxdbHost)
#
#     with transaction.manager:
#         target_deck = DBSession.query(Deck).filter(Deck.id == deckid).first()
#         deck = card2dict(target_deck.cards)
#         deck['title'] = str(target_deck.title)
#         deck['color'] = str(target_deck.color)
#         deck['id'] = deck_id
#
#         response = update_header(body=json.dumps(deck))
#         return response




# @view_config(route_name='add_user', renderer = 'json')
# def add_user(request):
#     req_post = request.POST
#     user_name = str(req_post['user_name'])
#     with transaction.manager:
#         model = User(user_name=user_name)
#         DBSession.add(model)
#     return {'add user': 'success'}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号