예제 #1
0
def post_list(request):
    start = request.GET.get('start', None) # required
    business_id = request.GET.get('business_id', None) # optional
    hot_area = request.GET.get('hot_area', None) # optional
    tag = request.GET.get('tag', None) # optional
    q = request.GET.get('q', None) # optional

    post = Post.objects.filter(is_approved=True).order_by('-id')
    if business_id:
        business = Business.objects.get(id=business_id)
        post = post.filter(business=business)
    if hot_area:
        post = post.filter(business__hot_area__name=hot_area)
    if tag:
        post = post.filter(business__tag__name=tag)
    if q:
        post = post.filter(Q(business__tag__name__icontains=q) | Q(business__name__icontains=q) | Q(business__name2__icontains=q))

    start = int(start)
    post = post[start:start+30]
    res = [{
        'id': p.id,
        'title': p.title,
        'preview': p.preview,
        'body': p.body,
        'date': p.datetime.strftime('%Y年%M月%d日'),
        'source': p.source,
        'business': tools.get_business_json(p.business),
        'qrcode': tools.url_to_qrcode('http://xun-wei.com/post/%s'%p.id),
    } for p in post]
    return JsonResponse(res, safe=False)
예제 #2
0
def post_list(request):
    start = request.GET.get('start', None)  # required
    business_id = request.GET.get('business_id', None)  # optional
    hot_area = request.GET.get('hot_area', None)  # optional
    tag = request.GET.get('tag', None)  # optional
    q = request.GET.get('q', None)  # optional

    post = Post.objects.filter(is_approved=True).order_by('-id')
    if business_id:
        business = Business.objects.get(id=business_id)
        post = post.filter(business=business)
    if hot_area:
        post = post.filter(business__hot_area__name=hot_area)
    if tag:
        post = post.filter(business__tag__name=tag)
    if q:
        post = post.filter(
            Q(business__tag__name__icontains=q)
            | Q(business__name__icontains=q)
            | Q(business__name2__icontains=q)).distinct()

    start = int(start)
    post = post[start:start + 50]
    res = [{
        'id': p.id,
        'title': p.title,
        'preview': p.preview,
        'body': p.body,
        'date': p.datetime.strftime('%Y年%M月%d日'),
        'source': p.source,
        'business': tools.get_business_json(p.business),
        'qrcode': tools.url_to_qrcode('http://xun-wei.com/post/%s' % p.id),
    } for p in post]
    return JsonResponse(res, safe=False)
예제 #3
0
def business(request):
    business_id = request.GET.get('business_id', None)

    business = Business.objects.get(id=business_id)
    if not business:
        return HttpResponse(status=404)
    res = tools.get_business_json(business)
    return JsonResponse(res, safe=False)    
예제 #4
0
def business(request):
    business_id = request.GET.get('business_id', None)

    business = Business.objects.get(id=business_id)
    if not business:
        return HttpResponse(status=404)
    res = tools.get_business_json(business)
    return JsonResponse(res, safe=False)
예제 #5
0
def business_list(request):
    start = request.GET.get('start', None) # require
    hot_area = request.GET.get('hot_area', None) # optional
    tag = request.GET.get('tag', None) # optional

    business = Business.objects.all()

    if hot_area:
        business = business.filter(hot_area__name=hot_area)
    if tag:
        business = business.filter(tag__name=tag)

    start = int(start)
    business = business[start:start+30]
    res = [tools.get_business_json(b) for b in business]
    return JsonResponse(res, safe=False)
예제 #6
0
def business_list(request):
    start = request.GET.get('start', None)  # require
    hot_area = request.GET.get('hot_area', None)  # optional
    tag = request.GET.get('tag', None)  # optional

    business = Business.objects.all()

    if hot_area:
        business = business.filter(hot_area__name=hot_area)
    if tag:
        business = business.filter(tag__name=tag)

    start = int(start)
    business = business[start:start + 50]
    res = [tools.get_business_json(b) for b in business]
    return JsonResponse(res, safe=False)
예제 #7
0
def post(request):
    post_id = request.GET.get('post_id', None)

    post = Post.objects.get(id=post_id)
    if not post:
        return HttpResponse(status=404)
    res = {
        'id': post.id,
        'title': post.title,
        'preview': post.preview,
        'body': post.body,
        'date': post.datetime.strftime('%Y年%M月%d日'),
        'source': post.source,
        'business': tools.get_business_json(post.business),
        'qrcode': tools.url_to_qrcode('http://xun-wei.com/post/%s'%post.id),
    }
    return JsonResponse(res, safe=False)
예제 #8
0
def post(request):
    post_id = request.GET.get('post_id', None)

    post = Post.objects.get(id=post_id)
    if not post:
        return HttpResponse(status=404)
    res = {
        'id': post.id,
        'title': post.title,
        'preview': post.preview,
        'body': post.body,
        'date': post.datetime.strftime('%Y年%M月%d日'),
        'source': post.source,
        'business': tools.get_business_json(post.business),
        'qrcode': tools.url_to_qrcode('http://xun-wei.com/post/%s' % post.id),
    }
    return JsonResponse(res, safe=False)