kitty.model.low_level.condition module

conditon object has one mandatory function - applies, which receives a Container as the single argument.

Conditions are used by the If and IfNot fields to decide wether to render their content or not. In many cases the decision is made based on a value of a specific field, but you can create whatever condition you want. In future versions, they will probably be used to make other decisions, not only basic rendering decisions.

class kitty.model.low_level.condition.Compare(field, comp_type, comp_value)[source]

Bases: kitty.model.low_level.condition.FieldCondition

Condition applies if the comparison between the value of the field and the comp_value evaluates to True

Note

There are some functions for creating specific Compare conditions that you can see below.

__init__(field, comp_type, comp_value)[source]
Parameters:
  • field – (name of) field that should meet the condition
  • comp_type – how to compare the values. One of (‘>’, ‘<’, ‘>=’, ‘<=’, ‘==’, ‘!=’)
  • comp_value – value to compare the field to
Example:

Render the content of the If container only if the value in the field called “name” is not ‘kitty’

Template([
    String('kitty', name='name'),
    If(Compare('name', '!=', 'kitty'), [
        String('current name is not kitty')
    ])
])
hash()[source]
Return type:int
Returns:hash of the condition
class kitty.model.low_level.condition.Condition[source]

Bases: object

applies(container, ctx)[source]

All subclasses must implement the applies(self, container) method

Parameters:
  • container (Container) – the caller
  • ctx – rendering context in which applies was called
Returns:

True if condition applies, False otherwise

copy()[source]
Returns:a copy of the condition
hash()[source]
Return type:int
Returns:hash of the condition
invalidate(container)[source]
Parameters:container – the container that tries to invalidate the condition
class kitty.model.low_level.condition.FieldCondition(field)[source]

Bases: kitty.model.low_level.condition.Condition

Base class for field-based conditions (if field meets condition return true)

__init__(field)[source]
Parameters:field (BaseField or str) – (name of, or) field that should meet the condition
applies(container, ctx)[source]

Subclasses should not override applies, but instead they should override _applies, which has the same syntax as applies. In the _applies method the condition is guaranteed to have a reference to the desired field, as self._field.

Parameters:
  • container (Container) – the caller
  • ctx – rendering context in which applies was called
Returns:

True if condition applies, False otherwise

hash()[source]
invalidate(container)[source]
Parameters:container – the container that tries to invalidate the condition
class kitty.model.low_level.condition.FieldMutating(field)[source]

Bases: kitty.model.low_level.condition.FieldCondition

Condition applies if the field is currently mutating

Example:

Render the content of the If container only if ‘kittyfield’ is currently mutating.

Template([
    String('kitty', name='kittyfield'),
    String('fritty', name='frittyfield'),
    If(FieldMutating('kittyfield'), [
        String('kitty is now mutating')
    ])
])
class kitty.model.low_level.condition.InList(field, value_list)[source]

Bases: kitty.model.low_level.condition.ListCondition

Condition applies if the value of the field appears in the value list

Example:

Render the content of the If container only if the current rendered value of the ‘numbers’ field is ‘1’, ‘5’ or ‘7’.

Template([
    Group(['1', '2', '3'], name='numbers'),
    If(InList('numbers', ['1', '5', '7']), [
        String('123')
    ])
])
class kitty.model.low_level.condition.ListCondition(field, value_list)[source]

Bases: kitty.model.low_level.condition.FieldCondition

Base class for comparison between field and list. can’t be instantiated

__init__(field, value_list)[source]
Parameters:
  • field – (name of) field that should meet the condition
  • value_list – list of values that should be compared to the field
hash()[source]