API

Plug-ins

Criterion

class lfs.criteria.models.Criterion

Base class for all criteria.

Attributes:

cart
The current cart of the current customer.
content
The content object the criterion belongs to.
operator
The current selected operator for the criterion.
position
The position of the criterion within a list of criteria of the content object.
product
The product, if the criterion is called from a product detail view. Otherwise this is None.
request
The current request.

Constants:

EQUAL, LESS_THAN, LESS_THAN_EQUAL, GREATER_THAN, GREATER_THAN_EQUAL, IS_SELECTED, IS_NOT_SELECTED, IS_VALID, IS_NOT_VALID, CONTAINS
Integers which represents certain operators.
INPUT, SELECT, MULTIPLE_SELECT
Constants which represents the types of selectable values. One of these must be returned from get_value_type.
NUMBER_OPERATORS

A list of operators which can be returned from get_operators.

[
    [EQUAL, _(u"Equal to")],
    [LESS_THAN, _(u"Less than")],
    [LESS_THAN_EQUAL, _(u"Less than equal to")],
    [GREATER_THAN, _(u"Greater than")],
    [GREATER_THAN_EQUAL, _(u"Greater than equal to")],
]
SELECTION_OPERATORS

A list of operators which can be returned from get_operators.

[
    [IS_SELECTED, _(u"Is selected")],
    [IS_NOT_SELECTED, _(u"Is not selected")],
]
VALID_OPERATORS

A list of operators which can be returned from get_operators.

[
    [IS_VALID, _(u"Is valid")],
    [IS_NOT_VALID, _(u"Is not valid")],
]
STRING_OPERATORS

A list of operators which can be return from get_operators.

[
    [EQUAL, _(u"Equal to")],
    [CONTAINS, _(u"Contains")],
]
get_operators()

Returns the selectable operators of the criterion which are displayed to the shop manager. This is a list of list, whereas the the first value is integer, which is stored within the criterion and the second value is the string which is displayed to the shop manager, e.g.:

[
    [0, _(u"Equal to")],
    [1, _(u"Less than")],
    [2, _(u"Less than equal to")],
    [3, _(u"Greater than")],
    [4, _(u"Greater than equal to")],
]

Note

You can use one of the provided class attributes, see above.

  • NUMBER_OPERATORS
  • SELECTION_OPERATORS
  • VALID_OPERATORS
  • STRING_OPERATORS
get_selectable_values(request)

Returns the selectable values as a list of dictionary, see below. This is only called when get_value_type returns SELECT or MULTIPLE_SELECT.

[
    {
        "id": 0,
        "name": "Name 0",
        "selected": False,
    },
    {
        "id": 1,
        "name": "Name 1",
        "selected": True,
    },
]
get_template(request)

Returns the template to render the criterion.

get_value_type()

Returns the type of the selectable values field. Must return one of:

  • self.INPUT
  • self.SELECT
  • self.MULTIPLE_SELECT
get_value()

Returns the current value of the criterion.

is_valid(request, product=None)

Returns True if the criterion is valid otherwise False.

render(request, position)

Renders the criterion as html in order to displayed it within the management form.

update(value)

Updates the value of the criterion.

Parameters:

value
The value the shop user has entered for the criterion.

OrderNumberGenerator

PaymentMethodProcessor

PriceCalculator

ShippingMethodPriceCalculator

Table Of Contents

Previous topic

Contributing translations

Next topic

Settings

This Page