Add try/catch in browsers display plugin in case of an icon doesn't exists)

This commit is contained in:
Gregory Soutade 2015-01-11 18:06:18 +01:00
parent 588b3179d5
commit 00ad08a201

View File

@ -82,12 +82,15 @@ class IWLADisplayBrowsers(IPlugin):
new_list = self.max_browsers and browsers[:self.max_browsers] or browsers
for (browser, entrance) in new_list:
if browser != 'unknown':
icon = '<img src="/%s/browser/%s.png"/>' % (self.icon_path, awstats_data.browsers_icons[self.icon_names[browser]])
try:
icon = '<img src="/%s/browser/%s.png"/>' % (self.icon_path, awstats_data.browsers_icons[self.icon_names[browser]])
except:
icon = '<img src="/%s/browser/unknown.png"/>' % (self.icon_path)
else:
icon = '<img src="/%s/browser/unknown.png"/>' % (self.icon_path)
browser = 'Unknown'
table.appendRow([icon, browser, entrance])
total_browsers[1] += entrance
total_browsers[2] += entrance
if self.max_browsers:
others = 0
for (browser, entrance) in browsers[self.max_browsers:]:
@ -111,14 +114,18 @@ class IWLADisplayBrowsers(IPlugin):
table.setColsCSSClass(['', '', 'iwla_hit'])
for (browser, entrance) in browsers[:10]:
if browser != 'unknown':
icon = '<img src="/%s/browser/%s.png"/>' % (self.icon_path, awstats_data.browsers_icons[self.icon_names[browser]])
try:
icon = '<img src="/%s/browser/%s.png"/>' % (self.icon_path, awstats_data.browsers_icons[self.icon_names[browser]])
except:
icon = '<img src="/%s/browser/unknown.png"/>' % (self.icon_path)
else:
icon = '<img src="/%s/browser/unknown.png"/>' % (self.icon_path)
browser = 'Unknown'
table.appendRow([icon, browser, entrance])
total_browsers[1] -= entrance
if total_browsers[1]:
total_browsers[0] = self.iwla._(u'Others')
total_browsers[2] -= entrance
if total_browsers[2]:
total_browsers[0] = u''
total_browsers[1] = self.iwla._(u'Others')
table.appendRow(total_browsers)
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
index.appendBlock(table)