Example #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)
Example #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)
Example #3
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)
Example #4
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)