Exemplo n.º 1
0
def save_category_js(request):
    status = 405
    response = {}
    response['entries'] = []
    if request.is_ajax() and request.method == 'POST':
        ids = request.POST.getlist('ids[]')
        titles = request.POST.getlist('titles[]')
        x = 0
        for the_id in ids:
            the_id = int(the_id)
            the_title = titles[x]
            x += 1
            if 0 == the_id:
                # if the category is new, then create new
                the_cat = EntryCategory(category_title=the_title,
                                        category_owner=request.user)
            else:
                # if the category already exists, update the title
                the_cat = EntryCategory.objects.get(pk=the_id)
                the_cat.category_title = the_title
            the_cat.save()
            response['entries'].append({
                'id': the_cat.id,
                'category_title': the_cat.category_title
            })
        status = 201

    return JsonResponse(response, status=status)
Exemplo n.º 2
0
def save_category_js(request):
    status = 405
    response = []
    if request.is_ajax() and request.method == 'POST':
        ids = request.POST.getlist('ids[]')
        titles = request.POST.getlist('titles[]')
        x = 0
        for the_id in ids:
            the_id = int(the_id)
            the_title = titles[x]
            x += 1
            if 0 == the_id:
                #if the category is new, then create new
                the_cat = EntryCategory(category_title=the_title,
                                        category_owner=request.user)
            else:
                #if the category already exists, update the title
                the_cat = EntryCategory.objects.get(pk=the_id)
                the_cat.category_title = the_title
            the_cat.save()
            response.append({
                'id': the_cat.id,
                'category_title': the_cat.category_title
            })
        status = 201

    return HttpResponse(json.dumps(response),
                        content_type='application/json; charset=utf8',
                        status=status)
Exemplo n.º 3
0
def save_category_js(request):
    status = 405
    response = []
    if request.is_ajax() and request.method == 'POST' :
        ids = request.POST.getlist('ids[]')
        titles = request.POST.getlist('titles[]')
        x = 0;
        for the_id in ids :
            the_id = int(the_id)
            the_title = titles[x]
            x += 1
            if 0 == the_id :
                #if the category is new, then create new
                the_cat = EntryCategory(category_title = the_title, category_owner = request.user)
            else :
                #if the category already exists, update the title
                the_cat = EntryCategory.objects.get(pk = the_id)
                the_cat.category_title = the_title
            the_cat.save()
            response.append({'id': the_cat.id, 'title': the_cat.category_title});
        status = 201
        
    return HttpResponse(
        simplejson.dumps(response),
        content_type = 'application/json; charset=utf8',
        status=status
    )
Exemplo n.º 4
0
def save_category_js(request):
    status = 405
    response = {}
    response['entries'] = []
    if request.is_ajax() and request.method == 'POST':
        ids = request.POST.getlist('ids[]')
        titles = request.POST.getlist('titles[]')
        x = 0
        for the_id in ids:
            the_id = int(the_id)
            the_title = titles[x]
            x += 1
            if 0 == the_id:
                # if the category is new, then create new
                the_cat = EntryCategory(
                    category_title=the_title,
                    category_owner=request.user
                )
            else:
                # if the category already exists, update the title
                the_cat = EntryCategory.objects.get(pk=the_id)
                the_cat.category_title = the_title
            the_cat.save()
            response['entries'].append(
                {'id': the_cat.id, 'category_title': the_cat.category_title}
            )
        status = 201

    return JsonResponse(
        response,
        status=status
    )
Exemplo n.º 5
0
def save_category(request):
    response = {}
    response["entries"] = []
    ids = request.POST.getlist("ids[]")
    titles = request.POST.getlist("titles[]")
    EntryCategory.objects.filter(category_owner=request.user).exclude(
        id__in=ids).delete()
    x = 0
    for the_id in ids:
        the_id = int(the_id)
        the_title = titles[x]
        x += 1
        if 0 == the_id:
            # if the category is new, then create new
            the_cat = EntryCategory(category_title=the_title,
                                    category_owner=request.user)
        else:
            # if the category already exists, update the title
            the_cat = EntryCategory.objects.get(pk=the_id)
            the_cat.category_title = the_title
        the_cat.save()
        response["entries"].append({
            "id": the_cat.id,
            "category_title": the_cat.category_title
        })
    status = 201

    return JsonResponse(response, status=status)