Example #1
0
def get_by_city_and_period():
    """ [GET] get restaurant-activities by city_ids and
        start-date and end-date """
    rest_activity_query = thirdparty_svc.ers.TRestaurantActivityQuery()
    args_spec = {
        'city_ids': Arg([], allow_missing=True),
        'begin_date': Arg(str, allow_missing=True),
        'end_date': Arg(str, allow_missing=True),
        'overdue': Arg(bool, allow_missing=True),
    }
    args = args_parser.parse(args_spec, request)

    city_ids = args.get('city_ids', [])

    if not coffee.hr_permission.isPermittedToThis(
            context=current_user.auth_context,
            permission=auth_map_admin['ACT_RST_ADMIN']):
        user_city_ids = current_user.utp_city_ids
        if city_ids:
            city_ids = list(set(city_ids + user_city_ids))
        else:
            city_ids = user_city_ids

    rest_activity_query.city_ids = city_ids
    rest_activity_query.begin_date = args.get('begin_date', None)
    rest_activity_query.end_date = args.get('end_date', None)
    rest_activity_query.limit = 1000
    overdue = args.get('overdue', None)

    with thrift_client('ers') as ers_client:
        restaurant_activities = ers_client.query_restaurant_activity_for_admin(
            rest_activity_query)

    if overdue is not None:
        today = date.today()
        if overdue:
            restaurant_activities = [
                act for act in restaurant_activities if _overdue(act, today)
            ]
        else:
            restaurant_activities = [
                act for act in restaurant_activities
                if not _overdue(act, today)
            ]

    total_num = len(restaurant_activities)
    rest_activities_page = paging(restaurant_activities)
    for act in rest_activities_page:
        act.activity_name = get_restaurant_activity_name(act)

    return {
        'restaurant_activities': rest_activities_page,
        'total_num': total_num
    }
Example #2
0
def get_by_city_and_period():
    """ [GET] get restaurant-activities by city_ids and
        start-date and end-date """
    rest_activity_query = thirdparty_svc.ers.TRestaurantActivityQuery()
    args_spec = {
        'city_ids': Arg([], allow_missing=True),
        'begin_date': Arg(str, allow_missing=True),
        'end_date': Arg(str, allow_missing=True),
        'overdue': Arg(bool, allow_missing=True),
    }
    args = args_parser.parse(args_spec, request)

    city_ids = args.get('city_ids', [])

    if not coffee.hr_permission.isPermittedToThis(context=current_user.auth_context,
                                                  permission=auth_map_admin['ACT_RST_ADMIN']):
        user_city_ids = current_user.utp_city_ids
        if city_ids:
            city_ids = list(set(city_ids + user_city_ids))
        else:
            city_ids = user_city_ids

    rest_activity_query.city_ids = city_ids
    rest_activity_query.begin_date = args.get('begin_date', None)
    rest_activity_query.end_date = args.get('end_date', None)
    rest_activity_query.limit = 1000
    overdue = args.get('overdue', None)

    with thrift_client('ers') as ers_client:
        restaurant_activities = ers_client.query_restaurant_activity_for_admin(
            rest_activity_query)

    if overdue is not None:
        today = date.today()
        if overdue:
            restaurant_activities = [act for act in restaurant_activities if
                                     _overdue(act, today)]
        else:
            restaurant_activities = [act for act in restaurant_activities if
                                     not _overdue(act, today)]

    total_num = len(restaurant_activities)
    rest_activities_page = paging(restaurant_activities)
    for act in rest_activities_page:
        act.activity_name = get_restaurant_activity_name(act)

    return {
        'restaurant_activities': rest_activities_page,
        'total_num': total_num
    }
Example #3
0
def get_list_from_mm():
    args_spec = {
        'cert_type': Arg(int, allow_missing=True),
        'cert_status': Arg(int, allow_missing=True),
        'time_from': Arg(str, allow_missing=True),
        'time_to': Arg(str, allow_missing=True),
        'restaurant_id_or_name': Arg(unicode, allow_missing=True),
    }
    args = args_parser.parse(args_spec)
    cert_type = args.get('cert_type', None)
    status = args.get('cert_status')
    time_from = args.get('time_from', None)
    time_to = args.get('time_to', None)
    restaurant_id_or_name = args.get('restaurant_id_or_name', None)

    page_no, page_size = get_paging_params()
    offset = (page_no-1)*page_size

    certs = cert_base.get_by_status(status)

    if not certs:
        return {'cert_list': [], 'total_num': 0}

    response_certs = _assemble_cert_response(certs)

    if cert_type:
        response_certs = filter(lambda res: res['type'] == cert_type,
                                response_certs)

    if time_from:
        response_certs = filter(lambda res: time_from <
                                res['application_time'], response_certs)

    if time_to:
        response_certs = filter(lambda res: res['application_time'] <
                                time_to, response_certs)

    if restaurant_id_or_name is not None:
        response_certs = filter(
            lambda res: restaurant_id_or_name in
            str(res['restaurant_id']) + res['restaurant_name'],
            response_certs)

    return {'total_num': len(response_certs),
                             'cert_list': paging(response_certs)}
Example #4
0
def get_list_from_mm():
    args_spec = {
        "cert_type": Arg(int, allow_missing=True),
        "cert_status": Arg(int, allow_missing=True),
        "time_from": Arg(str, allow_missing=True),
        "time_to": Arg(str, allow_missing=True),
        "restaurant_id_or_name": Arg(unicode, allow_missing=True),
    }
    args = args_parser.parse(args_spec)
    cert_type = args.get("cert_type", None)
    status = args.get("cert_status")
    time_from = args.get("time_from", None)
    time_to = args.get("time_to", None)
    restaurant_id_or_name = args.get("restaurant_id_or_name", None)

    page_no, page_size = get_paging_params()
    offset = (page_no - 1) * page_size

    certs = cert_base.get_by_status(status)

    if not certs:
        return {"cert_list": [], "total_num": 0}

    response_certs = _assemble_cert_response(certs)

    if cert_type:
        response_certs = filter(lambda res: res["type"] == cert_type, response_certs)

    if time_from:
        response_certs = filter(lambda res: time_from < res["application_time"], response_certs)

    if time_to:
        response_certs = filter(lambda res: res["application_time"] < time_to, response_certs)

    if restaurant_id_or_name is not None:
        response_certs = filter(
            lambda res: restaurant_id_or_name in str(res["restaurant_id"]) + res["restaurant_name"], response_certs
        )

    return {"total_num": len(response_certs), "cert_list": paging(response_certs)}
Example #5
0
    def gets(cls):
        args_spec = {
            'city_id': Arg(int, allow_missing=True),
            'name': Arg(str, allow_missing=True),
            'is_valid': Arg(bool, allow_missing=True),
            'is_expire': Arg(int, allow_missing=True),
        }
        args = args_parser.parse(args_spec)

        is_expire=args.pop('is_expire',2)

        city_id = args.pop('city_id', None)
        if city_id:
            args['regions'] = {city_id: {}}

        banners, total_num = banner_client.query(args)
        newbanners=[]
        if is_expire!=2:
            today=datetime.date.today()
            for banner in banners:
                end_date=strptime_to_date(banner.end_date)
                if end_date=='':
                    newbanners.append(banner)
                elif is_expire==1 and end_date<today:
                    newbanners.append(banner)
                elif is_expire==0 and end_date>today:
                    newbanners.append(banner)
                else:
                    pass
        else:
            newbanners=banners
        total_num=len(newbanners)
        banners = paging(newbanners)
        return {
            'banners': banners,
            'total_num': total_num
        }