forked from sahana/eden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.py
339 lines (283 loc) · 11.5 KB
/
event.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# -*- coding: utf-8 -*-
"""
Event Module - Controllers
http://eden.sahanafoundation.org/wiki/BluePrintScenario
"""
module = request.controller
resourcename = request.function
if not settings.has_module(module):
raise HTTP(404, body="Module disabled: %s" % module)
# -----------------------------------------------------------------------------
def index():
""" Module's Home Page """
return s3db.cms_index(module, alt_function="index_alt")
# -----------------------------------------------------------------------------
def index_alt():
"""
Module homepage for non-Admin users when no CMS content found
"""
# Just redirect to the list of Events
redirect(URL(f="event"))
# -----------------------------------------------------------------------------
def create():
""" Redirect to event/create """
redirect(URL(f="event", args="create"))
# -----------------------------------------------------------------------------
def event():
"""
RESTful CRUD controller
"""
# Pre-process
def prep(r):
if r.interactive:
if r.component:
if r.component.name == "req":
if r.method != "update" and r.method != "read":
# Hide fields which don't make sense in a Create form
# inc list_create (list_fields over-rides)
s3db.req_create_form_mods()
elif r.method != "update" and r.method != "read":
# Create or ListCreate
r.table.closed.writable = r.table.closed.readable = False
elif r.method == "update":
# Can't change details after event activation
table = r.table
table.exercise.writable = False
table.exercise.comment = None
table.start_date.writable = False
return True
s3.prep = prep
def postp(r, output):
if r.interactive:
if not r.component:
# Set the minimum end_date to the same as the start_date
s3.jquery_ready.append(
'''S3.start_end_date('event_event_start_date','event_event_end_date')''')
return output
s3.postp = postp
output = s3_rest_controller(rheader=event_rheader)
return output
# -----------------------------------------------------------------------------
def event_type():
"""
RESTful CRUD controller
"""
return s3_rest_controller()
# -----------------------------------------------------------------------------
def incident_type():
"""
RESTful CRUD controller
"""
return s3_rest_controller()
# -----------------------------------------------------------------------------
def incident():
"""
RESTful CRUD controller
"""
# Pre-process
def prep(r):
if r.interactive:
if r.component:
if r.component.name == "config":
s3db.configure("gis_config",
deletable=False)
s3.crud.submit_button = T("Update")
elif r.component.name == "human_resource":
s3db.configure("event_human_resource",
list_fields=["human_resource_id"])
s3.crud.submit_button = T("Assign")
s3.crud_labels["DELETE"] = T("Remove")
elif r.component.name == "asset":
s3db.configure("event_asset",
list_fields=["asset_id"])
s3.crud.submit_button = T("Assign")
s3.crud_labels["DELETE"] = T("Remove")
else:
s3.crud.submit_button = T("Assign")
s3.crud_labels["DELETE"] = T("Remove")
elif r.method != "update" and r.method != "read":
# Create or ListCreate
r.table.closed.writable = r.table.closed.readable = False
elif r.method == "update":
# Can't change details after event activation
table = r.table
table.scenario_id.writable = False
table.exercise.writable = False
table.exercise.comment = None
table.zero_hour.writable = False
return True
s3.prep = prep
# Post-process
def postp(r, output):
if r.interactive:
if r.component:
if r.component.name == "human_resource":
update_url = URL(c="hrm", f="human_resource", args=["[id]"])
s3_action_buttons(r, update_url=update_url)
if "msg" in settings.modules:
s3base.S3CRUD.action_button(url = URL(f="compose",
vars = {"hrm_id": "[id]"}),
_class = "action-btn send",
label = str(T("Send Notification")))
return output
s3.postp = postp
output = s3_rest_controller(rheader=event_rheader)
return output
# -----------------------------------------------------------------------------
def incident_report():
"""
RESTful CRUD controller
"""
return s3_rest_controller()
# -----------------------------------------------------------------------------
def resource():
"""
RESTful CRUD controller
"""
def prep(r):
if r.interactive:
if r.method in ("create", "update"):
table = r.table
if r.method == "create":
# Enable Location field
field = table.location_id
field.readable = field.writable = True
get_vars = r.get_vars
# Context from a Profile page?"
#location_id = get_vars.get("(location)", None)
#if location_id:
# field = table.location_id
# field.default = location_id
# field.readable = field.writable = False
incident_id = get_vars.get("~.(incident)", None)
if incident_id:
field = table.incident_id
field.default = incident_id
field.readable = field.writable = False
return True
s3.prep = prep
return s3_rest_controller()
# -----------------------------------------------------------------------------
def event_rheader(r):
""" Resource headers for component views """
rheader = None
if r.representation == "html":
if r.name == "event":
# Event Controller
tabs = [(T("Event Details"), None),
(T("Shelters"), "event_shelter"),
]
#if settings.has_module("req"):
# tabs.append((T("Requests"), "req"))
if settings.has_module("msg"):
tabs.append((T("Send Notification"), "dispatch"))
rheader_tabs = s3_rheader_tabs(r, tabs)
event = r.record
if event:
if event.exercise:
exercise = TH(T("EXERCISE"))
else:
exercise = TH()
if event.closed:
closed = TH(T("CLOSED"))
else:
closed = TH()
table = r.table
rheader = DIV(TABLE(TR(exercise),
TR(TH("%s: " % table.name.label),
event.name),
TR(TH("%s: " % table.comments.label),
event.comments),
TR(TH("%s: " % table.start_date.label),
table.start_date.represent(event.start_date)),
TR(closed),
), rheader_tabs)
if r.name == "incident":
# Incident Controller
tabs = [(T("Incident Details"), None)]
if settings.has_module("project"):
tabs.append((T("Tasks"), "task"))
if settings.has_module("hrm"):
tabs.append((T("Human Resources"), "human_resource"))
if settings.has_module("asset"):
tabs.append((T("Assets"), "asset"))
tabs.append((T("Facilities"), "site"))
tabs.append((T("Map Configuration"), "config"))
if settings.has_module("msg"):
tabs.append((T("Send Notification"), "dispatch"))
rheader_tabs = s3_rheader_tabs(r, tabs)
record = r.record
if record:
if record.exercise:
exercise = TH(T("EXERCISE"))
else:
exercise = TH()
if record.closed:
closed = TH(T("CLOSED"))
else:
closed = TH()
table = r.table
rheader = DIV(TABLE(TR(exercise),
TR(TH("%s: " % table.name.label),
record.name),
TR(TH("%s: " % table.comments.label),
record.comments),
TR(TH("%s: " % table.zero_hour.label),
table.zero_hour.represent(record.zero_hour)),
TR(closed),
), rheader_tabs)
return rheader
# -----------------------------------------------------------------------------
def person():
""" Person controller for AddPersonWidget """
def prep(r):
if r.representation != "s3json":
# Do not serve other representations here
return False
else:
current.xml.show_ids = True
return True
s3.prep = prep
return s3_rest_controller("pr", "person")
# -----------------------------------------------------------------------------
def compose():
""" Send message to people/teams """
vars = request.vars
if "hrm_id" in vars:
id = vars.hrm_id
fieldname = "hrm_id"
table = s3db.pr_person
htable = s3db.hrm_human_resource
pe_id_query = (htable.id == id) & \
(htable.person_id == table.id)
title = T("Send a message to this person")
else:
session.error = T("Record not found")
redirect(URL(f="index"))
pe = db(pe_id_query).select(table.pe_id,
limitby=(0, 1)).first()
if not pe:
session.error = T("Record not found")
redirect(URL(f="index"))
pe_id = pe.pe_id
# Get the individual's communications options & preference
table = s3db.pr_contact
contact = db(table.pe_id == pe_id).select(table.contact_method,
orderby="priority",
limitby=(0, 1)).first()
if contact:
s3db.msg_outbox.contact_method.default = contact.contact_method
else:
session.error = T("No contact method found")
redirect(URL(f="index"))
# URL to redirect to after message sent
url = URL(c=module,
f="compose",
vars={fieldname: id})
# Create the form
output = msg.compose(recipient = pe_id,
url = url)
output["title"] = title
response.view = "msg/compose.html"
return output
# END =========================================================================