From 83ac56d9e457aaa108fe8fbabd0ee7c52309e198 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 5 Oct 2011 21:50:14 +0200 Subject: [PATCH] client-barcode: Move from product ids to product barcodes --- client-barcode/freitagskasse.py | 11 +++++------ client-barcode/freitagslib/network.py | 8 +++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1da2f05..60bd45c 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -132,12 +132,12 @@ class Status: # Logout self._reset() - def find(self, item_id): + def find(self, barcode): try: - return self.item_cache[item_id] + return self.item_cache[barcode] except KeyError: - item = net.get_item(item_id) - self.item_cache[item_id] = item + item = net.get_item(barcode) + self.item_cache[barcode] = item return item def buy(self, item): @@ -178,9 +178,8 @@ def handle(line, status): params = call[1:] getattr(status, method)(*params) else: - item_id = int(line) # TODO try: - item = status.find(item_id) + item = status.find(line) except urllib2.HTTPError as e: if e.code == 404: # URL not found == item not found with REST error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line) diff --git a/client-barcode/freitagslib/network.py b/client-barcode/freitagslib/network.py index ec7f60c..60d4109 100644 --- a/client-barcode/freitagslib/network.py +++ b/client-barcode/freitagslib/network.py @@ -60,11 +60,9 @@ def buy_item(item_id, user_name): raise ValueError('Server says "%s"' % content) -def get_item(item_id): - require_type(int, item_id) - - content = _request('buyable/item/' + urllib.quote(str(item_id)), - {}, method='GET') +def get_item(barcode): + content = _request('buyable/item/', + {'barcode':barcode}, method='GET') d = json.loads(content) return Item(d)