From 87f8b74ab19d3061236983ac6265830511b35d94 Mon Sep 17 00:00:00 2001 From: Florent Date: Fri, 1 Feb 2013 10:40:08 +0100 Subject: [PATCH] Fix crash when no data available --- modules/nettokom/pages/history.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/nettokom/pages/history.py b/modules/nettokom/pages/history.py index d00a29de..aaf759e2 100644 --- a/modules/nettokom/pages/history.py +++ b/modules/nettokom/pages/history.py @@ -32,21 +32,22 @@ class DetailsPage(BasePage): def on_loaded(self): self.details = [] - table = self.document.xpath('//table[@id="reportTable"]')[0] + table = self.document.xpath('//table[@id="reportTable"]') - for tr in table.xpath('tbody/tr'): - detail = Detail() - # Skip global category - if tr.find('td/a') is not None: - continue - if tr.attrib["class"] == "totalAmount": - continue - tds = tr.xpath('td') - detail.label = unicode(tds[0].text.strip()) - detail.infos = unicode(tds[1].text.strip()) - detail.price = Decimal(tds[2].text.split(' ')[0].replace(',', '.')) + if len(table) > 0: + for tr in table[0].xpath('tbody/tr'): + detail = Detail() + # Skip global category + if tr.find('td/a') is not None: + continue + if tr.attrib["class"] == "totalAmount": + continue + tds = tr.xpath('td') + detail.label = unicode(tds[0].text.strip()) + detail.infos = unicode(tds[1].text.strip()) + detail.price = Decimal(tds[2].text.split(' ')[0].replace(',', '.')) - self.details.append(detail) + self.details.append(detail) def get_details(self): return self.details