django_program.registration.services.conditions

Condition evaluator service for the discount and condition engine.

Orchestrates evaluation of all active conditions for a user/cart context and returns applicable discounts as structured data for cart pricing integration.

All condition types are merged into a single priority-sorted list before evaluation so that priority ordering is respected globally across types.

Functions

commit_condition_usage(discounts)

Increment times_used for all stock-limited conditions that were applied.

evaluate_for_cart(cart)

Evaluate all conditions for a cart.

evaluate_for_items(items, user, conference)

Evaluate all conditions against a list of cart items (side-effect free).

get_eligible_discounts(user, conference)

Return all conditions the user currently qualifies for.

get_visible_products(user, conference)

Return ticket types and add-ons visible to this user.

Classes

CartItemDiscount

A discount applied to a single cart item by a condition.

class django_program.registration.services.conditions.CartItemDiscount[source]

Bases: object

A discount applied to a single cart item by a condition.

Parameters:
  • cart_item_id (int)

  • condition_name (str)

  • condition_type (str)

  • discount_amount (Decimal)

  • original_price (Decimal)

  • condition_pk (int)

  • condition_model (str)

cart_item_id: int
condition_name: str
condition_type: str
discount_amount: Decimal
original_price: Decimal
condition_pk: int = 0
condition_model: str = ''
__init__(cart_item_id, condition_name, condition_type, discount_amount, original_price, condition_pk=0, condition_model='')
Parameters:
  • cart_item_id (int)

  • condition_name (str)

  • condition_type (str)

  • discount_amount (Decimal)

  • original_price (Decimal)

  • condition_pk (int)

  • condition_model (str)

django_program.registration.services.conditions.evaluate_for_items(items, user, conference)[source]

Evaluate all conditions against a list of cart items (side-effect free).

Gathers all active conditions into a single priority-sorted list, evaluates each against the user, and applies the first matching discount per item (no stacking). Does NOT mutate the database; call commit_condition_usage() at checkout to persist usage.

Parameters:
  • items (list[CartItem]) – Pre-fetched cart items to evaluate against.

  • user (object) – The cart owner.

  • conference (object) – The conference context.

Return type:

list[CartItemDiscount]

Returns:

A list of CartItemDiscount entries, one per discounted cart item.

django_program.registration.services.conditions.evaluate_for_cart(cart)[source]

Evaluate all conditions for a cart.

Convenience wrapper around evaluate_for_items that fetches the cart’s items with related data.

Parameters:

cart (Cart) – The cart to evaluate conditions for.

Return type:

list[CartItemDiscount]

Returns:

A list of CartItemDiscount entries, one per discounted cart item.

django_program.registration.services.conditions.commit_condition_usage(discounts)[source]

Increment times_used for all stock-limited conditions that were applied.

Call this at checkout time (not during cart summary viewing) to persist usage counts. Evaluation is side-effect free; this is the commit step.

Groups discounts by condition and increments times_used by the number of items each condition discounted. Uses a conditional UPDATE that only increments when limit=0 OR times_used + count <= limit to prevent overshooting the cap under concurrency.

Parameters:

discounts (list[CartItemDiscount]) – The discount results from evaluate_for_items.

Return type:

None

django_program.registration.services.conditions.get_eligible_discounts(user, conference)[source]

Return all conditions the user currently qualifies for.

Parameters:
  • user (object) – The authenticated user.

  • conference (object) – The conference to check conditions for.

Return type:

list[ConditionBase]

Returns:

A list of condition instances the user qualifies for.

django_program.registration.services.conditions.get_visible_products(user, conference)[source]

Return ticket types and add-ons visible to this user.

Currently returns all active products for the conference. Future work can add flag-based visibility gating here.

Parameters:
  • user (object) – The authenticated user.

  • conference (object) – The conference to retrieve products for.

Return type:

tuple[QuerySet, QuerySet]

Returns:

A tuple of (ticket_types_queryset, addons_queryset).