Exemplo n.º 1
0
def format_department(objs, num):
    data = []

    for x in objs:
        num += 1
        city = CityBase().get_city_by_id(x.city_id) if x.city_id else None
        district = CityBase().get_district_by_id(
            x.district_id) if x.district_id else None

        data.append({
            'num': num,
            'department_id': x.id,
            'company_id': x.company.id,
            'company_name': x.company.name,
            'name': x.name,
            'des': x.des,
            'custom_manager_count': x.cm_count,
            'address': x.addr,
            'tel': x.tel,
            'sort_num': x.sort_num,
            'city_id': city.id if city else '',
            'city_name': city.city if city else '',
            'city_pinyin_abbr': city.pinyin_abbr if city else '',
            'district_id': district.id if district else '',
            'district_name': district.district if district else ''
        })

    return data
Exemplo n.º 2
0
def kaihu_ad(context):
    """
    @note: 头条最新热榜
    """
    from common import utils
    from www.kaihu.interface import AdBase, CityBase

    city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', ''))
    dict_ads = {
        "mz": ["ad_mz.jpg", "8655809", u"梅州"], 
        "my": ["ad_my.jpg", "1919994989", u"绵阳"], 
        "chengdu": ["ad_chengdu.jpg", "2277483400", u"成都"],
        "deyang": ["ad_deyang.jpg", "1547037393", u"德阳"],
        "gy": ["ad_gy.jpg", "342437260", u"广元"],
        "fushun": ["ad_fushun.jpg", "1508819430", u"抚顺"],
        "pj": ["ad_pj.jpg", "1315946235", u"盘锦"],
    }

    dict_ads = {}
    for x in AdBase().get_ads():
        city = CityBase().get_city_by_id(x.city_id)

        dict_ads[city.pinyin_abbr] = [x.img, x.qq, city.city]

    # print 'dict_ads', dict_ads

    default = ["http://static.zhixuan.com/img/kaihu/ad_common.jpg", "403897485", u""]
    ad_img = dict_ads.get(city_abbr, default)

    return render_to_response('kaihu/_kaihu_ad.html', locals(), context_instance=context).content
Exemplo n.º 3
0
def search(request):
    data = []
    flb = FriendlyLinkBase()
    fls = []

    link_type = request.REQUEST.get('link_type')
    name = request.REQUEST.get('name')
    city_name = request.REQUEST.get('city_name')
    page_index = int(request.REQUEST.get('page_index'))

    city_id = None
    if city_name:
        temp = CityBase().get_one_city_by_name(city_name)
        if temp:
            city_id = temp.id

    fls = flb.search_links_for_admin(link_type, name, city_id)

    page_objs = page.Cpt(fls, count=10, page=page_index).info

    # 格式化json
    num = 10 * (page_index - 1)
    data = format_friendly_link(flb.format_friendly_links(page_objs[0]), num)

    return HttpResponse(json.dumps({
        'data': data,
        'page_count': page_objs[4],
        'total_count': page_objs[5]
    }),
                        mimetype='application/json')
Exemplo n.º 4
0
def format_district(objs, num):
    data = []

    for x in objs:
        num += 1
        city = CityBase().get_city_by_id(x.city)

        data.append({
            'num': num,
            'district_id': x.id,
            'district_name': x.district,
            'city_id': city.id if city else '',
            'city_name': city.city if city else '',
            'city_pinyin_abbr': city.pinyin_abbr if city else '',
            'is_show': x.is_show,
            'pinyin': x.pinyin,
            'pinyin_abbr': x.pinyin_abbr,
            'sort_num': x.sort_num,
            # 'rank': x.baidu_rank if x.is_show else '未开放',
            # 'rank_url': x.get_baidu_search_url() if x.is_show else '#'
            'rank': u'未开放',
            'rank_url': ''
        })

    return data
Exemplo n.º 5
0
def search(request):
    data = []
    flb = FriendlyLinkBase()
    fls = []

    name = request.REQUEST.get('name')
    city_name = request.REQUEST.get('city_name')
    page_index = int(request.REQUEST.get('page_index'))

    if name:
        fls = FriendlyLinkBase().get_friendly_link_by_name(name)
    else:
        # 获取所有正常与不正常的客户经理
        fls = flb.get_all_friendly_link(state=None)

        # 城市
        if city_name:
            city = CityBase().get_one_city_by_name(city_name)
            if city:
                fls = fls.filter(city_id=city.id)
            else:
                fls = []

    page_objs = page.Cpt(fls, count=10, page=page_index).info

    # 格式化json
    num = 10 * (page_index - 1)
    data = format_friendly_link(flb.format_friendly_links(page_objs[0]), num)

    return HttpResponse(json.dumps({
        'data': data,
        'page_count': page_objs[4],
        'total_count': page_objs[5]
    }),
                        mimetype='application/json')
Exemplo n.º 6
0
def get_districts_by_city(request):
    city_id = request.REQUEST.get('city_id')
    data = []

    for d in CityBase().get_districts_by_city(city_id):
        data.append({'district_id': d.id, 'district_name': d.district})

    return HttpResponse(json.dumps(data), mimetype='application/json')
Exemplo n.º 7
0
def random_department(context):
    """
    @note: 随机出现营业部
    """
    from common import utils
    from www.kaihu.interface import DepartmentBase, CityBase

    city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', ''))
    city = CityBase().get_city_by_pinyin_abbr(city_abbr)

    departments = DepartmentBase().get_departments_by_random(city.id)[:10]
    return render_to_response('kaihu/_random_department.html', locals(), context_instance=context).content
Exemplo n.º 8
0
def get_citys_by_name(request):
    '''
    根据名字查询城市
    '''
    city_name = request.REQUEST.get('city_name')

    result = []

    citys = CityBase().get_citys_by_name(city_name)

    if citys:
        for x in citys:
            result.append([x.id, x.city, None, x.city])

    return HttpResponse(json.dumps(result), mimetype='application/json')
Exemplo n.º 9
0
def modify_district(request):
    district_id = request.REQUEST.get('district_id')
    district = request.REQUEST.get('name')
    pinyin = request.REQUEST.get('pinyin')
    pinyin = pinyin if pinyin else None
    pinyin_abbr = request.REQUEST.get('pinyin_abbr')
    pinyin_abbr = pinyin_abbr if pinyin_abbr else None
    sort_num = int(request.REQUEST.get('sort'))
    is_show = int(request.REQUEST.get('is_show'))

    return CityBase().modify_district(district_id,
                                      pinyin=pinyin,
                                      sort_num=sort_num,
                                      pinyin_abbr=pinyin_abbr,
                                      is_show=is_show,
                                      district=district)
Exemplo n.º 10
0
def modify_city(request):
    city_id = request.REQUEST.get('city_id')
    city = request.REQUEST.get('name')
    pinyin = request.REQUEST.get('pinyin')
    pinyin_abbr = request.REQUEST.get('pinyin_abbr')
    sort_num = int(request.REQUEST.get('sort'))
    is_show = int(request.REQUEST.get('is_show'))
    note = request.REQUEST.get('note')

    return CityBase().modify_city(city_id,
                                  pinyin=pinyin,
                                  sort_num=sort_num,
                                  pinyin_abbr=pinyin_abbr,
                                  is_show=is_show,
                                  city=city,
                                  note=note)
Exemplo n.º 11
0
def latest_article(context):
    """
    @note: 最新资讯
    """
    import re
    from common import utils
    from www.kaihu.interface import ArticleBase, CityBase

    city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', ''))
    city = CityBase().get_city_by_pinyin_abbr(city_abbr)

    path = context['request'].path
    p = re.compile(u'\/kaihu/article\/?\d*', re.I)
    ps = dict(city_id=city.id)
    if p.findall(path):
        ps.update(dict(order_by="?"))
    articles = ArticleBase().get_articles_by_city_id(**ps)[:10]

    return render_to_response('kaihu/_latest_article.html', locals(), context_instance=context).content
Exemplo n.º 12
0
def format_ad(objs, num):
    data = []

    for x in objs:
        num += 1
        city = CityBase().get_city_by_id(x.city_id) if x.city_id else None

        data.append({
            'num': num,
            'ad_id': x.id,
            'city_id': city.id if city else '',
            'city_name': city.city if city else '',
            'city_pinyin_abbr': city.pinyin_abbr if city else '',
            'qq': x.qq,
            'img': x.img,
            'expire_time': str(x.expire_time)[:10],
            'state': x.state,
            'create_time': str(x.create_time)
        })

    return data
Exemplo n.º 13
0
def search(request):
    data = []

    name = request.REQUEST.get('name')
    city_name = request.REQUEST.get('city_name')
    is_show = request.REQUEST.get('is_show')

    page_index = int(request.REQUEST.get('page_index'))

    objs = CityBase().search_districts_for_admin(name, city_name, is_show)

    page_objs = page.Cpt(objs, count=10, page=page_index).info

    # 格式化json
    num = 10 * (page_index - 1)
    data = format_district(page_objs[0], num)

    return HttpResponse(json.dumps({
        'data': data,
        'page_count': page_objs[4],
        'total_count': page_objs[5]
    }),
                        mimetype='application/json')
Exemplo n.º 14
0
def format_city(objs, num):
    data = []

    for x in objs:
        num += 1
        province = CityBase().get_province_by_id(x.province)

        data.append({
            'num': num,
            'city_id': x.id,
            'city_name': x.city,
            'province_id': province.id if province else '',
            'province_name': province.province if province else '',
            'is_show': x.is_show,
            'pinyin': x.pinyin,
            'pinyin_abbr': x.pinyin_abbr,
            'sort_num': x.sort_num,
            'rank': x.baidu_rank if x.is_show else '未开放',
            'rank_url': x.get_baidu_search_url() if x.is_show else '#',
            'department_count': x.department_count,
            'note': x.note or ''
        })

    return data
Exemplo n.º 15
0
def format_article(objs, num):
    data = []

    for x in objs:
        num += 1
        city = CityBase().get_city_by_id(x.city_id) if x.city_id else None

        data.append({
            'num':
            num,
            'article_id':
            x.id,
            'title':
            x.title,
            'content':
            x.content,
            'city_id':
            city.id if city else '',
            'city_name':
            city.city if city else '',
            'city_pinyin_abbr':
            city.pinyin_abbr if city else '',
            'department_id':
            x.department_id if x.department_id else '',
            'department_name':
            DepartmentBase().get_department_by_id(x.department_id).name
            if x.department_id else '',
            'sort_num':
            x.sort_num,
            'state':
            x.state,
            'create_time':
            str(x.create_time)
        })

    return data
Exemplo n.º 16
0
def search(request):
    data = []

    name = request.REQUEST.get('name')
    is_show = request.REQUEST.get('is_show')
    sort_by_province = request.REQUEST.get('sort_by_province')
    sort_by_province = True if sort_by_province == "1" else False

    page_index = int(request.REQUEST.get('page_index'))

    objs = CityBase().search_citys_for_admin(name, is_show, sort_by_province)

    page_objs = page.Cpt(objs, count=500, page=page_index).info

    # 格式化json
    num = 500 * (page_index - 1)
    data = format_city(page_objs[0], num)

    return HttpResponse(json.dumps({
        'data': data,
        'page_count': page_objs[4],
        'total_count': page_objs[5]
    }),
                        mimetype='application/json')
Exemplo n.º 17
0
def get_district_by_id(request):
    district_id = request.REQUEST.get('district_id')

    data = format_district([CityBase().get_district_by_id(district_id)], 1)[0]

    return HttpResponse(json.dumps(data), mimetype='application/json')
Exemplo n.º 18
0
def modify_note(request):
    city_id = request.REQUEST.get('city_id')
    note = request.REQUEST.get('note')

    return CityBase().modify_city(city_id, note=note)