forked from sahana/eden
/
msg.py
2234 lines (1905 loc) · 78.7 KB
/
msg.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 -*-
"""
Messaging Module - Controllers
"""
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 """
module_name = settings.modules[module].name_nice
response.title = module_name
return dict(module_name=module_name)
# -----------------------------------------------------------------------------
def basestation():
""" RESTful CRUD controller for Base Stations """
return s3_rest_controller()
# =============================================================================
def compose():
""" Compose a Message which can be sent to a pentity via a number of different communications channels """
return msg.compose()
# =============================================================================
def message():
"""
RESTful CRUD controller for the master message log
"""
tablename = "msg_message"
table = s3db.msg_message
table.instance_type.readable = True
table.instance_type.label = T("Channel")
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Message Details"),
title_list = T("Message Log"),
label_list_button = T("View Message Log"),
msg_list_empty = T("No Messages currently in the Message Log")
)
def postp(r, output):
if r.interactive:
# Normal Action Buttons
s3_action_buttons(r)
# Custom Action Buttons
s3.actions += [dict(label=str(T("Mark Sender")),
_class="action-btn",
url=URL(f="mark_sender",
args="[id]")),
]
return output
s3.postp = postp
s3db.configure(tablename,
deletable = False,
editable = False,
insertable = False,
)
return s3_rest_controller()
# =============================================================================
def mark_sender():
"""
Assign priority to the given sender
"""
try:
mid = request.args[0]
except:
raise SyntaxError
mtable = s3db.msg_message
stable = s3db.msg_sender
# @ToDo: Replace 2 queries with Join
srecord = db(mtable.id == mid).select(mtable.from_address,
limitby=(0, 1)
).first()
sender = srecord.from_address
record = db(stable.sender == sender).select(stable.id,
limitby=(0, 1)
).first()
if record:
args = "update"
else:
args = "create"
url = URL(f="sender", args=args, vars=dict(sender=sender))
redirect(url)
# =============================================================================
def outbox():
""" View the contents of the Outbox """
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_outbox"
table = s3db[tablename]
table.message_id.label = T("Message")
table.message_id.writable = False
table.message_id.readable = True
table.pe_id.readable = True
table.pe_id.label = T("Recipient")
table.message_id.represent = s3db.msg_message_represent
table.pe_id.represent = s3db.pr_PersonEntityRepresent(default_label="")
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Message Details"),
title_list = T("Outbox"),
label_list_button = T("View Outbox"),
label_delete_button = T("Delete Message"),
msg_record_deleted = T("Message deleted"),
msg_list_empty = T("No Messages currently in Outbox")
)
def postp(r, output):
if isinstance(output, dict):
add_btn = A(T("Compose"),
_class="action-btn",
_href=URL(f="compose")
)
output["rheader"] = add_btn
return output
s3.postp = postp
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
)
return s3_rest_controller()
# -----------------------------------------------------------------------------
def email_outbox():
"""
RESTful CRUD controller for the Email Outbox
- all Outbound Email Messages are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_email"
table = s3db.msg_email
s3.filter = (table.inbound == False)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Email Details"),
title_list = T("Sent Emails"),
label_list_button = T("View Sent Emails"),
label_delete_button = T("Delete Email"),
msg_record_deleted = T("Email deleted"),
msg_list_empty = T("No Emails currently in Outbox")
)
def postp(r, output):
if isinstance(output, dict):
add_btn = A(T("Compose"),
_class="action-btn",
_href=URL(f="compose")
)
output["rheader"] = add_btn
return output
s3.postp = postp
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
listadd = False,
list_fields = ["id",
"date",
"to_address",
"subject",
"body",
],
)
return s3_rest_controller(module, "email")
# -----------------------------------------------------------------------------
def facebook_outbox():
"""
RESTful CRUD controller for the Facebook Outbox
- all Outbound Facebook Messages are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_facebook"
table = s3db.msg_facebook
s3.filter = (table.inbound == False)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Post Details"),
title_list = T("Sent Posts"),
label_list_button = T("View Sent Posts"),
label_delete_button = T("Delete Post"),
msg_record_deleted = T("Post deleted"),
msg_list_empty = T("No Posts currently in Outbox")
)
#def postp(r, output):
# if isinstance(output, dict):
# add_btn = A(T("Compose"),
# _class="action-btn",
# _href=URL(f="compose")
# )
# output["rheader"] = add_btn
# return output
#s3.postp = postp
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
listadd = False,
list_fields = ["id",
"date",
#"to_address",
"body",
],
)
return s3_rest_controller(module, "facebook")
# -----------------------------------------------------------------------------
def sms_outbox():
"""
RESTful CRUD controller for the SMS Outbox
- all sent SMS are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_sms"
table = s3db.msg_sms
s3.filter = (table.inbound == False)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("SMS Details"),
title_list = T("Sent SMS"),
label_list_button = T("View Sent SMS"),
label_delete_button = T("Delete SMS"),
msg_record_deleted = T("SMS deleted"),
msg_list_empty = T("No SMS currently in Outbox")
)
def postp(r, output):
if isinstance(output, dict):
add_btn = A(T("Compose"),
_class="action-btn",
_href=URL(f="compose")
)
output["rheader"] = add_btn
return output
s3.postp = postp
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
listadd = False,
list_fields = ["id",
"date",
"to_address",
"body",
],
)
return s3_rest_controller(module, "sms")
# -----------------------------------------------------------------------------
def twitter_outbox():
"""
RESTful CRUD controller for the Twitter Outbox
- all sent Tweets are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_twitter"
table = s3db.msg_twitter
s3.filter = (table.inbound == False)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Tweet Details"),
title_list = T("Sent Tweets"),
label_list_button = T("View Sent Tweets"),
label_delete_button = T("Delete Tweet"),
msg_record_deleted = T("Tweet deleted"),
msg_list_empty = T("No Tweets currently in Outbox")
)
def postp(r, output):
if isinstance(output, dict):
add_btn = A(T("Compose"),
_class="action-btn",
_href=URL(f="compose")
)
output["rheader"] = add_btn
return output
s3.postp = postp
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
listadd = False,
list_fields = ["id",
"date",
"to_address",
"body",
],
)
return s3_rest_controller(module, "twitter")
# =============================================================================
def inbox():
"""
RESTful CRUD controller for the Inbox
- all Inbound Messages are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
table = s3db.msg_message
s3.filter = (table.inbound == True)
table.inbound.readable = False
tablename = "msg_message"
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Message Details"),
title_list = T("InBox"),
label_list_button = T("View InBox"),
label_delete_button = T("Delete Message"),
msg_record_deleted = T("Message deleted"),
msg_list_empty = T("No Messages currently in InBox")
)
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
list_fields = ["id",
"date",
"channel_id",
"from_address",
"body",
],
)
return s3_rest_controller(module, "message")
# -----------------------------------------------------------------------------
def email_inbox():
"""
RESTful CRUD controller for the Email Inbox
- all Inbound Email Messages are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
s3.filter = (FS("inbound") == True)
from s3 import S3SQLCustomForm, S3SQLInlineComponent
crud_form = S3SQLCustomForm("date",
"subject",
"from_address",
"body",
S3SQLInlineComponent(
"attachment",
name = "document_id",
label = T("Attachments"),
fields = ["document_id",
],
),
)
tablename = "msg_email"
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Email Details"),
title_list = T("Email InBox"),
label_list_button = T("View Email InBox"),
label_delete_button = T("Delete Email"),
msg_record_deleted = T("Email deleted"),
msg_list_empty = T("No Emails currently in InBox")
)
s3db.configure(tablename,
crud_form = crud_form,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
list_fields = ["id",
"date",
"from_address",
"subject",
"body",
(T("Attachments"), "attachment.document_id"),
],
)
def prep(r):
s3db.msg_email.inbound.readable = False
if r.id:
s3db.msg_attachment.document_id.label = ""
return True
s3.prep = prep
return s3_rest_controller(module, "email")
# =============================================================================
def rss():
"""
RESTful CRUD controller for RSS feed posts
"""
if not auth.s3_has_role(ADMIN):
session.error = ERROR.UNAUTHORISED
redirect(URL(f="index"))
tablename = "msg_rss"
table = s3db.msg_rss
# To represent the description suitably
# If it is an image display an image
#table.description.represent = lambda description: HTML(description)
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("RSS Post Details"),
title_list = T("RSS Posts"),
label_list_button = T("View RSS Posts"),
label_delete_button = T("Delete Post"),
msg_record_deleted = T("RSS Post deleted"),
msg_list_empty = T("No Posts available")
)
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
list_fields = ["id",
"date",
"body",
],
)
return s3_rest_controller()
# -----------------------------------------------------------------------------
def sms_inbox():
"""
RESTful CRUD controller for the SMS Inbox
- all Inbound SMS Messages go here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_sms"
table = s3db[tablename]
s3.filter = (table.inbound == True)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("SMS Details"),
title_list = T("SMS InBox"),
label_list_button = T("View SMS InBox"),
label_delete_button = T("Delete SMS"),
msg_record_deleted = T("SMS deleted"),
msg_list_empty = T("No SMS currently in InBox")
)
s3db.configure(tablename,
# Permissions-based
#deletable = False,
editable = False,
insertable = False,
list_fields = ["id",
"date",
"from_address",
"body",
],
)
return s3_rest_controller(module, "sms")
# -----------------------------------------------------------------------------
def twitter():
"""
Twitter RESTful Controller
@ToDo: Action Button to update async
"""
s3db.configure("msg_twitter",
editable = False,
insertable = False,
list_fields = ["id",
"date",
"from_address",
"to_address",
"body",
],
)
return s3_rest_controller()
# -----------------------------------------------------------------------------
def twitter_inbox():
"""
RESTful CRUD controller for the Twitter Inbox
- all Inbound Tweets (Directed Messages) are visible here
"""
if not auth.s3_logged_in():
session.error = T("Requires Login!")
redirect(URL(c="default", f="user", args="login"))
tablename = "msg_twitter"
table = s3db.msg_twitter
s3.filter = (table.inbound == True)
table.inbound.readable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Tweet Details"),
title_list = T("Twitter InBox"),
label_list_button = T("View Twitter InBox"),
label_delete_button = T("Delete Tweet"),
msg_record_deleted = T("Tweet deleted"),
msg_list_empty = T("No Tweets currently in InBox")
)
s3db.configure(tablename,
editable = False,
insertable = False,
list_fields = ["id",
"date",
"from_address",
"body",
],
)
return s3_rest_controller(module, "twitter")
# =============================================================================
def tropo():
"""
Receive a JSON POST from the Tropo WebAPI
@see: https://www.tropo.com/docs/webapi/newhowitworks.htm
"""
# Stored in modules/tropo.py
from tropo import Tropo, Session
try:
s = Session(request.body.read())
t = Tropo()
# This is their service contacting us, so parse their request
try:
row_id = s.parameters["row_id"]
# This is an Outbound message which we've requested Tropo to send for us
table = s3db.msg_tropo_scratch
query = (table.row_id == row_id)
row = db(query).select().first()
# Send the message
#t.message(say_obj={"say":{"value":row.message}},to=row.recipient,network=row.network)
t.call(to=row.recipient, network=row.network)
t.say(row.message)
# Update status to sent in Outbox
outbox = s3db.msg_outbox
db(outbox.id == row.row_id).update(status=2)
# @ToDo: Set message log to actioned
#log = s3db.msg_log
#db(log.id == row.message_id).update(actioned=True)
# Clear the Scratchpad
db(query).delete()
return t.RenderJson()
except:
# This is an Inbound message
try:
message = s.initialText
# This is an SMS/IM
# Place it in the InBox
uuid = s.id
recipient = s.to["id"]
try:
fromaddress = s.fromaddress["id"]
except:
# SyntaxError: s.from => invalid syntax (why!?)
fromaddress = ""
# @ToDo: Update to new model
#s3db.msg_log.insert(uuid=uuid, fromaddress=fromaddress,
# recipient=recipient, message=message,
# inbound=True)
# Send the message to the parser
reply = msg.parse_message(message)
t.say([reply])
return t.RenderJson()
except:
# This is a Voice call
# - we can't handle these yet
raise HTTP(501)
except:
# GET request or some random POST
pass
# =============================================================================
@auth.s3_requires_membership(1)
def sms_outbound_gateway():
""" SMS Outbound Gateway selection for the messaging framework """
# CRUD Strings
s3.crud_strings["msg_sms_outbound_gateway"] = Storage(
label_create=T("Create SMS Outbound Gateway"),
title_display=T("SMS Outbound Gateway Details"),
title_list=T("SMS Outbound Gateways"),
title_update=T("Edit SMS Outbound Gateway"),
label_list_button=T("List SMS Outbound Gateways"),
label_delete_button=T("Delete SMS Outbound Gateway"),
msg_record_created=T("SMS Outbound Gateway added"),
msg_record_modified=T("SMS Outbound Gateway updated"),
msg_record_deleted=T("SMS Outbound Gateway deleted"),
msg_list_empty=T("No SMS Outbound Gateways currently registered"))
return s3_rest_controller()
# -----------------------------------------------------------------------------
def channel():
"""
RESTful CRUD controller for Channels
- unused
"""
return s3_rest_controller()
# -----------------------------------------------------------------------------
def email_channel():
"""
RESTful CRUD controller for Inbound Email channels
- appears in the administration menu
"""
if not auth.s3_has_role(ADMIN):
session.error = ERROR.UNAUTHORISED
redirect(URL(f="index"))
tablename = "msg_email_channel"
table = s3db[tablename]
table.server.label = T("Server")
table.protocol.label = T("Protocol")
table.use_ssl.label = "SSL"
table.port.label = T("Port")
table.username.label = T("Username")
table.password.label = T("Password")
table.delete_from_server.label = T("Delete from Server?")
table.port.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("Port"),
T("For POP-3 this is usually 110 (995 for SSL), for IMAP this is usually 143 (993 for IMAP).")))
table.delete_from_server.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("Delete"),
T("If this is set to True then mails will be deleted from the server after downloading.")))
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Email Settings"),
title_list = T("Email Accounts"),
label_create = T("Add Email Account"),
title_update = T("Edit Email Settings"),
label_list_button = T("View Email Accounts"),
msg_record_created = T("Account added"),
msg_record_deleted = T("Email Account deleted"),
msg_list_empty = T("No Accounts currently defined"),
msg_record_modified = T("Email Settings updated")
)
def postp(r, output):
if r.interactive:
# Normal Action Buttons
s3_action_buttons(r)
# Custom Action Buttons for Enable/Disable
table = r.table
query = (table.deleted == False)
rows = db(query).select(table.id,
table.enabled,
)
restrict_e = [str(row.id) for row in rows if not row.enabled]
restrict_d = [str(row.id) for row in rows if row.enabled]
s3.actions += [dict(label=str(T("Enable")),
_class="action-btn",
url=URL(args=["[id]", "enable"]),
restrict = restrict_e),
dict(label=str(T("Disable")),
_class="action-btn",
url = URL(args = ["[id]", "disable"]),
restrict = restrict_d),
]
if not s3task._is_alive():
# No Scheduler Running
s3.actions += [dict(label=str(T("Poll")),
_class="action-btn",
url = URL(args = ["[id]", "poll"]),
restrict = restrict_d)
]
return output
s3.postp = postp
return s3_rest_controller()
# -----------------------------------------------------------------------------
def facebook_channel():
"""
RESTful CRUD controller for Facebook channels
- appears in the administration menu
"""
if not auth.s3_has_role(ADMIN):
session.error = ERROR.UNAUTHORISED
redirect(URL(f="index"))
tablename = "msg_facebook_channel"
table = s3db[tablename]
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Facebook Settings"),
title_list = T("Facebook Accounts"),
label_create = T("Add Facebook Account"),
title_update = T("Edit Facebook Settings"),
label_list_button = T("View Facebook Accounts"),
msg_record_created = T("Account added"),
msg_record_deleted = T("Facebook Account deleted"),
msg_list_empty = T("No Accounts currently defined"),
msg_record_modified = T("Facebook Settings updated")
)
def postp(r, output):
if r.interactive:
# Normal Action Buttons
s3_action_buttons(r)
# Custom Action Buttons for Enable/Disable
table = r.table
query = (table.deleted == False)
rows = db(query).select(table.id,
table.enabled,
)
restrict_e = [str(row.id) for row in rows if not row.enabled]
restrict_d = [str(row.id) for row in rows if row.enabled]
s3.actions += [dict(label=str(T("Enable")),
_class="action-btn",
url=URL(args=["[id]", "enable"]),
restrict = restrict_e),
dict(label=str(T("Disable")),
_class="action-btn",
url = URL(args = ["[id]", "disable"]),
restrict = restrict_d),
]
#if not s3task._is_alive():
# # No Scheduler Running
# s3.actions += [dict(label=str(T("Poll")),
# _class="action-btn",
# url = URL(args = ["[id]", "poll"]),
# restrict = restrict_d)
# ]
return output
s3.postp = postp
return s3_rest_controller()
# -----------------------------------------------------------------------------
def mcommons_channel():
"""
RESTful CRUD controller for Mobile Commons SMS Channels
- appears in the administration menu
"""
if not auth.s3_has_role(ADMIN):
session.error = ERROR.UNAUTHORISED
redirect(URL(f="index"))
tablename = "msg_mcommons_channel"
table = s3db[tablename]
table.name.label = T("Account Name")
table.name.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("Account Name"),
T("Name for your Mobile Commons Account")))
table.campaign_id.label = T("Campaign ID")
table.url.label = T("URL")
table.url.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("URL"),
T("URL for the Mobile Commons API")))
table.username.label = T("Username")
table.password.label = T("Password")
table.timestmp.label = T("Last Downloaded")
table.timestmp.writable = False
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("Mobile Commons Setting Details"),
title_list = T("Mobile Commons Settings"),
label_create = T("Add Mobile Commons Settings"),
title_update = T("Edit Mobile Commons Settings"),
label_list_button = T("View Mobile Commons Settings"),
msg_record_created = T("Mobile Commons Setting added"),
msg_record_deleted = T("Mobile Commons Setting deleted"),
msg_list_empty = T("No Mobile Commons Settings currently defined"),
msg_record_modified = T("Mobile Commons settings updated")
)
def postp(r, output):
if r.interactive:
# Normal Action Buttons
s3_action_buttons(r)
# Custom Action Buttons for Enable/Disable
table = r.table
query = (table.deleted == False)
rows = db(query).select(table.id,
table.enabled,
)
restrict_e = [str(row.id) for row in rows if not row.enabled]
restrict_d = [str(row.id) for row in rows if row.enabled]
s3.actions += [dict(label=str(T("Enable")),
_class="action-btn",
url=URL(args=["[id]", "enable"]),
restrict = restrict_e),
dict(label=str(T("Disable")),
_class="action-btn",
url = URL(args = ["[id]", "disable"]),
restrict = restrict_d),
]
if not s3task._is_alive():
# No Scheduler Running
s3.actions += [dict(label=str(T("Poll")),
_class="action-btn",
url = URL(args = ["[id]", "poll"]),
restrict = restrict_d)
]
return output
s3.postp = postp
return s3_rest_controller()
# -----------------------------------------------------------------------------
def rss_channel():
"""
RESTful CRUD controller for RSS channels
- appears in the administration menu
"""
if not auth.s3_has_role(ADMIN):
session.error = ERROR.UNAUTHORISED
redirect(URL(f="index"))
tablename = "msg_rss_channel"
table = s3db[tablename]
table.name.label = T("Name")
table.description.label = T("Description")
table.url.label = T("URL/Link")
table.url.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("URL"),
T("Link for the RSS Feed.")))
table.enabled.comment = DIV(_class="tooltip",
_title="%s|%s" % (T("Subscriptions Status"),
T("Are you susbscribed?")))
# CRUD Strings
s3.crud_strings[tablename] = Storage(
title_display = T("RSS Channel Details"),
title_list = T("RSS Channels"),
label_create = T("Add RSS Channel"),
title_update = T("Edit RSS Channel"),
label_list_button = T("View RSS Channels"),
msg_record_created = T("Channel added"),
msg_record_deleted = T("RSS Channel deleted"),
msg_list_empty = T("No RSS Channels currently defined"),
msg_record_modified = T("RSS Channel updated"))
def status_represent(v):
try:
v = int(v)
except:
# Text
return v
return "There have been no new entries for %s requests" % v
s3db.msg_channel_status.status.represent = status_represent
def postp(r, output):
if r.interactive:
# Normal Action Buttons
s3_action_buttons(r)
# Custom Action Buttons for Enable/Disable
table = r.table
query = (table.deleted == False)
rows = db(query).select(table.id,
table.enabled,
)
restrict_e = [str(row.id) for row in rows if not row.enabled]
restrict_d = [str(row.id) for row in rows if row.enabled]
s3.actions += [dict(label=str(T("Subscribe")),
_class="action-btn",
url=URL(args=["[id]", "enable"]),
restrict = restrict_e),
dict(label=str(T("Unsubscribe")),
_class="action-btn",
url = URL(args = ["[id]", "disable"]),
restrict = restrict_d),
]
if not s3task._is_alive():
# No Scheduler Running
s3.actions += [dict(label=str(T("Poll")),
_class="action-btn",
url = URL(args = ["[id]", "poll"]),
restrict = restrict_d)
]
return output
s3.postp = postp
return s3_rest_controller()
# -----------------------------------------------------------------------------
def twilio_channel():
"""
RESTful CRUD controller for Twilio SMS channels
- appears in the administration menu
"""