forked from sahana/eden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
executable file
·1207 lines (1065 loc) · 44.2 KB
/
default.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Default Controllers
"""
module = "default"
# -----------------------------------------------------------------------------
def call():
"Call an XMLRPC, JSONRPC or RSS service"
# If webservices don't use sessions, avoid cluttering up the storage
#session.forget()
return service()
# -----------------------------------------------------------------------------
def download():
""" Download a file """
try:
filename = request.args[0]
except:
session.error("Need to specify the file to download!")
redirect(URL(f="index"))
# Load the Model
tablename = filename.split(".", 1)[0]
table = s3db[tablename]
return response.download(request, db)
# =============================================================================
def register_validation(form):
""" Validate the fields in registration form """
vars = form.vars
# Mobile Phone
if "mobile" in vars and vars.mobile:
import re
regex = re.compile(single_phone_number_pattern)
if not regex.match(vars.mobile):
form.errors.mobile = T("Invalid phone number")
elif settings.get_auth_registration_mobile_phone_mandatory():
form.errors.mobile = T("Phone number is required")
org = settings.get_auth_registration_organisation_id_default()
if org:
# Add to default organisation
vars.organisation_id = org
return
# =============================================================================
def index():
""" Main Home Page """
auth.settings.register_onvalidation = register_validation
auth.configure_user_fields()
page = request.args(0)
if page:
# Go to a custom page
# Arg 1 = function in /private/templates/<template>/controllers.py
# other Args & Vars passed through
controller = "applications.%s.private.templates.%s.controllers" % \
(appname, settings.get_template())
try:
exec("import %s as custom" % controller)
except ImportError, e:
# No Custom Page available, continue with the default
page = "private/templates/%s/controllers.py" % \
settings.get_template()
s3base.s3_debug("File not loadable: %s, %s" % (page, e.message))
else:
if "." in page:
# Remove extension
page = page.split(".", 1)[0]
if page in custom.__dict__:
exec ("output = custom.%s()()" % page)
return output
elif page != "login":
raise(HTTP(404, "Function not found: %s()" % page))
else:
output = custom.index()()
return output
elif settings.get_template() != "default":
# Try a Custom Homepage
controller = "applications.%s.private.templates.%s.controllers" % \
(appname, settings.get_template())
try:
exec("import %s as custom" % controller)
except ImportError, e:
# No Custom Page available, continue with the default
# @ToDo: cache this result in session
s3base.s3_debug("Custom homepage cannot be loaded: %s" % e.message)
else:
if "index" in custom.__dict__:
output = custom.index()()
return output
# Default Homepage
title = settings.get_system_name()
response.title = title
item = ""
has_module = settings.has_module
if has_module("cms"):
table = s3db.cms_post
ltable = s3db.cms_post_module
query = (ltable.module == module) & \
(ltable.post_id == table.id) & \
(table.deleted != True)
item = db(query).select(table.body,
limitby=(0, 1)).first()
if item:
item = DIV(XML(item.body))
else:
item = ""
if has_module("cr"):
table = s3db.cr_shelter
SHELTERS = s3.crud_strings["cr_shelter"].title_list
else:
SHELTERS = ""
# Menu Boxes
menu_btns = [#div, label, app, function
["facility", T("Facilities"), "org", "facility"],
["facility", T("Hospitals"), "hms", "hospital"],
["facility", T("Offices"), "org", "office"],
["facility", SHELTERS, "cr", "shelter"],
["facility", T("Warehouses"), "inv", "warehouse"],
["sit", T("Staff"), "hrm", "staff"],
["sit", T("Volunteers"), "vol", "volunteer"],
["sit", T("Incidents"), "irs", "ireport"],
["sit", T("Assessments"), "survey", "series"],
["sit", T("Assets"), "asset", "asset"],
["sit", T("Inventory Items"), "inv", "inv_item"],
#["dec", T("Gap Map"), "project", "gap_map"],
#["dec", T("Gap Report"), "project", "gap_report"],
["dec", T("Requests"), "req", "req"],
["res", T("Projects"), "project", "project"],
["res", T("Commitments"), "req", "commit"],
["res", T("Sent Shipments"), "inv", "send"],
["res", T("Received Shipments"), "inv", "recv"],
]
# Change to (Mitigation)/Preparedness/Response/Recovery?
menu_divs = {"facility": DIV(H3(T("Facilities")),
_id = "facility_box",
_class = "menu_box",
),
"sit": DIV(H3(T("Situation")),
_id = "menu_div_sit",
_class = "menu_div",
),
"dec": DIV(H3(T("Decision")),
_id = "menu_div_dec",
_class = "menu_div",
),
"res": DIV(H3(T("Response")),
_id = "menu_div_res",
_class = "menu_div",
),
}
for div, label, app, function in menu_btns:
if has_module(app):
# @ToDo: Also check permissions (e.g. for anonymous users)
menu_divs[div].append(A(DIV(label,
_class = "menu-btn-r"),
_class = "menu-btn-l",
_href = URL(app, function)
)
)
div_arrow = DIV(IMG(_src = "/%s/static/img/arrow_blue_right.png" % \
appname),
_class = "div_arrow")
sit_dec_res_box = DIV(menu_divs["sit"],
div_arrow,
menu_divs["dec"],
div_arrow,
menu_divs["res"],
_id = "sit_dec_res_box",
_class = "menu_box fleft swidth"
#div_additional,
)
facility_box = menu_divs["facility"]
facility_box.append(A(IMG(_src = "/%s/static/img/map_icon_128.png" % \
appname),
_href = URL(c="gis", f="index"),
_title = T("Map")
)
)
# Check logged in AND permissions
roles = session.s3.roles
table = s3db.org_organisation
has_permission = auth.s3_has_permission
if AUTHENTICATED in roles and \
has_permission("read", table):
org_items = organisation()
datatable_ajax_source = "/%s/default/organisation.aadata" % \
appname
s3.actions = None
response.view = "default/index.html"
permission = auth.permission
permission.controller = "org"
permission.function = "site"
permitted_facilities = auth.permitted_facilities(redirect_on_error=False)
if permitted_facilities:
facilities = s3db.org_SiteRepresent().bulk(permitted_facilities)
facility_list = [(fac, facilities[fac]) for fac in facilities]
facility_list = sorted(facility_list, key=lambda fac: fac[1])
facility_opts = [OPTION(fac[1], _value=fac[0])
for fac in facility_list]
manage_facility_box = DIV(H3(T("Manage Your Facilities")),
SELECT(_id = "manage_facility_select",
_style = "max-width:400px;",
*facility_opts
),
A(T("Go"),
_href = URL(c="default", f="site",
args=[facility_list[0][0]]),
#_disabled = "disabled",
_id = "manage_facility_btn",
_class = "action-btn"
),
_id = "manage_facility_box",
_class = "menu_box fleft"
)
s3.jquery_ready.append(
'''$('#manage_facility_select').change(function(){
$('#manage_facility_btn').attr('href',S3.Ap.concat('/default/site/',$('#manage_facility_select').val()))
})''')
else:
manage_facility_box = ""
if has_permission("create", table):
create = A(T("Add Organization"),
_href = URL(c="org", f="organisation",
args=["create"]),
_id = "add-btn",
_class = "action-btn",
_style = "margin-right: 10px;")
else:
create = ""
org_box = DIV(H3(T("Organizations")),
create,
org_items,
_id = "org_box",
_class = "menu_box fleft"
)
else:
datatable_ajax_source = ""
manage_facility_box = ""
org_box = ""
# Login/Registration forms
self_registration = settings.get_security_self_registration()
registered = False
login_form = None
login_div = None
register_form = None
register_div = None
if AUTHENTICATED not in roles:
# This user isn't yet logged-in
if request.cookies.has_key("registered"):
# This browser has logged-in before
registered = True
if self_registration:
# Provide a Registration box on front page
register_form = auth.s3_registration_form()
register_div = DIV(H3(T("Register")),
P(XML(T("If you would like to help, then please %(sign_up_now)s") % \
dict(sign_up_now=B(T("sign-up now"))))))
if request.env.request_method == "POST":
post_script = \
'''$('#register_form').removeClass('hide')
$('#login_form').addClass('hide')'''
else:
post_script = ""
register_script = \
'''$('#register-btn').attr('href','#register')
$('#login-btn').attr('href','#login')
%s
$('#register-btn').click(function(){
$('#register_form').removeClass('hide')
$('#login_form').addClass('hide')
})
$('#login-btn').click(function(){
$('#register_form').addClass('hide')
$('#login_form').removeClass('hide')
})''' % post_script
s3.jquery_ready.append(register_script)
# Provide a login box on front page
request.args = ["login"]
auth.messages.submit_button = T("Login")
login_form = auth()
login_div = DIV(H3(T("Login")),
P(XML(T("Registered users can %(login)s to access the system") % \
dict(login=B(T("login"))))))
if settings.frontpage.rss:
s3.external_stylesheets.append("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css")
s3.scripts.append("http://www.google.com/jsapi?key=notsupplied-wizard")
s3.scripts.append("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js")
counter = 0
feeds = ""
for feed in settings.frontpage.rss:
counter += 1
feeds = "".join((feeds,
"{title:'%s',\n" % feed["title"],
"url:'%s'}" % feed["url"]))
# Don't add a trailing comma for old IEs
if counter != len(settings.frontpage.rss):
feeds += ",\n"
# feedCycleTime: milliseconds before feed is reloaded (5 minutes)
feed_control = "".join(('''
function LoadDynamicFeedControl(){
var feeds=[
''', feeds, '''
]
var options={
feedCycleTime:300000,
numResults:5,
stacked:true,
horizontal:false,
title:"''', str(T("News")), '''"
}
new GFdynamicFeedControl(feeds,'feed-control',options)
}
google.load('feeds','1')
google.setOnLoadCallback(LoadDynamicFeedControl)'''))
s3.js_global.append(feed_control)
output = dict(title = title,
item = item,
sit_dec_res_box = sit_dec_res_box,
facility_box = facility_box,
manage_facility_box = manage_facility_box,
org_box = org_box,
r = None, # Required for dataTable to work
datatable_ajax_source = datatable_ajax_source,
self_registration=self_registration,
registered=registered,
login_form=login_form,
login_div=login_div,
register_form=register_form,
register_div=register_div
)
output = s3_guided_tour(output)
return output
# -----------------------------------------------------------------------------
def organisation():
"""
Function to handle pagination for the org list on the homepage
"""
request = current.request
get_vars = request.get_vars
representation = request.extension
resource = current.s3db.resource("org_organisation")
totalrows = resource.count()
display_start = int(get_vars.iDisplayStart) if get_vars.iDisplayStart else 0
display_length = int(get_vars.iDisplayLength) if get_vars.iDisplayLength else 10
limit = 4 * display_length
list_fields = ["id", "name"]
default_orderby = orderby = "org_organisation.name asc"
if representation == "aadata":
query, orderby, left = resource.datatable_filter(list_fields, get_vars)
if orderby is None:
orderby = default_orderby
data = resource.select(list_fields,
start=display_start,
limit=limit,
orderby=orderby,
count=True,
represent=True)
filteredrows = data["numrows"]
rfields = data["rfields"]
data = data["rows"]
dt = S3DataTable(rfields, data)
dt.defaultActionButtons(resource)
current.response.s3.no_formats = True
if representation == "html":
items = dt.html(totalrows,
totalrows,
"org_dt",
dt_displayLength=display_length,
dt_ajax_url=URL(c="default",
f="organisation",
extension="aadata",
vars={"id": "org_dt"},
),
dt_pagination="true",
)
elif representation == "aadata":
if "sEcho" in request.vars:
echo = int(request.vars.sEcho)
else:
echo = None
items = dt.json(totalrows,
filteredrows,
"org_dt",
echo)
else:
from gluon.http import HTTP
raise HTTP(501, resource.ERROR.BAD_FORMAT)
return items
# -----------------------------------------------------------------------------
def site():
"""
@ToDo: Avoid redirect
"""
try:
site_id = request.args[0]
except:
raise HTTP(404)
table = s3db.org_site
record = db(table.site_id == site_id).select(table.instance_type,
limitby=(0, 1)).first()
tablename = record.instance_type
table = s3db.table(tablename)
if table:
query = (table.site_id == site_id)
id = db(query).select(table.id,
limitby = (0, 1)).first().id
cf = tablename.split("_", 1)
redirect(URL(c = cf[0],
f = cf[1],
args = [id]))
# -----------------------------------------------------------------------------
def message():
""" Show a confirmation screen """
#if "verify_email_sent" in request.args:
title = T("Account Registered - Please Check Your Email")
message = T( "%(system_name)s has sent an email to %(email)s to verify your email address.\nPlease check your email to verify this address. If you do not receive this email please check you junk email or spam filters." )\
% {"system_name": settings.get_system_name(),
"email": request.vars.email}
image = "email_icon.png"
return dict(title = title,
message = message,
image_src = "/%s/static/img/%s" % (appname, image)
)
# -----------------------------------------------------------------------------
def rapid():
""" Set/remove rapid data entry flag """
val = request.vars.get("val", True)
if val == "0":
val = False
else:
val = True
session.s3.rapid_data_entry = val
response.view = "xml.html"
return dict(item=str(session.s3.rapid_data_entry))
# -----------------------------------------------------------------------------
def user():
""" Auth functions based on arg. See gluon/tools.py """
arg = request.args(0)
auth.settings.on_failed_authorization = URL(f="error")
auth.configure_user_fields()
auth.settings.register_onvalidation = register_validation
_table_user = auth.settings.table_user
auth.settings.profile_onaccept = auth.s3_user_profile_onaccept
self_registration = settings.get_security_self_registration()
login_form = register_form = None
if request.args:
arg = request.args(0)
else:
arg = None
# Check for template-specific customisations
customize = settings.ui.get("customize_auth_user", None)
if customize:
customize(arg=arg)
# Needs more work to integrate our form extensions
#auth.settings.formstyle = s3_formstyle
if arg == "login":
title = response.title = T("Login")
# @ToDo: move this code to /modules/s3/s3aaa.py:def login()?
auth.messages.submit_button = T("Login")
form = auth()
#form = auth.login()
login_form = form
elif arg == "register":
title = response.title = T("Register")
# @ToDo: move this code to /modules/s3/s3aaa.py:def register()?
if not self_registration:
session.error = T("Registration not permitted")
redirect(URL(f="index"))
form = register_form = auth.s3_registration_form()
elif arg == "change_password":
title = response.title = T("Change Password")
form = auth()
# Add client-side validation
if s3.debug:
s3.scripts.append("/%s/static/scripts/jquery.pstrength.2.1.0.js" % appname)
else:
s3.scripts.append("/%s/static/scripts/jquery.pstrength.2.1.0.min.js" % appname)
s3.jquery_ready.append("$('.password:eq(1)').pstrength()")
elif arg == "retrieve_password":
title = response.title = T("Retrieve Password")
form = auth()
elif arg == "profile":
title = response.title = T("User Profile")
form = auth.profile()
elif arg == "options.s3json":
# Used when adding organisations from registration form
return s3_rest_controller(prefix="auth", resourcename="user")
else:
# logout
title = ""
form = auth()
if form:
if s3.crud.submit_style:
form[0][-1][1][0]["_class"] = s3.crud.submit_style
elif s3_formstyle == "bootstrap":
form[0][-1][1][0]["_class"] = "btn btn-primary"
# Use Custom Ext views
# Best to not use an Ext form for login: can't save username/password in browser & can't hit 'Enter' to submit!
#if request.args(0) == "login":
# response.title = T("Login")
# response.view = "auth/login.html"
if settings.get_template() != "default":
# Try a Custom View
view = os.path.join(request.folder, "private", "templates",
settings.get_template(), "views", "user.html")
if os.path.exists(view):
try:
# Pass view as file not str to work in compiled mode
response.view = open(view, "rb")
except IOError:
from gluon.http import HTTP
raise HTTP("404", "Unable to open Custom View: %s" % view)
return dict(title=title,
form=form,
login_form=login_form,
register_form=register_form,
self_registration=self_registration)
# -----------------------------------------------------------------------------
def person():
"""
Profile to show:
- User Details
- Person Details
- Staff/Volunteer Record
- Map Config
"""
# Set to current user
user_person_id = str(s3_logged_in_person())
# When request.args = [], set it as user_person_id.
# When it is not an ajax request and the first argument is not user_person_id, set it.
# If it is an json request, leave the arguments unmodified.
if not request.args or (request.args[0] != user_person_id and \
request.args[-1] != "options.s3json" and \
request.args[-1] != "validate.json"
):
request.args = [user_person_id]
set_method = s3db.set_method
# Custom Method for User
def auth_profile_method(r, **attr):
# Custom View
response.view = "update.html"
current.menu.breadcrumbs = None
# RHeader for consistency
rheader = attr.get("rheader", None)
if callable(rheader):
rheader = rheader(r)
table = auth.settings.table_user
tablename = table._tablename
next = URL(c = "default",
f = "person",
args = [user_person_id, "user"])
onaccept = lambda form: auth.s3_approve_user(form.vars),
form = auth.profile(next = next,
onaccept = onaccept)
return dict(title = T("User Profile"),
rheader = rheader,
form = form,
)
set_method("pr", "person",
method="user",
action=auth_profile_method)
# Custom Method for Contacts
set_method("pr", "person",
method="contacts",
action=s3db.pr_contacts)
#if settings.has_module("asset"):
# # Assets as component of people
# s3db.add_component("asset_asset",
# pr_person="assigned_to_id")
# CRUD pre-process
def prep(r):
if r.method in ("options", "validate"):
return True
if r.interactive and r.method != "import":
# Load default model to override CRUD Strings
tablename = "pr_person"
table = s3db[tablename]
s3.crud_strings[tablename].update(
title_display = T("Personal Profile"),
title_update = T("Personal Profile"))
# Organisation-dependent Fields
set_org_dependent_field = settings.set_org_dependent_field
set_org_dependent_field("pr_person_details", "father_name")
set_org_dependent_field("pr_person_details", "mother_name")
set_org_dependent_field("pr_person_details", "affiliations")
set_org_dependent_field("pr_person_details", "company")
if r.component:
if r.component_name == "physical_description":
# Hide all but those details that we want
# Lock all the fields
table = r.component.table
for field in table.fields:
table[field].writable = False
table[field].readable = False
# Now enable those that we want
table.ethnicity.writable = True
table.ethnicity.readable = True
table.blood_type.writable = True
table.blood_type.readable = True
table.medical_conditions.writable = True
table.medical_conditions.readable = True
table.other_details.writable = True
table.other_details.readable = True
elif r.component_name == "saved_search":
if r.method == "load":
if r.component_id:
table = db.pr_saved_search
record = db(table.id == r.component_id).select(table.url,
limitby=(0, 1)
).first()
if record:
redirect(record.url)
else:
raise HTTP(404)
elif r.component_name == "config":
ctable = s3db.gis_config
s3db.gis_config_form_setup()
# Create forms use this
# (update forms are in gis/config())
fields = ["name",
"pe_default",
"default_location_id",
"zoom",
"lat",
"lon",
#"projection_id",
#"symbology_id",
#"wmsbrowser_url",
#"wmsbrowser_name",
]
osm_table = s3db.gis_layer_openstreetmap
openstreetmap = db(osm_table.deleted == False).select(osm_table.id,
limitby=(0, 1))
if openstreetmap:
# OpenStreetMap config
s3db.add_component("auth_user_options",
gis_config=dict(joinby="pe_id",
pkey="pe_id",
multiple=False)
)
fields += ["user_options.osm_oauth_consumer_key",
"user_options.osm_oauth_consumer_secret",
]
crud_form = s3base.S3SQLCustomForm(*fields)
list_fields = ["name",
"pe_default",
]
s3db.configure("gis_config",
crud_form=crud_form,
insertable=False,
list_fields = list_fields,
)
else:
table.pe_label.readable = False
table.pe_label.writable = False
table.missing.readable = False
table.missing.writable = False
table.age_group.readable = False
table.age_group.writable = False
# Assume volunteers only between 12-81
table.date_of_birth.widget = S3DateWidget(past=972, future=-144)
return True
else:
# Disable non-interactive & import
return False
s3.prep = prep
# CRUD post-process
def postp(r, output):
if r.interactive and r.component:
if r.component_name == "human_resource":
# Set the minimum end_date to the same as the start_date
s3.jquery_ready.append(
'''S3.start_end_date('hrm_human_resource_start_date','hrm_human_resource_end_date')''')
if r.component_name == "experience":
# Set the minimum end_date to the same as the start_date
s3.jquery_ready.append(
'''S3.start_end_date('hrm_experience_start_date','hrm_experience_end_date')''')
elif r.component_name == "config":
update_url = URL(c="gis", f="config",
args="[id]")
s3_action_buttons(r, update_url=update_url)
s3.actions.append(
dict(url=URL(c="gis", f="index",
vars={"config":"[id]"}),
label=str(T("Show")),
_class="action-btn")
)
elif r.component_name == "saved_search" and r.method in (None, "search"):
s3_action_buttons(r)
s3.actions.append(
dict(url=URL(args=r.args + ["[id]", "load"]),
label=str(T("Load")),
_class="action-btn")
)
elif r.component_name == "asset":
# Provide a link to assign a new Asset
# @ToDo: Proper Widget to do this inline
output["add_btn"] = A(T("Assign Asset"),
_href=URL(c="asset", f="asset"),
_id="add-btn",
_class="action-btn")
return output
s3.postp = postp
if settings.get_hrm_staff_experience() == "experience":
experience_tab = (T("Experience"), "experience")
else:
experience_tab = None
if settings.get_hrm_use_certificates():
certificates_tab = (T("Certificates"), "certificate")
else:
certificates_tab = None
if settings.get_hrm_use_credentials():
credentials_tab = (T("Credentials"), "credential")
else:
credentials_tab = None
if settings.get_hrm_use_description():
description_tab = (T("Description"), "physical_description")
else:
description_tab = None
if settings.get_hrm_use_education():
education_tab = (T("Education"), "education")
else:
education_tab = None
if settings.get_hrm_use_id():
id_tab = (T("ID"), "identity")
else:
id_tab = None
if settings.get_hrm_use_skills():
skills_tab = (T("Skills"), "competency")
else:
skills_tab = None
teams = settings.get_hrm_teams()
if teams:
teams_tab = (T(teams), "group_membership")
else:
teams_tab = None
if settings.get_hrm_use_trainings():
trainings_tab = (T("Trainings"), "training")
else:
trainings_tab = None
if settings.get_search_save_widget():
searches_tab = (T("Saved Searches"), "saved_search")
else:
searches_tab = None
tabs = [(T("Person Details"), None),
(T("User Account"), "user"),
(T("Staff/Volunteer Record"), "human_resource"),
id_tab,
description_tab,
(T("Address"), "address"),
(T("Contacts"), "contacts"),
education_tab,
trainings_tab,
certificates_tab,
skills_tab,
credentials_tab,
experience_tab,
teams_tab,
#(T("Assets"), "asset"),
(T("My Maps"), "config"),
searches_tab,
]
output = s3_rest_controller("pr", "person",
rheader = lambda r: \
s3db.pr_rheader(r, tabs=tabs))
return output
# -----------------------------------------------------------------------------
def group():
"""
RESTful CRUD controller
- needed when group add form embedded in default/person
- only create method is allowed, when opened in a inline form.
"""
# Check if it is called from a inline form
if auth.permission.format != "popup":
return ""
# Pre-process
def prep(r):
if r.method != "create":
return False
return True
s3.prep = prep
output = s3_rest_controller("pr", "group")
return output
# -----------------------------------------------------------------------------
def skill():
"""
RESTful CRUD controller
- needed when skill add form embedded in default/person
- only create method is allowed, when opened in a inline form.
"""
# Check if it is called from a inline form
if auth.permission.format != "popup":
return ""
# Pre-process
def prep(r):
if r.method != "create":
return False
return True
s3.prep = prep
output = s3_rest_controller("hrm", "skill")
return output
# -----------------------------------------------------------------------------
def facebook():
""" Login using Facebook """
if not auth.settings.facebook:
redirect(URL(f="user", args=request.args, vars=request.vars))
from s3oauth import FaceBookAccount
auth.settings.login_form = FaceBookAccount()
form = auth()
return dict(form=form)
# -----------------------------------------------------------------------------
def google():
""" Login using Google """
if not auth.settings.google:
redirect(URL(f="user", args=request.args, vars=request.vars))
from s3oauth import GooglePlusAccount
auth.settings.login_form = GooglePlusAccount()
form = auth()
return dict(form=form)
# -----------------------------------------------------------------------------
# About Sahana
def apath(path=""):
""" Application path """
from gluon.fileutils import up
opath = up(request.folder)
# @ToDo: This path manipulation is very OS specific.
while path[:3] == "../": opath, path=up(opath), path[3:]
return os.path.join(opath,path).replace("\\", "/")
def about():
"""
The About page provides details on the software dependencies and
versions available to this instance of Sahana Eden.
"""
response.title = T("About")
if settings.get_template() != "default":
# Try a Custom View
view = os.path.join(request.folder, "private", "templates",
settings.get_template(), "views", "about.html")
if os.path.exists(view):
try:
# Pass view as file not str to work in compiled mode
response.view = open(view, "rb")
except IOError:
from gluon.http import HTTP
raise HTTP("404", "Unable to open Custom View: %s" % view)
import sys
import subprocess
import string
python_version = sys.version
web2py_version = open(apath("../VERSION"), "r").read()[8:]
sahana_version = open(os.path.join(request.folder, "VERSION"), "r").read()
# Database
sqlite_version = None
mysql_version = None
mysqldb_version = None
pgsql_version = None
psycopg_version = None
if db_string.find("sqlite") != -1:
try:
import sqlite3
sqlite_version = sqlite3.version
except:
sqlite_version = T("Unknown")
elif db_string.find("mysql") != -1:
try:
import MySQLdb
mysqldb_version = MySQLdb.__revision__
except:
mysqldb_version = T("Not installed or incorrectly configured.")
mysql_version = T("Unknown")
else:
#mysql_version = (subprocess.Popen(["mysql", "--version"], stdout=subprocess.PIPE).communicate()[0]).rstrip()[10:]
con = MySQLdb.connect(host=settings.database.get("host", "localhost"),
port=settings.database.get("port", None) or 3306,
db=settings.database.get("database", "sahana"),
user=settings.database.get("username", "sahana"),
passwd=settings.database.get("password", "password")
)
cur = con.cursor()
cur.execute("SELECT VERSION()")
mysql_version = cur.fetchone()
else:
# Postgres
try:
import psycopg2
psycopg_version = psycopg2.__version__
except:
psycopg_version = T("Not installed or incorrectly configured.")