예제 #1
0
async def area_update(request,show_id=''):
    '''
    更新地址
    :param request:
    :param show_id:
    :return:
    '''
    if request.method == 'GET':
        show_id = request.args.get("show_id")
        areas = Areas.select().filter(Areas.parent_code == '+86').order_by(Areas.order.asc())
        send = SendAddress.get(SendAddress.id == request.app.get_id_by_show_id(show_id))
        return jinja.render("admin/area_update.html", request, send=send, areas=areas)
    if request.method == 'POST':
        cookie = request.cookies.get("user")
        user = get_cookies(AGENT_COOKIE_TOKEN, cookie)
        data = request.form
        kargs = {key: value[0] for key, value in data.items()}

        {'sender_name': '赵六', 'sender_mobile': '1221212121',
         'sender_prov': '14', 'sender_city': '杭州市', 'sender_area': '余杭区',
         'sender_address': '231312312'}
        try:
            prov_code = int(kargs.pop('sender_prov'))
            sender_prov = Areas.get(Areas.code==prov_code).name
            city_code = int(kargs.pop('sender_city'))
            sender_city = Areas.get(Areas.code == city_code).name
            area_code = int(kargs.pop('sender_area'))
            sender_area = Areas.get(Areas.code == area_code).name
        except:
            pass
        kargs.update({'sender_prov':sender_prov,'sender_city':sender_city,'sender_area':sender_area})
        SendAddress.update(**kargs).where(SendAddress.id == request.app.get_id_by_show_id(show_id),
                                        SendAddress.user_id == request.app.get_id_by_show_id(user.get('show_id'))).execute()
        return text('修改成功')
예제 #2
0
 def update_Area(self, show_id, **kargs):
     '''
     修改默认地址
     :param show_id:
     :param kargs:
     :return:
     '''
     info = SendAddress.update(**kargs).where(
         SendAddress.id == show_id).execute()
     return info
예제 #3
0
async def area_list(request):
    '''
    地址管理
    :param request:
    :return:
    '''
    if request.method == 'GET':
        cookie = request.cookies.get("user")
        user = get_cookies(AGENT_COOKIE_TOKEN, cookie)
        user_id = user.get("id")
        send = SendAddress.select().filter(SendAddress.user_id==user_id,SendAddress.deleted == 0)
        areas = Areas.select().filter(Areas.parent_code == '+86').order_by(Areas.order.asc())
        kargs = {}
        kargs["sender_name"] = request.args.get("sender_name", "")
        kargs["sender_mobile"] = request.args.get("sender_mobile", "")
        query = AreaService().query_list(user_id,**kargs)
        data = get_page_data(request, query)
        return jinja.render("admin/area_list.html", request, kargs=kargs, data=data, areas=areas,send=send)
    elif request.method == "POST":
        id = request.form.get("id")
        SendAddress.update({SendAddress.deleted: 1}).where(SendAddress.id == id).execute()
        return text("已删除")