Commit 208abc30 authored by Arthur Lutz's avatar Arthur Lutz
Browse files

Primary view improvements

parent bd562ed5be0d
......@@ -36,12 +36,13 @@ class StatPeriodPrimaryView(primary.PrimaryView):
def cell_call(self, row, col):
_ = self._cw._
req = self._cw
self.w(u'<div id="statperiod">')
self.w(u'<div id="primarystatperiod">')
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s - %s</h1>' % (_('Statistics for period :'),
entity.printable_value('start'),
entity.printable_value('stop')) )
# TODO - display length
self.w(u'<h1>%s %s - %s (%s %s)</h1>' % (_('Statistics for period :'),
entity.printable_value('start'),
entity.printable_value('stop'),
(entity.stop - entity.start).days,
_('days')) )
rset = self._cw.execute('DISTINCT Any C WHERE X is Hits, X hit_type C')
self.w(u'<a href="%s">%s</a>' % (entity.absolute_url(showall=1),
_('show all results')))
......@@ -58,10 +59,11 @@ class StatPeriodPrimaryView(primary.PrimaryView):
rset = self._cw.execute(typedrql, {'e':entity.eid})
self.wview('table', rset, 'null')
# cf rql/editextensions.py unset_limit
#refactor below
nolimit_rql = typedrql.replace('LIMIT 20', '')
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.w(u'</td>')
self.w(u'</tr></table>')
else:
......@@ -98,27 +100,18 @@ class StatGraph(EntityView):
# select only instances with stats_about relation
def cell_call(self, row, col):
_ = self._cw._
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s</h1>' % (_('Graph of hits for'),
entity.dc_title()))
self.w(u'<div id="webstats">')
rql = ('DISTINCT Any S, HITS ORDERBY S WITH S, HITS BEING ('
'(Any START, HITS WHERE H count HITS, H period P, P start START, P stop STOP, H stats_about E, E eid %%(e)s %s)'
'(Any START, HITS WHERE H count HITS, H hit_type "normal", H period P, P start START, P stop STOP, H stats_about E, E eid %%(e)s %s)'
' UNION '
'(Any START, 0 WHERE P is StatPeriod, P start START, P stop STOP, NOT EXISTS(H period P, H stats_about E, E eid %%(e)s) %s))')
for constraint in (' HAVING STOP-START <= 20',
' HAVING STOP-START >= 20'):
for constraint, label in ((' HAVING STOP-START <= 20', _('Daily')),
(' HAVING STOP-START >= 20', _('Monthly'))):
self.w(u'<h2>%s</h2>' % label)
rset = self._cw.execute(rql % (constraint, constraint), {'e':entity.eid})
self.w(self._cw.view('plot', rset, 'null'))
class StatPeriodChart(EntityView):
__regid__ = 'periodchart'
__select__ = is_instance('StatPeriod')
def cell_call(self, row, col):
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s</h1>' % (_('Piechart of hits for'),
entity.dc_title()))
rql = 'Any X, C ORDERBY C DESC LIMIT 20 WHERE H stats_about X, H hit_type "normal",H count C, H period P, P eid %(e)s'
self.wview('piechart', self._cw.execute(rql, {'e': entity.eid}),
'null')
self.w(self._cw.view('plot', rset))
self.w(u'</div>')
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