コード例 #1
0
ファイル: region.py プロジェクト: liuzelei/walis
def delete(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    region = region_base.get(pk)
    if region['type_code'] == WHITE_COLLAR_TYPE_CODE:
        white_collar_base.delete_by_region(pk)
    region_base.delete(pk)
    return ''
コード例 #2
0
def delete(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    region = region_base.get(pk)
    if region['type_code'] == WHITE_COLLAR_TYPE_CODE:
        white_collar_base.delete_by_region(pk)
    region_base.delete(pk)
    return ''
コード例 #3
0
ファイル: region.py プロジェクト: liuzelei/walis
def get(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    result = region_base.get(pk)
    dic_fields_process(result, excludes=['has_geohash', 'color'])
    result['_area'] = back_area_to_front_area(result['area'])
    if result['type_code'] == WHITE_COLLAR_TYPE_CODE:
        result['buildings'] = _get_building_by_region_id(result['id'])
    return result
コード例 #4
0
def get(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    result = region_base.get(pk)
    dic_fields_process(result, excludes=['has_geohash', 'color'])
    result['_area'] = back_area_to_front_area(result['area'])
    if result['type_code'] == WHITE_COLLAR_TYPE_CODE:
        result['buildings'] = _get_building_by_region_id(result['id'])
    return result
コード例 #5
0
ファイル: region.py プロジェクト: liuzelei/walis
def check_region(*args, **kwargs):
    if current_user.is_super_admin():
        return True
    region_id = int(kwargs['pk'])
    if region_id in current_user.region_ids:
        return True
    city_ids = current_user.city_ids
    if city_ids:
        region = region_base.get(region_id)
        if region['city_id'] in city_ids:
            return True
コード例 #6
0
def check_region(*args, **kwargs):
    if current_user.is_super_admin():
        return True
    region_id = int(kwargs['pk'])
    if region_id in current_user.region_ids:
        return True
    city_ids = current_user.city_ids
    if city_ids:
        region = region_base.get(region_id)
        if region['city_id'] in city_ids:
            return True
コード例 #7
0
ファイル: region.py プロジェクト: liuzelei/walis
def put(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    dic = args_parser.parse_all()
    region = region_base.get(pk)
    dic['area'] = front_area_to_back_area(dic['_area'])
    result = region_base.put(pk, dic)
    if region['type_code'] == WHITE_COLLAR_TYPE_CODE and dic['type_code'] != WHITE_COLLAR_TYPE_CODE:
        white_collar_base.delete_by_region(result)
    if dic['type_code'] == WHITE_COLLAR_TYPE_CODE:
        white_collar_base.update_building_region(result, dic['_area'])
    return result
コード例 #8
0
def put(pk):
    pk = int(pk)
    if not check_region(pk=pk):
        raise_auth_exc(AUTH_FAILED_ERROR)
    dic = args_parser.parse_all()
    region = region_base.get(pk)
    dic['area'] = front_area_to_back_area(dic['_area'])
    result = region_base.put(pk, dic)
    if region['type_code'] == WHITE_COLLAR_TYPE_CODE and dic[
            'type_code'] != WHITE_COLLAR_TYPE_CODE:
        white_collar_base.delete_by_region(result)
    if dic['type_code'] == WHITE_COLLAR_TYPE_CODE:
        white_collar_base.update_building_region(result, dic['_area'])
    return result
コード例 #9
0
def get_trs_by_region_id(region_id):
    region = region_svc.get(region_id)
    area = json.loads(region['area'])[0]['point']
    points = [[float(p.split(',')[1]), float(p.split(',')[0])] for p in area]
    points.append(points[0])

    polygon = {'type': 'Polygon', 'coordinates': [points]}

    area_json = geojson_to_wkbelement(json.dumps(polygon))
    log.info('area_json: {}'.format(area_json))
    daily_trs = inner.get_order_transaction(region['city_id'], area_json)
    if not daily_trs:
        daily_trs = 0.0
    daily_amount = float(daily_trs) / 7.0

    return {
        'id': region_id,
        'name': region['name'],
        'trs': round(daily_amount, 2),
    }
コード例 #10
0
ファイル: transaction.py プロジェクト: liuzelei/walis
def get_trs_by_region_id(region_id):
    region = region_svc.get(region_id)
    area = json.loads(region['area'])[0]['point']
    points = [[float(p.split(',')[1]), float(p.split(',')[0])]
              for p in area]
    points.append(points[0])

    polygon = {'type': 'Polygon', 'coordinates': [points]}

    area_json = geojson_to_wkbelement(json.dumps(polygon))
    log.info('area_json: {}'.format(area_json))
    daily_trs = inner.get_order_transaction(region['city_id'], area_json)
    if not daily_trs:
        daily_trs = 0.0
    daily_amount = float(daily_trs) / 7.0

    return {
        'id': region_id,
        'name': region['name'],
        'trs': round(daily_amount, 2),
    }