django_program.registration.services.capacity

Global ticket capacity enforcement for conferences.

Provides functions to count, check, and validate total ticket sales against a conference-level capacity limit. Add-ons are excluded from the global count because they do not consume venue seats.

Functions

get_global_remaining(conference)

Return the number of tickets still available under the global cap.

get_global_sold_count(conference)

Return the total number of tickets sold across all ticket types.

validate_global_capacity(conference, ...)

Raise ValidationError if desired_total would exceed global capacity.

django_program.registration.services.capacity.get_global_sold_count(conference)[source]

Return the total number of tickets sold across all ticket types.

Counts OrderLineItem quantities for ticket-type items (not add-ons) in orders that are PAID, PARTIALLY_REFUNDED, or PENDING with an active inventory hold.

Uses addon__isnull=True rather than ticket_type__isnull=False so that line items whose ticket type was deleted (SET_NULL) are still counted toward the sold total, preventing oversells.

Parameters:

conference (object) – The conference to count sales for.

Return type:

int

Returns:

The total number of tickets sold.

django_program.registration.services.capacity.get_global_remaining(conference)[source]

Return the number of tickets still available under the global cap.

Parameters:

conference (object) – The conference to check capacity for.

Return type:

int | None

Returns:

The remaining ticket count, or None if the conference has no global capacity limit (total_capacity == 0).

django_program.registration.services.capacity.validate_global_capacity(conference, desired_total)[source]

Raise ValidationError if desired_total would exceed global capacity.

Acquires a row-level lock on the conference via select_for_update() to prevent race conditions when multiple concurrent requests validate capacity at the same time. The caller must already be inside a transaction.atomic block.

The early-return check for unlimited conferences happens after the lock is acquired so that a stale in-memory instance cannot bypass enforcement.

Parameters:
  • conference (object) – The conference to validate against.

  • desired_total (int) – The total number of ticket items in the cart (across all ticket types, excluding add-ons).

Raises:

ValidationError – If the desired total exceeds the conference’s total_capacity.

Return type:

None