Ejemplo n.º 1
0
def categories(request):
    form = CategoryForm()
    if request.method == 'POST':
        if form.validate(request.form):
            form.save()
            return redirect('category/admin/categories')
    return render_to_response('category/admin/category.html',
            {'form':form.as_widget(),
             'categories':Category.all().order('name')})
Ejemplo n.º 2
0
def category_edit(request, id):
    category = Category.get_by_id(id)
    if not category:
        return redirect('category/admin/categories')
    form = CategoryForm(instance=category)
    if request.method == 'POST':
        if form.validate(request.form):
            form.save()
            return redirect('category/admin/categories')
    return render_to_response('category/admin/category.html',
            {'form':form.as_widget(),
             'categories':Category.all().order('name'),
             'edit_flag':True})
Ejemplo n.º 3
0
def create_post(request, *args, **kwargs):
    form = CategoryForm(request.POST or None)

    if form.is_valid():
        item = form.save()

        result = ExecResult(item, msg="创建成功", status=ExecStatus.Success)
        serializer = ExecResultSerializer(result)
        return JSONResponse(serializer.data, status=200)
        # return render_to_response("web4mobile/category/update.html", locals())
    else:
        # return render_to_response("web4mobile/category/create.html", locals())
        result = ExecResult(form.errors, msg="验证参数错误", status=ExecStatus.ClientError)
        serializer = ExecResultSerializer(result)
        return JSONResponse(serializer.data, status=200)
Ejemplo n.º 4
0
def create_post(request, *args, **kwargs):
    form = CategoryForm(request.POST or None)

    if form.is_valid():
        item = form.save()

        result = ExecResult(item, msg="创建成功", status=ExecStatus.Success)
        serializer = ExecResultSerializer(result)
        return JSONResponse(serializer.data, status=200)
        # return render_to_response("web4mobile/category/update.html", locals())
    else:
        # return render_to_response("web4mobile/category/create.html", locals())
        result = ExecResult(form.errors,
                            msg="验证参数错误",
                            status=ExecStatus.ClientError)
        serializer = ExecResultSerializer(result)
        return JSONResponse(serializer.data, status=200)