MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / numbers_in_range

Method numbers_in_range

apps/channels/api_views.py:1703–1778  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

1701 )
1702 @action(detail=False, methods=["get"], url_path="numbers-in-range")
1703 def numbers_in_range(self, request, *args, **kwargs):
1704 from .managers import with_effective_values
1705
1706 raw_start = request.query_params.get("start")
1707 raw_end = request.query_params.get("end")
1708 if raw_start is None or raw_start == "":
1709 return Response({"occupants": []})
1710 try:
1711 start = float(raw_start)
1712 except (TypeError, ValueError):
1713 return Response(
1714 {"detail": "Invalid start value"},
1715 status=status.HTTP_400_BAD_REQUEST,
1716 )
1717 try:
1718 end = float(raw_end) if raw_end not in (None, "") else start
1719 except (TypeError, ValueError):
1720 return Response(
1721 {"detail": "Invalid end value"},
1722 status=status.HTTP_400_BAD_REQUEST,
1723 )
1724 if end < start:
1725 start, end = end, start
1726
1727 queryset = (
1728 with_effective_values(
1729 Channel.objects.all(), select_related_fks=True
1730 )
1731 .filter(
1732 effective_channel_number__gte=start,
1733 effective_channel_number__lte=end,
1734 )
1735 .order_by("effective_channel_number")[:50]
1736 )
1737
1738 occupants = []
1739 for occupant in queryset:
1740 effective_group = getattr(
1741 occupant, "effective_channel_group_obj", None
1742 )
1743 group_name = (
1744 getattr(effective_group, "name", None)
1745 if effective_group is not None
1746 else None
1747 )
1748 effective_group_id = getattr(
1749 occupant, "effective_channel_group_id", None
1750 )
1751 override = getattr(occupant, "override", None)
1752 override_sets_number = bool(
1753 override is not None and override.channel_number is not None
1754 )
1755 occupants.append(
1756 {
1757 "id": occupant.id,
1758 "name": getattr(
1759 occupant, "effective_name", occupant.name
1760 ),

Callers

nothing calls this directly

Calls 3

with_effective_valuesFunction · 0.85
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected