-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebMainStation.py
More file actions
112 lines (99 loc) · 4.71 KB
/
webMainStation.py
File metadata and controls
112 lines (99 loc) · 4.71 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
103
104
105
106
107
108
109
110
111
112
from accounts import Accounts, Role
import cherrypy
from webBase import WebBase
KEYHOLDER_BARCODE = '999901'
class WebMainStation(WebBase):
# STATION
@cherrypy.expose
def index(self, error=''):
with self.dbConnect() as dbConnection:
(_, keyholder_name) = self.engine.accounts.getActiveKeyholder(dbConnection)
return self.template('station.mako',
todaysTransactions=self.engine.reports.transactionsToday(
dbConnection),
numberPresent=self.engine.reports.numberPresent(
dbConnection),
uniqueVisitorsToday=self.engine.reports.uniqueVisitorsToday(
dbConnection),
keyholder_name=keyholder_name,
stewards=self.engine.accounts.getPresentWithRole(
dbConnection, Role.SHOP_STEWARD),
error=error)
@cherrypy.expose
# later change this to be more ajaxy, but for now...
def scanned(self, barcode):
error = ''
# strip whitespace before or after barcode digits (occasionally a space comes before or after)
barcodes = barcode.split()
with self.dbConnect() as dbConnection:
(current_keyholder_bc, _) = self.engine.accounts.getActiveKeyholder(
dbConnection)
for bc in barcodes:
if (bc == KEYHOLDER_BARCODE) or (bc == current_keyholder_bc):
whoIsHere = self.engine.reports.whoIsHere(dbConnection)
if (bc == current_keyholder_bc) and len(whoIsHere) == 1:
self.checkout(bc, called=True)
else:
return self.template('keyholder.mako', whoIsHere=whoIsHere)
else:
error = self.engine.visits.scannedMember(dbConnection, bc)
if not current_keyholder_bc:
self.engine.accounts.setActiveKeyholder(
dbConnection, bc)
if error:
cherrypy.log(error)
raise cherrypy.HTTPRedirect("/station")
@cherrypy.expose
def checkin(self, barcode, called=False):
inBarcodeList = barcode.split()
with self.dbConnect() as dbConnection:
self.engine.checkin(dbConnection, inBarcodeList)
if not called:
raise cherrypy.HTTPRedirect(f"/links?barcode={inBarcodeList[0]}")
@cherrypy.expose
def checkout(self, barcode, called=False):
outBarcodeList = barcode.split()
with self.dbConnect() as dbConnection:
(current_keyholder_bc, _) = self.engine.accounts.getActiveKeyholder(
dbConnection)
leaving_keyholder_bc = self.engine.checkout(
dbConnection, current_keyholder_bc, outBarcodeList)
with self.dbConnect() as dbConnection:
if leaving_keyholder_bc:
self.engine.visits.emptyBuilding(
dbConnection, leaving_keyholder_bc)
self.engine.accounts.removeKeyholder(dbConnection)
if not called:
raise cherrypy.HTTPRedirect(f"/links?barcode={outBarcodeList[0]}")
@cherrypy.expose
def bulkUpdate(self, inBarcodes="", outBarcodes=""):
self.checkin(inBarcodes, called=True)
self.checkout(outBarcodes, called=True)
return "Bulk Update success"
@cherrypy.expose
def makeKeyholder(self, barcode):
error = ''
bc = barcode.strip()
with self.dbConnect() as dbConnection:
self.engine.visits.checkInMember(
dbConnection, barcode) # make sure checked in
result = self.engine.accounts.setActiveKeyholder(
dbConnection, barcode)
whoIsHere = self.engine.reports.whoIsHere(dbConnection)
if result == False:
return self.template('keyholder.mako', whoIsHere=whoIsHere)
raise cherrypy.HTTPRedirect(f"/links?barcode={bc}")
@cherrypy.expose
def keyholder(self, barcode):
error = ''
bc = barcode.strip()
with self.dbConnect() as dbConnection:
(current_keyholder_bc, _) = self.engine.accounts.getActiveKeyholder(
dbConnection)
if (bc == KEYHOLDER_BARCODE) or (bc == current_keyholder_bc):
self.engine.visits.emptyBuilding(
dbConnection, current_keyholder_bc)
self.engine.accounts.removeKeyholder(dbConnection)
else:
return self.makeKeyholder(barcode)
raise cherrypy.HTTPRedirect("/station")