client-barcode: Move from product ids to product barcodes

This commit is contained in:
Sebastian Pipping 2011-10-05 21:50:14 +02:00
parent dd224f42f6
commit 83ac56d9e4
2 changed files with 8 additions and 11 deletions

View File

@ -132,12 +132,12 @@ class Status:
# Logout # Logout
self._reset() self._reset()
def find(self, item_id): def find(self, barcode):
try: try:
return self.item_cache[item_id] return self.item_cache[barcode]
except KeyError: except KeyError:
item = net.get_item(item_id) item = net.get_item(barcode)
self.item_cache[item_id] = item self.item_cache[barcode] = item
return item return item
def buy(self, item): def buy(self, item):
@ -178,9 +178,8 @@ def handle(line, status):
params = call[1:] params = call[1:]
getattr(status, method)(*params) getattr(status, method)(*params)
else: else:
item_id = int(line) # TODO
try: try:
item = status.find(item_id) item = status.find(line)
except urllib2.HTTPError as e: except urllib2.HTTPError as e:
if e.code == 404: # URL not found == item not found with REST if e.code == 404: # URL not found == item not found with REST
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line) error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)

View File

@ -60,11 +60,9 @@ def buy_item(item_id, user_name):
raise ValueError('Server says "%s"' % content) raise ValueError('Server says "%s"' % content)
def get_item(item_id): def get_item(barcode):
require_type(int, item_id) content = _request('buyable/item/',
{'barcode':barcode}, method='GET')
content = _request('buyable/item/' + urllib.quote(str(item_id)),
{}, method='GET')
d = json.loads(content) d = json.loads(content)
return Item(d) return Item(d)