Exemplo n.º 1
0
def city_list_with_region(request):
    area_obj = CityArea()
    area_d = dict()
    q = City.objects.filter(citylevel__in=[1,2,3])
    for item in q:
        try:
            area_name = area_obj.get_area(item.province.areaid)
            if area_name not in area_d:
                area_d[area_name] = list()
            area_d[area_name].append((item.cityid, item.cityenname, item.cityname))
        except Province.DoesNotExist:
            pass
    #return HttpResponse(json.dumps(area_d), content_type="application/json")
    context = dict()
    context['area_d'] = area_d
    return render(request, 'member/citylist.html', context)
Exemplo n.º 2
0
def index_page(request, page):
    context = dict()
    #get the city name
    if request.user.id != None:
        context['city_id'] = Dper.objects.get(user_id=request.user.id).city
        context['city_name'] = City.objects.get(cityid=context['city_id']).cityname

    flag = False
    if request.path == None or len(request.path) == 1:
        if request.user.id == None:
            city_en_name = "shanghai"
            flag = True
    else:
        city_en_name = request.path[1:-1]
        flag = True

    if flag == True:
        area_obj = CityArea()
        context['city_name'] = area_obj.convert_city_name(city_en_name)
        context['city_id'] = area_obj.get_city_id(city_en_name)


    context['tag_list'] = [tag for tag in Tag.objects.all()][0:10]
    is_login = request.user.is_authenticated()
    context['is_login'] = is_login
    if is_login:
        context['username'] = request.user.username
        context['msg_num'] = Message.objects.filter(targetid=request.user.id, status=0).count()

    book_list = [book for book in Book.objects.filter(city=context['city_id'])]
    for b in book_list:
        if len(b.title) > 12:    
            b.title = b.title[0:12] + '...'
        name = User.objects.filter(id=b.ownerid)[0].username
        dpers = [d for d in Dper.objects.filter(user_id=b.ownerid)]
        department = ''
        if len(dpers) > 0:
            department = dpers[0].department
        b.username = name
        b.position = department
    book_list = Paginator(book_list, 6)
    context['book_list'] = book_list.page(int(page))
    return render(request, 'default/home.html', context)