-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.py
279 lines (240 loc) · 7.02 KB
/
entry.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env python3
########### SVN repository information ###########
# $Date$
# $Author$
# $Revision$
# $URL$
# $Id$
########### SVN repository information ###########
'''
The Entry class used by Kevin's monthly-report software.
Allows the interface to be agnostic with respect to the log file type.
'''
from time import strftime, strptime
import config
class ReportEntry:
'''
Class representing a monthly-report entry.
All arguments to the init function are strings.
'''
def __init__(self, date=None, duration="0.0", activity="", group="", title="", description="", payCode=""):
if date == None:
self.date = strftime("%Y-%m-%d")
self.duration = duration
self.activity = activity
self.group = group
self.title = title
self.description = description
self.payCode = payCode
self.functionDict = {"date":(self.getDate, self.setDate, self.verifyDate),
"duration":(self.getDuration, self.setDuration, self.verifyDuration),
"activity":(self.getActivity, self.setActivity, self.verifyActivity),
"group":(self.getGroup, self.setGroup, self.verifyGroup),
"title":(self.getTitle, self.setTitle, self.verifyTitle),
"description":(self.getDescription, self.setDescription, self.verifyDescription),
"payCode":(self.getPayCode, self.setPayCode, self.verifyPayCode),
"index":(self.getIndex, self.setIndex, self.verifyIndex)}
self.index = -1
def getAll(self):
'''
Method to get all the fields that can be modified by the user.
Returns [self.date, self.duration, self.activity, self.group, self.title, self.description, self.payCode]
'''
return [self.date, self.duration, self.activity, self.group, self.title, self.description, self.payCode]
def setAll(self, fieldList):
'''
Method to set all the fields that can be modified by the user.
fieldList: [self.date, self.duration, self.activity, self.group, self.title, self.description, self.payCode]
'''
self.date, self.duration, self.activity, self.group, self.title, self.description, self.payCode = fieldList
return
def getYear(self):
'''
Method to get the entry year
'''
return self.date[:4]
def getDate(self):
'''
Method to get the entry date.
'''
return self.date
def getDuration(self):
'''
Method to get the entry duration.
'''
return self.duration
def getDurationFloat(self):
'''
Method to get the entry duration as a float.
'''
return float(self.duration)
def getActivity(self):
'''
Method to get the entry activity.
'''
return self.activity
def getGroup(self):
'''
Method to get the entry group.
'''
return self.group
def getTitle(self):
'''
Method to get the entry title.
'''
return self.title
def getDescription(self):
'''
Method to get the entry description.
'''
return self.description
def getPayCode(self):
'''
Method to get the entry pay code.
'''
return self.payCode
def getIndex(self):
'''
Method to get the entry index.
'''
return self.index
def setDate(self, date):
'''
Method to set the entry date (String).
'''
self.date = date
def setDuration(self, duration):
'''
Method to set the entry duration (String).
'''
self.duration = duration
def setActivity(self, activity):
'''
Method to set the entry activity (String, choices defined in the config module).
'''
self.activity = activity
def setGroup(self, group):
'''
Method to set the entry group (String, choices defined in the config module).
'''
self.group = group
def setTitle(self, title):
'''
Method to set the entry title (String).
'''
self.title = title
def setDescription(self, description):
'''
Method to set the entry description (String).
'''
self.description = description
def setPayCode(self, payCode):
'''
Method to set the entry pay code (String).
'''
self.payCode = payCode
def setIndex(self, index):
'''
Method to set the entry index (String, numbering starts with 1)
'''
# Maybe should make this simply pass instead
self.index = index
def verifyDate(self, userInput):
'''
Method to verify the date to be written to the entry. (String)
'''
if userInput == "":
valid = True
else:
try:
strptime(userInput, '%Y-%m-%d')
valid = True
except ValueError:
valid = False
return valid
def verifyDuration(self, userInput):
'''
Method to verify the duration to be written to the entry. (String)
'''
if userInput == "":
valid = True
else:
try:
float(userInput)
valid = True
except ValueError:
valid = False
return valid
def verifyActivity(self, userInput):
'''
Method to verify the activity to be written to the entry. (String)
'''
if userInput in config.possible_activities:
valid = True
else:
valid = False
return valid
def verifyGroup(self, userInput):
'''
Method to verify the group to be written to the entry. (String)
'''
if userInput in config.possible_groups:
valid = True
else:
valid = False
return valid
def verifyTitle(self, userInput):
'''
Method to verify the title to be written to the entry. (String)
'''
return True
def verifyDescription(self, userInput):
'''
Method to verify the description to be written to the entry. (String)
'''
return True
def verifyPayCode(self, userInput):
'''
Method to verify the pay code to be written to the entry. (String)
'''
# Allow an empty string to be considered valid; the ui must handle that case
if userInput in config.possible_payCodes or userInput == "":
valid = True
else:
valid = False
return valid
def verifyIndex(self, userInput):
'''
Method to verify the index to be written to the entry. (String)
'''
# Maybe should make this simply pass instead
if userInput == "":
valid = True
else:
try:
index = int(userInput)
if index >= -1:
valid = True
else:
valid = False
except ValueError:
valid = False
return valid
def getFunctions(self, item):
'''
Method that returns the get, set and verify functions for a given string from log.logEntryDef.
'''
return self.functionDict[item]
def printEntry(self):
'''
Prints the entry to the console.
'''
# Should this instead return a string representation of the entry?
print("index: {}".format(self.index))
print("date: {}".format(self.date))
print("duration: {}".format(self.duration))
print("activity: {}".format(self.activity))
print("group: {}".format(self.group))
print("title: {}".format(self.title))
print("description: {}".format(self.description))
print("payCode: {}".format(self.payCode))