Example #1
0
def manage_property(request, id, template_name="manage/properties/property.html"):
    """The main view to manage the property with passed id.
    """
    prop = get_object_or_404(Property, pk=id)
    if request.method == "POST":
        form = PropertyDataForm(instance=prop, data=request.POST)
        if form.is_valid():
            form.save()
            _update_property_positions()
            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_shop_property", kwargs={"id": prop.id}),
                msg=_(u"Property type has been saved."),
            )

    else:
        form = PropertyDataForm(instance=prop)

    display_step_form = prop.is_number_field and prop.filterable

    # return render_to_response(template_name, RequestContext(request, {
    #     "property": prop,
    #     "properties": Property.objects.filter(local=False),
    #     "form": form,
    #     "type_form": PropertyTypeForm(instance=prop),
    #     "current_id": int(id),
    #     "options": options_inline(request, id),
    #     "steps": steps_inline(request, id),
    #     "number_field": number_field(request, prop),
    #     "select_field": select_field(request, prop),
    #     "display_step_form": display_step_form,
    #   }))

    properties = _get_filtered_properties_for_property_view(request)
    paginator = Paginator(properties, 25)
    page = get_current_page(request, properties, prop, 25)

    try:
        page = paginator.page(page)
    except EmptyPage:
        page = paginator.page(1)

    return render_to_response(template_name, RequestContext(request, {
        "property": prop,
        "form": form,
        "type_form": PropertyTypeForm(instance=prop),
        "current_id": int(id),
        "options": options_inline(request, id),
        "steps": steps_inline(request, id),
        "number_field": number_field(request, prop),
        "select_field": select_field(request, prop),
        "display_step_form": display_step_form,

        "selectable_properties": selectable_properties_inline(request, page, paginator, id),
        # pagination data:
        "properties": properties,
        "pages_inline": pages_inline(request, page, paginator, id),
        "name_filter_value": request.session.get("property_filters", {}).get("property_name", ""),
    }))
Example #2
0
def update_property_type(request, id):
    """Updates the type of the property.

    This is separated from the data, because a change of type causes a deletion
    of product property values
    """
    property = get_object_or_404(Property, pk=id)
    old_type = property.type
    form = PropertyTypeForm(instance=property, data=request.POST)
    new_property = form.save()

    # Send signal only when the type changed as all values are deleted.
    if old_type != new_property.type:
        property_type_changed.send(property)

    return lfs.core.utils.set_message_cookie(
        url=reverse("lfs_manage_shop_property", kwargs={"id": property.id}),
        msg=_(u"Property type has been changed."),
    )
Example #3
0
def update_property_type(request, id):
    """Updates the type of the property.

    This is separated from the data, because a change of type causes a deletion
    of product property values
    """
    property = get_object_or_404(Property, pk=id)
    old_type = property.type
    form = PropertyTypeForm(instance=property, data=request.POST)
    new_property = form.save()

    # Send signal only when the type changed as all values are deleted.
    if old_type != new_property.type:
        property_type_changed.send(property)

    return lfs.core.utils.set_message_cookie(
        url=reverse("lfs_manage_shop_property", kwargs={"id": property.id}),
        msg=_(u"Property type has been changed."),
    )
Example #4
0
def manage_property(request,
                    id,
                    template_name="manage/properties/property.html"):
    """The main view to manage the property with passed id.
    """
    property = get_object_or_404(Property, pk=id)
    if request.method == "POST":
        form = PropertyDataForm(instance=property, data=request.POST)
        if form.is_valid():
            form.save()
            _update_property_positions()
            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_shop_property",
                            kwargs={"id": property.id}),
                msg=_(u"Property type has been saved."),
            )

    else:
        form = PropertyDataForm(instance=property)

    display_step_form = property.is_number_field and property.filterable

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "property": property,
                "properties": Property.objects.filter(local=False),
                "form": form,
                "type_form": PropertyTypeForm(instance=property),
                "current_id": int(id),
                "options": options_inline(request, id),
                "steps": steps_inline(request, id),
                "number_field": number_field(request, property),
                "select_field": select_field(request, property),
                "display_step_form": display_step_form,
            }))