Ejemplo n.º 1
0
def add_ajax(request):
    form = ProductGroupForm(request.POST, instance=ProductGroup())

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

        return HttpResponse(simplejson.dumps({'name': a.name,
                                              'valid':True,
                                              'id': a.id}), mimetype='application/json')


    else:
       errors = dict([(field, errors[0]) for field, errors in form.errors.items()])

       return HttpResponse(simplejson.dumps({'errors': errors,
                                             'valid': False}), mimetype='application/json')

    return HttpResponse("ERROR")
Ejemplo n.º 2
0
def form(request, id=False):
    if id:
        instance = get_object_or_404(ProductGroup, id=id, deleted=False)
        msg = "Velykket endret produktgruppen"
    else:
        instance = ProductGroup()
        msg = "Velykket lagt til ny produktgruppe"

    #Save and set to active, require valid form
    if request.method == 'POST':
        form = ProductGroupForm(request.POST, instance=instance)
        if form.is_valid():
            o = form.save(commit=False)
            o.owner = request.user
            o.save()
            request.message_success(msg)

            return redirect(overview)

    else:
        form = ProductGroupForm(instance=instance)

    return render(request, "form.html", {
        'title': 'Produktgruppe',
        'form': form
    })
Ejemplo n.º 3
0
def form (request, id=False):
    if id:
        instance = get_object_or_404(ProductGroup, id=id, deleted=False)
        msg = "Velykket endret produktgruppen"
    else:
        instance = ProductGroup()
        msg = "Velykket lagt til ny produktgruppe"

    #Save and set to active, require valid form
    if request.method == 'POST':
        form = ProductGroupForm(request.POST, instance=instance)
        if form.is_valid():
            o = form.save(commit=False)
            o.owner = request.user
            o.save()
            request.message_success(msg)

            return redirect(overview)

    else:
        form = ProductGroupForm(instance=instance)

    return render(request, "form.html", {'title': 'Produktgruppe', 'form': form})
Ejemplo n.º 4
0
def add_ajax(request):
    form = ProductGroupForm(request.POST, instance=ProductGroup())

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

        return HttpResponse(simplejson.dumps({
            'name': a.name,
            'valid': True,
            'id': a.id
        }),
                            mimetype='application/json')

    else:
        errors = dict([(field, errors[0])
                       for field, errors in form.errors.items()])

        return HttpResponse(simplejson.dumps({
            'errors': errors,
            'valid': False
        }),
                            mimetype='application/json')

    return HttpResponse("ERROR")
Ejemplo n.º 5
0
 def simpleform():
     return ProductGroupForm(instance=ProductGroup(),
                             prefix="productgroups")