-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebReports.py
More file actions
102 lines (86 loc) · 3.69 KB
/
webReports.py
File metadata and controls
102 lines (86 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import datetime
import sqlite3
import cherrypy
from webBase import WebBase
from accounts import Role
from tracing import Tracing
class WebReports(WebBase):
def checkPermissions(self, source="/reports"):
super().checkPermissions(Role.ADMIN, source)
@cherrypy.expose
def index(self, error=""):
self.checkPermissions()
with self.dbConnect() as dbConnection:
firstDate = self.engine.reports.getEarliestDate(
dbConnection).isoformat()
todayDate = datetime.date.today().isoformat()
reportList = self.engine.customReports.get_report_list(
dbConnection)
activeMembers = self.engine.members.getActive(dbConnection)
guests = self.engine.guests.getGuests(dbConnection, numDays=30)
return self.template('reports.mako',
firstDate=firstDate, todayDate=todayDate,
reportList=reportList, activeMembers=activeMembers, guests=guests, error=error)
@cherrypy.expose
def tracing(self, numDays, barcode=None):
if not barcode:
return self.index(error="No member selected")
self.checkPermissions()
with self.dbConnect() as dbConnection:
dictVisits = Tracing().getDictVisits(dbConnection, barcode, numDays)
(_, displayName) = self.engine.members.getName(
dbConnection, barcode)
if not displayName:
(_, displayName) = self.engine.guests.getName(
dbConnection, barcode)
return self.template('tracing.mako',
displayName=displayName,
dictVisits=dictVisits,
error="")
@cherrypy.expose
def standard(self, startDate, endDate):
self.checkPermissions()
return self.template('report.mako', stats=self.engine.reports.getStats(self.dbConnect(), startDate, endDate))
@cherrypy.expose
def graph(self, startDate, endDate):
self.checkPermissions()
cherrypy.response.headers['Content-Type'] = "image/png"
stats = self.engine.reports.getStats(
self.dbConnect(), startDate, endDate)
return stats.getBuildingUsageGraph()
@cherrypy.expose
def saveCustom(self, sql, report_name):
self.checkPermissions()
with self.dbConnect() as dbConnection:
error = self.engine.customReports.saveCustomSQL(
dbConnection, sql, report_name)
return self.index(error)
@cherrypy.expose
def savedCustom(self, report_id, error=''):
self.checkPermissions()
title = "Error"
sql = ""
try:
(title, sql, header, data) = self.engine.customReports.customReport(report_id)
except sqlite3.OperationalError as e:
data = repr(e)
header = ["Error"]
return self.template('customSQL.mako', report_title=title, sql=sql, data=data, header=header)
@cherrypy.expose
def customSQLReport(self, sql):
self.checkPermissions()
try:
(header, data) = self.engine.customReports.customSQL(sql)
except sqlite3.OperationalError as e:
data = repr(e)
header = ["Error"]
return self.template('customSQL.mako', sql=sql, header=header, data=data)
@cherrypy.expose
def teamList(self):
self.checkPermissions()
with self.dbConnect() as dbConnection:
teams = self.engine.teams.getActiveTeamList(dbConnection)
for team in teams:
team.members = self.engine.teams.getTeamMembers(
dbConnection, team.teamId)
return self.template('teamReport.mako', teams=teams)