Beispiel #1
0
def snack_like_list(request):
    form = ListIndexCheckForm(request.POST)
    if form.is_valid():
        index = form.cleaned_data['index']
        db_snacks_like = SnackLike.objects.filter(user=form.get_user())
        snacks_like = db_snacks_like[index:index+20]
        #snacks_hate = db_snacks.order_by('-snack_grade')[index:index+20]
        total_count = len(db_snacks_like)
        return HttpResponse(json.dumps(dict(status=dict(title="SnackLikeList", code='OK', reason='OK'),
                                            totalCount=total_count,
                                            snacks=[_snack_like.list_to_dict() for _snack_like in snacks_like])),
                            content_type="application/json")
    return HttpResponse(json.dumps(dict(status=dict(title="SnackLikeList", code="FAIL", reason=form.errors.keys()[0]))),
                        content_type='application/json')
Beispiel #2
0
def snack_list(request):
    form = ListIndexCheckForm(request.POST)
    if form.is_valid():
        index = form.cleaned_data['index']
        db_snacks = Snack.objects.all()
        snacks = db_snacks.order_by('-snack_grade')[index:index+20]
        total_count = len(db_snacks)
        for snack in snacks:
            snack.preference = snack_preference(form, snack)
            #cal_count_grade(snack)
        return HttpResponse(json.dumps(dict(status=dict(title="MainSnackList", code='OK', reason='OK'),
                                            totalCount=total_count,
                                            snacks=[snack.list_to_dict() for snack in snacks])),
                            content_type="application/json")
    return HttpResponse(json.dumps(dict(status=dict(title="MainSnackList", code="FAIL",
                                                    reason=form.errors.keys()[0]))), content_type='application/json')
Beispiel #3
0
def snack_search(request):
    form = ListIndexCheckForm(request.POST)
    snack_name = request.POST['snackName']
    if form.is_valid():
        index = form.cleaned_data['index']
        try:
            db_snacks = Snack.objects.filter(name__contains=snack_name)
            snacks = db_snacks.order_by('-snack_grade')[index:index+20]
            #snacks = db_snacks[index:index+20]
            total_count = len(db_snacks)
            for snack in snacks:
                snack.preference = snack_preference(form, snack)
                #cal_count_grade(snack)
        except Snack.DoesNotExist:
            return HttpResponse(json.dumps(dict(status=dict(title="SnackSearch", code='FAIL',
                                                            reason=u'존재하지 않는 식품입니다.'))),
                                content_type="application/json")
        return HttpResponse(json.dumps(dict(status=dict(title="SnackSearch", code='OK', reason='OK'),
                                            totalCount=total_count,
                                            snacks=[snack.list_to_dict() for snack in snacks])),
                            content_type="application/json")
    return HttpResponse(json.dumps(dict(status=dict(title="SnackSearch", code="FAIL", reason=form.errors.keys()[0]))),
                        content_type='application/json')