Commit 807d241f authored by Arthur Lutz's avatar Arthur Lutz
Browse files

cosmetic refactoring & optimisations

parent dcb2eebde49b
......@@ -25,7 +25,7 @@ class AwstatsAccessAction(action.Action):
category = 'manage'
def url(self):
return self._cw.build_url('?vid=awstats')
return self._cw.build_url('view', vid='awstats')
class WebStatsAccessAction(action.Action):
......@@ -36,5 +36,5 @@ class WebStatsAccessAction(action.Action):
category = 'manage'
def url(self):
return self._cw.build_url('?vid=webstats')
return self._cw.build_url('view', vid='webstats')
......@@ -63,7 +63,7 @@ class StatPeriodPrimaryView(primary.PrimaryView):
self.w(u'<a href="%s">Export CSV</a>' % self._cw.build_url('', rql=nolimit_rql % {'e':entity.eid},
vid='csvexport'))
#FIXME TODO not working right now
#self.wview('piechart', rset, 'null')
self.wview('piechart', rset, 'null')
self.w(u'</td>')
self.w(u'</tr></table>')
else:
......@@ -81,18 +81,18 @@ class StatPeriodIPrevNextAdapter(navigation.IPrevNextAdapter):
def previous_entity(self):
entity = self.entity
execute = self._cw.execute
rset = execute("StatPeriod S ORDERBY D WHERE S start D")
for index, item in enumerate(rset):
if item[0] == entity.eid and index >= 1:
return rset.get_entity(index-1, 0)
rset = execute("StatPeriod P ORDERBY S DESC LIMIT 1 WHERE P start S, P2 start S2, P2 eid %(e)s HAVING S < S2",
{'e':entity.eid})
if rset:
return rset.get_entity(0, 0)
def next_entity(self):
entity = self.entity
execute = self._cw.execute
rset = execute("StatPeriod S ORDERBY D WHERE S start D")
for index, item in enumerate(rset):
if item[0] == entity.eid and index + 1 < len(rset):
return rset.get_entity(index+1, 0)
rset = execute("StatPeriod P ORDERBY S LIMIT 1 WHERE P start S, P2 start S2, P2 eid %(e)s HAVING S > S2",
{'e':entity.eid})
if rset:
return rset.get_entity(0, 0)
class StatGraph(EntityView):
......
......@@ -51,8 +51,7 @@ def extract_available_time_periods(form, **attrs):
if match:
periods.append((specific_format('time_period', match.group(1)),
match.group(1)))
periods.sort()
return periods
return sorted(periods)
def extract_available_domains(form, **attrs):
""" extract available domains from list of awstats files """
......@@ -62,8 +61,7 @@ def extract_available_domains(form, **attrs):
match = re.search('awstats(\d{2})(\d{4})\.?(.*).txt', filename)
if match and match.group(3) not in domains:
domains.append(match.group(3))
domains.sort()
return domains
return sorted(domains)
def use_as_sort_key(value):
""" use value as sort value, try it as an int, else just use value """
......@@ -189,8 +187,7 @@ class AwstatsView(StartupView):
self.w(u'<th scope="col">%s</th>' % xml_escape(header))
self.w(u'</tr><tbody>')
ordered_values = self.order_values(section_name, stats_dict)
for index, item in enumerate([item[1] for item in ordered_values]):
for index, item in enumerate(self.order_values(section_name, stats_dict)):
self.w(u'<tr>')
for tdindex, header in enumerate(SECTIONSPEC[section_name]):
if tdindex:
......@@ -216,10 +213,7 @@ class AwstatsView(StartupView):
else:
order_key = SECTIONSPEC[section_name][1]
reverse = True
ordered_values = [(int(item[order_key]), item)
for item in stats_dict[section_name].values()]
ordered_values.sort(reverse=reverse)
return ordered_values
return sorted(stats_dict[section_name].values(), reverse=reverse, key=lambda i: int(i[order_key]))
class WebStatsRefreshForm(forms.FieldsForm):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment