예제 #1
0
def get_paginator(model=None, per_page=10, page=1, orderby=None, **kwargs):
    if page is None:
        page = 1
    if not isinstance(model, str):
        model = model.value
    try:
        cmsmodel = getattr(cmsmodels, model)
    except AttributeError:
        raise Http404
    # append is_enable=1 is_show=1 is_frozen=0
    kwargs = append_kwargs(model, kwargs)
    objs = cmsmodel.objects.all()
    if kwargs:
        objs = objs.filter(**kwargs)
    if orderby:
        orderby = str2array(orderby)
        objs = objs.order_by(*orderby)
    paginator = Paginator(objs, per_page)
    p = paginator.page(page)
    page_dict = {}
    page_dict['paginator'] = {
        'count': paginator.count,
        'num_pages': paginator.num_pages,
    }
    page_dict['object_list'] = list(p.object_list.values())

    return page_dict
예제 #2
0
def list_objs(model=None,
              offset=None,
              count=None,
              orderby=None,
              exclude=None,
              **kwargs):
    if not isinstance(model, str):
        model = model.value
    try:
        cmsmodel = getattr(cmsmodels, model)
    except AttributeError:
        raise Http404
    # append is_enable=1 is_show=1 is_frozen=0
    kwargs = append_kwargs(model, kwargs)
    objs = cmsmodel.objects.all()
    if kwargs:
        objs = objs.filter(**kwargs)
    if exclude:
        objs = objs.exclude(**exclude)
    if orderby:
        orderby = str2array(orderby)
        objs = objs.order_by(*orderby)
    if offset and count:
        offset = int(offset)
        count = int(count)
        objs = objs[offset:offset + count]
    elif offset:
        offset = int(offset)
        objs = objs[offset:]
    elif count:
        count = int(count)
        objs = objs[:count]
    return objs
예제 #3
0
def get_offerprice(city_id=None,
                   dealer_id=None,
                   dealer_id_list=None,
                   car_series_id=None,
                   car_type_id=None):
    """
        根据城市ID或者经销商ID或者车系ID或者车型ID返回最低报价,
        车系ID和车型ID必选一个

        参数
        ----
        city_id : int, 可选
            城市ID
        dealer_id : int, 可选
            经销商ID
        dealer_id_list : list, 可选
            经销商ID数组
        car_series_id : int, 可选
            车系ID
        car_type_id : int, 可选
            车型ID

        返回值
        ------
        result_dict : dict
            返回最低报价
    """
    city_id = common_utils.to_int(city_id)
    dealer_id = common_utils.to_int(dealer_id)
    dealer_id_list = str2array(dealer_id_list)
    car_series_id = common_utils.to_int(car_series_id)
    car_type_id = common_utils.to_int(car_type_id)
    if car_type_id:
        if dealer_id:
            return get_offerprice_by_type_dealer(car_type_id=car_type_id,
                                                 dealer_id=dealer_id)
        elif dealer_id_list:
            return get_offerprice_by_type_dealer_list(
                car_type_id=car_type_id, dealer_id_list=dealer_id_list)
        elif city_id:
            return get_offerprice_by_type_city(car_type_id=car_type_id,
                                               city_id=city_id)
        else:
            return get_offerprice_by_type(car_type_id=car_type_id)
    elif car_series_id:
        if dealer_id:
            return get_offerprice_by_series_dealer(car_series_id=car_series_id,
                                                   dealer_id=dealer_id)
        elif dealer_id_list:
            return get_offerprice_by_series_dealer_list(
                car_series_id=car_series_id, dealer_id_list=dealer_id_list)
        elif city_id:
            return get_offerprice_by_series_city(car_series_id=car_series_id,
                                                 city_id=city_id)
        else:
            return get_offerprice_by_series(car_series_id=car_series_id)

    else:
        return get_offerprice_none()
예제 #4
0
def get_car_series_property(car_series_id=None, prop_keys=None):
    """
        车系页面,PC和WAP通用
        获取车系下所有车型的多个属性

        参数
        ----
        car_series_id : int
            车系ID
        prop_keys : list of str
            属性对应的字符串数组,例如['pailiang', 'chang']

        返回值
        ------
        result_dict : dict
            每个属性的KEY对应的是一个数组,
            对应的是所有车型的不同的值
    """
    if not prop_keys:
        return None
    car_series_id = common_utils.to_int(car_series_id)

    prop_keys = str2array(prop_keys)

    cursor = connection().cursor()
    car_series_sql = """
        SELECT 
            a.order_no, a.property_key, a.name, b.property_value 
        FROM 
            t_base_car_type_property_template AS a, 
            t_base_car_type_property AS b, 
            t_base_car_type AS c 
        WHERE 
            a.id=b.property_id 
            AND b.car_type_id=c.id 
            AND c.car_series_id=%s 
            AND a.property_key in %s
            AND a.is_enable=1
            AND b.is_enable=1
            AND c.is_enable=1
            AND c.is_show=1
    """
    cursor.execute(car_series_sql, [car_series_id, prop_keys])
    rows = dictfetchall(cursor)
    prop_dict = {}
    for row in rows:
        key = row['property_key']
        if key not in prop_dict:
            prop_dict[key] = []
            prop_dict[key].append(row)
        else:
            is_contained = False
            for prop in prop_dict[key]:
                if prop['property_value'] == row['property_value']:
                    is_contained = True
                    break
            if not is_contained:
                prop_dict[key].append(row)
    return prop_dict
예제 #5
0
def get_dealer_list_by_id_list(dealer_id_list=None):
    dealer_id_list = str2array(dealer_id_list)
    if not dealer_id_list:
        return None
    dealer_list = []
    for dealer_id in dealer_id_list:
        tmp_dealer = get_dealer_by_id(dealer_id=dealer_id)
        if tmp_dealer:
            dealer_list.append(tmp_dealer)
    return dealer_list
예제 #6
0
def get_car_type_property_back(car_type_id=None, prop_keys=None):
    """
        车型页面,PC和WAP通用,
        获取车型属性

        参数
        ----
        car_type_id : int
            车型ID
        prop_keys : list of str
            属性对应的字符串数组,例如['pailiang', 'chang']

        返回值
        ------
        result_dict : dict
            返回车型属性
    """
    if not prop_keys:
        return None

    car_type_id = common_utils.to_int(car_type_id)
    prop_keys = str2array(prop_keys)

    cursor = connection().cursor()
    car_type_sql = """
        SELECT 
            a.order_no, a.property_key, a.name, b.property_value 
        FROM 
            t_base_car_type_property_template AS a, 
            t_base_car_type_property AS b 
        WHERE 
            a.id=b.property_id 
            AND b.car_type_id=%s 
            AND a.property_key in %s
            AND a.is_enable=1
            AND b.is_enable=1
    """
    cursor.execute(car_type_sql, [car_type_id, prop_keys])
    rows = dictfetchall(cursor)
    prop_dict = {}
    # for tmp_prop_key in prop_keys:
    #     prop_dict[tmp_prop_key] = {
    #         'order_no': 0,
    #         'property_key': tmp_prop_key,
    #         'name': '',
    #         'property_value': '',
    #     }
    for row in rows:
        prop_dict[row['property_key']] = row
    return prop_dict
예제 #7
0
def get_offerprice_by_type_dealer_list(car_type_id=None, dealer_id_list=None):
    car_type_id = common_utils.to_int(car_type_id)
    dealer_id_list = str2array(dealer_id_list)
    if not dealer_id_list:
        return get_offerprice_none_type(car_type_id=car_type_id)
    try:
        offer_price = list_objs(
            model=ModelName.T_BASE_OFFER_PRICE,
            orderby=['public_offer_price', '-created_date'],
            is_enable=1,
            car_type_id=car_type_id,
            dealer_id__in=dealer_id_list)[0]
    except IndexError:
        return get_offerprice_none_type(car_type_id=car_type_id)
    offer_price_dict = get_offerprice_by_model(offer_price=offer_price)
    return offer_price_dict