minor fixes
This commit is contained in:
@@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from pypretix_device.models import CheckinList, CheckinResult, DeviceInfo, Event, SearchResult
|
from pypretix_device.models import CheckinList, CheckinResult, DeviceInfo, Event, Item, SearchResult
|
||||||
|
|
||||||
# API endpoint bases
|
# API endpoint bases
|
||||||
_CHECKINRPC_REDEEM = "checkinrpc/redeem/"
|
_CHECKINRPC_REDEEM = "checkinrpc/redeem/"
|
||||||
@@ -134,7 +134,7 @@ class PretixDeviceClient:
|
|||||||
"source_type": "barcode",
|
"source_type": "barcode",
|
||||||
"lists": checkin_list_id,
|
"lists": checkin_list_id,
|
||||||
"type": "entry",
|
"type": "entry",
|
||||||
"force": True,
|
"force": False,
|
||||||
"ignore_unpaid": False,
|
"ignore_unpaid": False,
|
||||||
"questions_supported": False,
|
"questions_supported": False,
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ class PretixDeviceClient:
|
|||||||
"source_type": "barcode",
|
"source_type": "barcode",
|
||||||
"lists": checkin_list_id,
|
"lists": checkin_list_id,
|
||||||
"type": "exit",
|
"type": "exit",
|
||||||
"force": True,
|
"force": False,
|
||||||
"ignore_unpaid": False,
|
"ignore_unpaid": False,
|
||||||
"questions_supported": False,
|
"questions_supported": False,
|
||||||
}
|
}
|
||||||
@@ -357,6 +357,46 @@ class PretixDeviceClient:
|
|||||||
logger.error(f"Failed to list check-in lists: {e}")
|
logger.error(f"Failed to list check-in lists: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def list_items(self, event_slug: Optional[str] = None) -> List[Item]:
|
||||||
|
"""List products/items for the current (or specified) event.
|
||||||
|
|
||||||
|
Check-in responses (``checkinrpc/redeem``, ``checkinrpc/search``) only
|
||||||
|
include the numeric item ID on the position, not its name — use this
|
||||||
|
to resolve IDs to display names.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
event_slug: Event slug to fetch items for. Uses client default if not provided.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of Item objects.
|
||||||
|
"""
|
||||||
|
event = event_slug or self.event_slug
|
||||||
|
endpoint = f"events/{event}/items/"
|
||||||
|
try:
|
||||||
|
resp = self._request("GET", self._api_url(endpoint))
|
||||||
|
if resp is None:
|
||||||
|
logger.error("Failed to list items")
|
||||||
|
return []
|
||||||
|
|
||||||
|
data = resp.json()
|
||||||
|
result = []
|
||||||
|
for item in data.get("results", []):
|
||||||
|
name_raw = item.get("name", "")
|
||||||
|
if isinstance(name_raw, dict):
|
||||||
|
name = name_raw.get("de") or name_raw.get("en") or "Unnamed"
|
||||||
|
else:
|
||||||
|
name = str(name_raw)
|
||||||
|
result.append(Item(
|
||||||
|
id=item["id"],
|
||||||
|
name=name,
|
||||||
|
internal_name=item.get("internal_name"),
|
||||||
|
))
|
||||||
|
return result
|
||||||
|
|
||||||
|
except (requests.exceptions.RequestException, ValueError, KeyError) as e:
|
||||||
|
logger.error(f"Failed to list items: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
def select_event(self, event_slug: str) -> bool:
|
def select_event(self, event_slug: str) -> bool:
|
||||||
"""Switch the client to use a different event.
|
"""Switch the client to use a different event.
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ class Event:
|
|||||||
date_to: Optional[str] = None
|
date_to: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Item:
|
||||||
|
"""A product/item within an event."""
|
||||||
|
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
internal_name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CheckinList:
|
class CheckinList:
|
||||||
"""A check-in list within an event."""
|
"""A check-in list within an event."""
|
||||||
|
|||||||
Reference in New Issue
Block a user