Exemplo n.º 1
0
def update_data(request, manufacturer_id):
    """Updates data of manufacturer with given manufacturer id.
    """
    manufacturer = Manufacturer.objects.get(pk=manufacturer_id)
    form = ManufacturerDataForm(instance=manufacturer, data=request.POST,
                                files=request.FILES)

    if form.is_valid():
        manufacturer = form.save()
        msg = _(u"Manufacturer data has been saved.")
    else:
        msg = _(u"Please correct the indicated errors.")

    # Delete image
    if request.POST.get("delete_image"):
        try:
            manufacturer.image.delete()
        except OSError as e:
            logger.error('Error while trying to delete manufacturer image: %s' % e)

    html = (
        ("#data", manufacturer_data_inline(request, manufacturer.pk)),
        ("#selectable-manufacturers", selectable_manufacturers_inline(request, manufacturer_id)),
    )

    result = json.dumps({
        "html": html,
        "message": msg
    }, cls=LazyEncoder)

    return HttpResponse(result, mimetype='application/json')
Exemplo n.º 2
0
def update_data(request, manufacturer_id):
    """Updates data of manufacturer with given manufacturer id.
    """
    manufacturer = Manufacturer.objects.get(pk=manufacturer_id)
    form = ManufacturerDataForm(instance=manufacturer,
                                data=request.POST,
                                files=request.FILES)

    if form.is_valid():
        manufacturer = form.save()
        msg = _(u"Manufacturer data has been saved.")
    else:
        msg = _(u"Please correct the indicated errors.")

    # Delete image
    if request.POST.get("delete_image"):
        try:
            manufacturer.image.delete()
        except OSError as e:
            logger.error(
                'Error while trying to delete manufacturer image: %s' % e)

    html = (
        ("#data", manufacturer_data_inline(request, manufacturer.pk)),
        ("#selectable-manufacturers",
         selectable_manufacturers_inline(request, manufacturer_id)),
    )

    result = json.dumps({"html": html, "message": msg}, cls=LazyEncoder)

    return HttpResponse(result, content_type='application/json')
Exemplo n.º 3
0
def add_manufacturer(request,
                     template_name="manage/manufacturers/add_manufacturer.html"
                     ):
    """Form and logic to add a manufacturer.
    """
    if request.method == "POST":
        form = ManufacturerDataForm(data=request.POST)
        if form.is_valid():
            new_manufacturer = form.save()
            return HttpResponseRedirect(
                reverse("lfs_manufacturer",
                        kwargs={"manufacturer_id": new_manufacturer.id}))

    else:
        form = ManufacturerDataForm()

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "form":
                form,
                "selectable_manufacturers_inline":
                selectable_manufacturers_inline(request, 0),
                "came_from":
                request.REQUEST.get("came_from",
                                    reverse("lfs_manufacturer_dispatcher")),
            }))
Exemplo n.º 4
0
def add_manufacturer(request, template_name="manage/manufacturers/add_manufacturer.html"):
    """Form and logic to add a manufacturer.
    """
    if request.method == "POST":
        form = ManufacturerDataForm(data=request.POST)
        if form.is_valid():
            new_manufacturer = form.save()
            return HttpResponseRedirect(
                reverse("lfs_manufacturer", kwargs={"manufacturer_id": new_manufacturer.id}))

    else:
        form = ManufacturerDataForm()

    return render_to_response(template_name, RequestContext(request, {
        "form": form,
        "selectable_manufacturers_inline": selectable_manufacturers_inline(request, 0),
        "came_from": request.REQUEST.get("came_from", reverse("lfs_manufacturer_dispatcher")),
    }))
Exemplo n.º 5
0
def update_data(request, manufacturer_id):
    """Updates data of manufacturer with given manufacturer id.
    """
    manufacturer = Manufacturer.objects.get(pk=manufacturer_id)
    form = ManufacturerDataForm(instance=manufacturer, data=request.POST)

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

    msg = _(u"Manufacturer data has been saved.")

    html = (
        ("#data", manufacturer_data_inline(request, manufacturer_id, form)),
        ("#selectable-manufacturers",
         selectable_manufacturers_inline(request, manufacturer_id)),
    )

    result = simplejson.dumps({"html": html, "message": msg}, cls=LazyEncoder)

    return HttpResponse(result)
Exemplo n.º 6
0
def update_data(request, manufacturer_id):
    """Updates data of manufacturer with given manufacturer id.
    """
    manufacturer = Manufacturer.objects.get(pk=manufacturer_id)
    form = ManufacturerDataForm(instance=manufacturer, data=request.POST)

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

    msg = _(u"Manufacturer data has been saved.")

    html = (
        ("#data", manufacturer_data_inline(request, manufacturer_id, form)),
        ("#selectable-manufacturers", selectable_manufacturers_inline(request, manufacturer_id)),
    )

    result = simplejson.dumps({
        "html": html,
        "message": msg
    }, cls=LazyEncoder)

    return HttpResponse(result)