-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMemberRecord.py
160 lines (137 loc) · 5.01 KB
/
MemberRecord.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------
# _____ ______________
# | __ \ /\|__ ____ __|
# | |__) | / \ | | | |
# | _ / / /\ \ | | | |
# | | \ \/ ____ \| | | |
# |_| \_\/ \_\_| |_| ... RFID ALL THE THINGS!
#
# A resource access control and telemetry solution for Makerspaces
#
# Developed at MakeIt Labs - New Hampshire's First & Largest Makerspace
# http://www.makeitlabs.com/
#
# Copyright 2018 MakeIt Labs
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
#
# Author: Steve Richardson (steve.richardson@makeitlabs.com)
#
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal, pyqtProperty
class MemberRecord(QObject):
recordChanged = pyqtSignal()
ACCESS_LEVEL=['User','Trainer','ARM','RM','Admin']
LEVEL_USER=0
LEVEL_TRAINER=1
LEVEL_ARM=2
LEVEL_RM=3
LEVEL_ADMIN=4
LEVEL_HEADRM=4 # Equiv of Admin
LEVEL_NOACCESS=-1
def __init__(self, initRecord = []):
QObject.__init__(self)
self.clear()
if initRecord != []:
self.parseRecord(initRecord)
def copy(self, source):
self._member = source.name
self._nickname = source.nickname
self._endorsements = source.endorsements
self._level = source.level
self._tagid = source.tag
self._lastaccessed = source.lastAccessed
self._warning = source.warningText
self._plan = source.plan
self._allowed = source.allowed
self._isValid = source.valid
self._isLoggedIn = source.loggedIn
self.recordChanged.emit()
def clear(self):
self._member = ''
self._nickname = ''
self._endorsements = ''
self._level = -1
self._tagid = ''
self._lastaccessed = ''
self._warning = ''
self._plan = ''
self._allowed = False
self._isValid = False
self._isLoggedIn = False
self.recordChanged.emit()
def isClear(self):
return self._member == '' and self._isValid == False and self._isLoggedIn == False
def parseRecord(self, record):
try:
self._member = record['member']
self._nickname = record['nickname']
if 'endorsements' in record:
self._endorsements = record['endorsements']
else:
self._endorsements = ''
self._level = int(record['level'])
self._tagid = record['tagid']
self._lastaccessed = record['last_accessed']
self._warning = record['warning']
self._plan = record['plan']
self._allowed = (record['allowed'] == 'allowed')
self._isValid = True
self.recordChanged.emit()
except:
self.clear()
return self._isValid
@pyqtProperty(str, notify=recordChanged)
def name(self):
return self._member
@pyqtProperty(str, notify=recordChanged)
def nickname(self):
return self._nickname
@pyqtProperty(str, notify=recordChanged)
def endorsements(self):
return self._endorsements
@pyqtProperty(int, notify=recordChanged)
def level(self):
return self._level
@pyqtProperty(str, notify=recordChanged)
def tag(self):
return self._tagid
@pyqtProperty(str, notify=recordChanged)
def lastAccessed(self):
return self._lastaccessed
@pyqtProperty(str, notify=recordChanged)
def warningText(self):
return self._warning
@pyqtProperty(str, notify=recordChanged)
def plan(self):
return self._plan
@pyqtProperty(bool, notify=recordChanged)
def allowed(self):
return self._allowed
@pyqtProperty(bool, notify=recordChanged)
def valid(self):
return self._isValid
@pyqtProperty(bool, notify=recordChanged)
def loggedIn(self):
return self._isLoggedIn
@loggedIn.setter
def loggedIn(self, value):
self._isLoggedIn = value
self.recordChanged.emit()