-
Notifications
You must be signed in to change notification settings - Fork 542
/
Copy pathcontrollers.py
2223 lines (2083 loc) · 118 KB
/
controllers.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
# share/controllers.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-
from django.db.models import F
from django.utils.timezone import now
from .models import ShareManager
from analytics.models import ACTION_VIEW_SHARED_BALLOT, ACTION_VIEW_SHARED_BALLOT_ALL_OPINIONS, \
ACTION_VIEW_SHARED_CANDIDATE, ACTION_VIEW_SHARED_CANDIDATE_ALL_OPINIONS, \
ACTION_VIEW_SHARED_CHALLENGE, \
ACTION_VIEW_SHARED_MEASURE, ACTION_VIEW_SHARED_MEASURE_ALL_OPINIONS, \
ACTION_VIEW_SHARED_OFFICE, ACTION_VIEW_SHARED_OFFICE_ALL_OPINIONS, \
ACTION_VIEW_SHARED_ORGANIZATION, ACTION_VIEW_SHARED_ORGANIZATION_ALL_OPINIONS, \
ACTION_VIEW_SHARED_READY, ACTION_VIEW_SHARED_READY_ALL_OPINIONS, \
AnalyticsManager
from follow.models import FOLLOWING, FollowOrganizationManager
import json
from organization.models import OrganizationManager
from position.models import PositionListManager
import robot_detection
from share.models import SharedItem, SharedLinkClicked, SharedPermissionsGranted, \
VoterWhoSharesSummaryAllTime, VoterWhoSharesSummaryOneYear
from voter.models import VoterDeviceLinkManager, VoterManager, Voter
import wevote_functions.admin
from wevote_functions.functions import convert_to_int, positive_value_exists
from wevote_functions.functions_date import DATE_FORMAT_YMD_HMS
from wevote_settings.models import WeVoteSetting, WeVoteSettingsManager
INDIVIDUAL = 'I' # One person
# TODO: If longer than 10 or so ballot items, return office/measure data in a second API call
BALLOT_SHARED_ITEM_CUTOFF = 1000
logger = wevote_functions.admin.get_logger(__name__)
def move_shared_items_to_another_voter(from_voter_we_vote_id, to_voter_we_vote_id,
from_organization_we_vote_id, to_organization_we_vote_id):
status = ''
success = True
shared_item_entries_moved = 0
shared_item_entries_not_moved = 0
if not positive_value_exists(from_voter_we_vote_id) or not positive_value_exists(to_voter_we_vote_id):
status += "MOVE_SHARED_ITEMS-MISSING_EITHER_FROM_OR_TO_VOTER_WE_VOTE_ID "
success = False
results = {
'status': status,
'success': success,
'from_voter_we_vote_id': from_voter_we_vote_id,
'to_voter_we_vote_id': to_voter_we_vote_id,
'shared_item_entries_moved': shared_item_entries_moved,
'shared_item_entries_not_moved': shared_item_entries_not_moved,
}
return results
if from_voter_we_vote_id == to_voter_we_vote_id:
status += "MOVE_SHARED_ITEMS-FROM_AND_TO_VOTER_WE_VOTE_IDS_IDENTICAL "
success = False
results = {
'status': status,
'success': success,
'from_voter_we_vote_id': from_voter_we_vote_id,
'to_voter_we_vote_id': to_voter_we_vote_id,
'shared_item_entries_moved': shared_item_entries_moved,
'shared_item_entries_not_moved': shared_item_entries_not_moved,
}
return results
# ######################
# Migrations
if positive_value_exists(to_organization_we_vote_id):
try:
shared_item_entries_moved += SharedItem.objects\
.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id)\
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id,
shared_by_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_ITEM-SHARED_BY_VOTER_WE_VOTE_ID-INCLUDING_ORG: " + str(e) + " "
success = False
try:
SharedLinkClicked.objects.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id,
shared_by_organization_we_vote_id=to_organization_we_vote_id)
SharedLinkClicked.objects.filter(viewed_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(viewed_by_voter_we_vote_id=to_voter_we_vote_id,
viewed_by_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_LINK_CLICKED-SHARED_BY_VOTER_WE_VOTE_ID-INCLUDING_ORG: " + str(e) + " "
success = False
try:
SharedPermissionsGranted.objects.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id,
shared_by_organization_we_vote_id=to_organization_we_vote_id)
SharedPermissionsGranted.objects.filter(shared_to_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_to_voter_we_vote_id=to_voter_we_vote_id,
shared_to_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_PERMISSIONS_GRANTED-SHARED_BY_VOTER_WE_VOTE_ID-INCLUDING_ORG: " + str(e) + " "
success = False
else:
try:
SharedItem.objects.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id)\
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_ITEM-SHARED_BY_VOTER_WE_VOTE_ID: " + str(e) + " "
success = False
try:
SharedLinkClicked.objects.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id)
SharedLinkClicked.objects.filter(viewed_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(viewed_by_voter_we_vote_id=to_voter_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_LINK_CLICKED-SHARED_BY_VOTER_WE_VOTE_ID: " + str(e) + " "
success = False
try:
SharedPermissionsGranted.objects.filter(shared_by_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_by_voter_we_vote_id=to_voter_we_vote_id)
SharedPermissionsGranted.objects.filter(shared_to_voter_we_vote_id=from_voter_we_vote_id) \
.update(shared_to_voter_we_vote_id=to_voter_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_PERMISSIONS_GRANTED-SHARED_BY_VOTER_WE_VOTE_ID: " + str(e) + " "
success = False
if positive_value_exists(from_organization_we_vote_id) and positive_value_exists(to_organization_we_vote_id):
try:
SharedItem.objects.filter(site_owner_organization_we_vote_id=from_organization_we_vote_id) \
.update(site_owner_organization_we_vote_id=to_organization_we_vote_id)
SharedItem.objects.filter(shared_by_organization_we_vote_id=from_organization_we_vote_id) \
.update(shared_by_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_ITEM-SITE_OWNER_ORGANIZATION_WE_VOTE_ID: " + str(e) + " "
success = False
try:
SharedLinkClicked.objects.filter(shared_by_organization_we_vote_id=from_organization_we_vote_id) \
.update(shared_by_organization_we_vote_id=to_organization_we_vote_id)
SharedLinkClicked.objects.filter(viewed_by_organization_we_vote_id=from_organization_we_vote_id) \
.update(viewed_by_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_LINK_CLICKED-SHARED_BY_ORGANIZATION_WE_VOTE_ID: " + str(e) + " "
success = False
try:
SharedPermissionsGranted.objects\
.filter(shared_by_organization_we_vote_id=from_organization_we_vote_id) \
.update(shared_by_organization_we_vote_id=to_organization_we_vote_id)
SharedPermissionsGranted.objects\
.filter(shared_to_organization_we_vote_id=from_organization_we_vote_id) \
.update(shared_to_organization_we_vote_id=to_organization_we_vote_id)
except Exception as e:
status += "FAILED-SHARED_PERMISSIONS_GRANTED-SHARED_BY_ORGANIZATION_WE_VOTE_ID: " + str(e) + " "
success = False
else:
status += "MOVE_SHARED_ITEMS-MISSING_EITHER_FROM_OR_TO_ORGANIZATION_WE_VOTE_ID "
results = {
'status': status,
'success': success,
'from_voter_we_vote_id': from_voter_we_vote_id,
'to_voter_we_vote_id': to_voter_we_vote_id,
'shared_item_entries_moved': shared_item_entries_moved,
'shared_item_entries_not_moved': shared_item_entries_not_moved,
}
return results
def shared_item_list_save_for_api( # sharedItemListSave
voter_device_id='',
destination_full_url='',
ballot_item_we_vote_id='',
google_civic_election_id=0,
is_ballot_share=False,
is_candidate_share=False,
is_measure_share=False,
is_office_share=False,
is_organization_share=False,
is_ready_share=False,
is_remind_contact_share=False,
other_voter_email_address_array=None,
shared_message=None):
status = ''
success = True
candidate_we_vote_id = ''
date_first_shared = None
hostname = ''
measure_we_vote_id = ''
office_we_vote_id = ''
shared_by_display_name = None
shared_by_first_name = None
shared_by_last_name = None
shared_by_organization_type = ''
shared_by_organization_we_vote_id = ''
shared_by_voter_we_vote_id = ''
shared_by_we_vote_hosted_profile_image_url_large = None
shared_by_we_vote_hosted_profile_image_url_medium = None
shared_by_we_vote_hosted_profile_image_url_tiny = None
shared_item_code_no_opinions = ''
shared_item_code_all_opinions = ''
site_owner_organization_we_vote_id = ''
url_with_shared_item_code_no_opinions = destination_full_url # Default to this
url_with_shared_item_code_all_opinions = destination_full_url # Default to this
voter = None
voter_manager = VoterManager()
voter_results = voter_manager.retrieve_voter_from_voter_device_id(voter_device_id, read_only=True)
if voter_results['voter_found']:
voter = voter_results['voter']
if positive_value_exists(voter.first_name):
shared_by_first_name = voter.first_name
if positive_value_exists(voter.last_name):
shared_by_last_name = voter.last_name
shared_by_voter_we_vote_id = voter.we_vote_id
shared_by_organization_we_vote_id = voter.linked_organization_we_vote_id
shared_by_organization_type = INDIVIDUAL
organization_manager = OrganizationManager()
try:
hostname = destination_full_url.strip().lower()
hostname = hostname.replace('http://', '')
hostname = hostname.replace('https://', '')
if '/' in hostname:
hostname_array = hostname.split('/')
hostname = hostname_array[0]
results = organization_manager.retrieve_organization_from_incoming_hostname(hostname, read_only=True)
status += results['status']
organization_found = results['organization_found']
if organization_found:
organization = results['organization']
site_owner_organization_we_vote_id = organization.we_vote_id
except Exception as e:
status += "COULD_NOT_MODIFY_HOSTNAME: " + str(e) + " "
success = False
if positive_value_exists(ballot_item_we_vote_id):
if "cand" in ballot_item_we_vote_id:
candidate_we_vote_id = ballot_item_we_vote_id
elif "meas" in ballot_item_we_vote_id:
measure_we_vote_id = ballot_item_we_vote_id
elif "off" in ballot_item_we_vote_id:
office_we_vote_id = ballot_item_we_vote_id
required_variables_for_new_entry = positive_value_exists(destination_full_url) \
and positive_value_exists(shared_by_voter_we_vote_id) \
and other_voter_email_address_array and len(other_voter_email_address_array) > 0
if not required_variables_for_new_entry or not success:
if positive_value_exists(is_remind_contact_share):
status += "REMIND_CONTACT_SHARED_ITEM_LIST_REQUIRED_VARIABLES_MISSING "
else:
status += "SHARED_ITEM_LIST_SAVE_REQUIRED_VARIABLES_MISSING "
results = {
'status': status,
'success': False,
'candidate_we_vote_id': candidate_we_vote_id,
'date_first_shared': date_first_shared,
'destination_full_url': destination_full_url,
'google_civic_election_id': google_civic_election_id,
'is_ballot_share': is_ballot_share,
'is_candidate_share': is_candidate_share,
'is_measure_share': is_measure_share,
'is_office_share': is_office_share,
'is_organization_share': is_organization_share,
'is_ready_share': is_ready_share,
'is_remind_contact_share': is_remind_contact_share,
'measure_we_vote_id': measure_we_vote_id,
'office_we_vote_id': office_we_vote_id,
'other_voter_email_address_array': other_voter_email_address_array,
'shared_by_display_name': shared_by_display_name,
'shared_by_first_name': shared_by_first_name,
'shared_by_last_name': shared_by_last_name,
'shared_by_organization_type': shared_by_organization_type,
'shared_by_organization_we_vote_id': shared_by_organization_we_vote_id,
'shared_by_voter_we_vote_id': shared_by_voter_we_vote_id,
'shared_by_we_vote_hosted_profile_image_url_large': shared_by_we_vote_hosted_profile_image_url_large,
'shared_by_we_vote_hosted_profile_image_url_medium': shared_by_we_vote_hosted_profile_image_url_medium,
'shared_by_we_vote_hosted_profile_image_url_tiny': shared_by_we_vote_hosted_profile_image_url_tiny,
'shared_item_code_no_opinions': shared_item_code_no_opinions,
'shared_item_code_all_opinions': shared_item_code_all_opinions,
'shared_message': shared_message,
'site_owner_organization_we_vote_id': site_owner_organization_we_vote_id,
'url_with_shared_item_code_no_opinions': url_with_shared_item_code_no_opinions,
'url_with_shared_item_code_all_opinions': url_with_shared_item_code_all_opinions,
}
return results
share_manager = ShareManager()
if positive_value_exists(shared_by_organization_we_vote_id):
results = organization_manager.retrieve_organization_from_we_vote_id(
organization_we_vote_id=shared_by_organization_we_vote_id,
read_only=True)
if results['success'] and results['organization_found']:
shared_by_display_name = None
if positive_value_exists(results['organization'].organization_name) \
and 'Voter-' not in results['organization'].organization_name:
shared_by_display_name = results['organization'].organization_name
shared_by_we_vote_hosted_profile_image_url_large = \
results['organization'].we_vote_hosted_profile_image_url_large
shared_by_we_vote_hosted_profile_image_url_medium = \
results['organization'].we_vote_hosted_profile_image_url_medium
shared_by_we_vote_hosted_profile_image_url_tiny = \
results['organization'].we_vote_hosted_profile_image_url_tiny
error_message_to_show_voter = ''
number_of_messages_sent = 0
success_message_to_show_voter = ''
for other_voter_email_address_text in other_voter_email_address_array:
one_result = shared_item_save_for_api(
voter,
destination_full_url=destination_full_url,
ballot_item_we_vote_id=ballot_item_we_vote_id,
google_civic_election_id=google_civic_election_id,
is_ballot_share=is_ballot_share,
is_candidate_share=is_candidate_share,
is_measure_share=is_measure_share,
is_office_share=is_office_share,
is_organization_share=is_organization_share,
is_ready_share=is_ready_share,
is_remind_contact_share=is_remind_contact_share,
# organization_we_vote_id=organization_we_vote_id,
# other_voter_display_name=other_voter_display_name,
# other_voter_first_name=other_voter_first_name,
# other_voter_last_name=other_voter_last_name,
# other_voter_we_vote_id=other_voter_we_vote_id,
other_voter_email_address_text=other_voter_email_address_text,
shared_message=shared_message,
)
number_of_messages_sent += one_result['number_of_messages_sent']
if hasattr(one_result, 'success_message_to_show_voter') \
and positive_value_exists(one_result['success_message_to_show_voter']):
success_message_to_show_voter += one_result['success_message_to_show_voter']
if hasattr(one_result, 'error_message_to_show_voter') \
and positive_value_exists(one_result['error_message_to_show_voter']):
error_message_to_show_voter += one_result['error_message_to_show_voter']
results = {
'status': status,
'success': success,
'candidate_we_vote_id': candidate_we_vote_id,
'date_first_shared': date_first_shared,
'destination_full_url': destination_full_url,
'error_message_to_show_voter': error_message_to_show_voter,
'google_civic_election_id': google_civic_election_id,
'is_ballot_share': is_ballot_share,
'is_candidate_share': is_candidate_share,
'is_measure_share': is_measure_share,
'is_office_share': is_office_share,
'is_organization_share': is_organization_share,
'is_ready_share': is_ready_share,
'is_remind_contact_share': is_remind_contact_share,
'measure_we_vote_id': measure_we_vote_id,
'number_of_messages_sent': number_of_messages_sent,
'office_we_vote_id': office_we_vote_id,
'other_voter_email_address_array': other_voter_email_address_array,
'shared_by_display_name': shared_by_display_name,
'shared_by_first_name': shared_by_first_name,
'shared_by_last_name': shared_by_last_name,
'shared_by_organization_type': shared_by_organization_type,
'shared_by_organization_we_vote_id': shared_by_organization_we_vote_id,
'shared_by_voter_we_vote_id': shared_by_voter_we_vote_id,
'shared_by_we_vote_hosted_profile_image_url_large': shared_by_we_vote_hosted_profile_image_url_large,
'shared_by_we_vote_hosted_profile_image_url_medium': shared_by_we_vote_hosted_profile_image_url_medium,
'shared_by_we_vote_hosted_profile_image_url_tiny': shared_by_we_vote_hosted_profile_image_url_tiny,
'shared_item_code_no_opinions': shared_item_code_no_opinions,
'shared_item_code_all_opinions': shared_item_code_all_opinions,
'site_owner_organization_we_vote_id': site_owner_organization_we_vote_id,
'success_message_to_show_voter': success_message_to_show_voter,
'url_with_shared_item_code_no_opinions': url_with_shared_item_code_no_opinions,
'url_with_shared_item_code_all_opinions': url_with_shared_item_code_all_opinions,
}
return results
def shared_item_retrieve_for_api( # sharedItemRetrieve
voter_device_id='',
destination_full_url='',
shared_item_code='',
shared_item_clicked=False,
user_agent_string='',
user_agent_object=None):
status = ''
success = True
candidate_we_vote_id = ''
date_first_shared = None
hostname = ''
include_friends_only_positions = False
is_ballot_share = False
is_candidate_share = False
is_challenge_share = False
is_measure_share = False
is_office_share = False
is_organization_share = False
is_ready_share = False
is_remind_contact_share = False
google_civic_election_id = ''
measure_we_vote_id = ''
office_we_vote_id = ''
other_voter_display_name = ''
other_voter_email_address_text = ''
other_voter_first_name = ''
other_voter_last_name = ''
other_voter_we_vote_id = ''
api_call_coming_from_voter_who_shared = False
email_secret_key = ''
sms_secret_key = ''
shared_by_display_name = ''
shared_by_first_name = ''
shared_by_last_name = ''
shared_by_voter_we_vote_id = ''
shared_by_organization_type = ''
shared_by_organization_we_vote_id = ''
shared_by_we_vote_hosted_profile_image_url_large = ''
shared_by_we_vote_hosted_profile_image_url_medium = ''
shared_by_we_vote_hosted_profile_image_url_tiny = ''
shared_item_code_no_opinions = ''
shared_item_code_all_opinions = ''
shared_message = ''
site_owner_organization_we_vote_id = ''
url_with_shared_item_code_no_opinions = ''
url_with_shared_item_code_all_opinions = ''
viewed_by_voter_we_vote_id = ''
viewed_by_organization_we_vote_id = ''
voter_id = 0
is_signed_in = False
error_results = {
'status': status,
'success': False,
'candidate_we_vote_id': candidate_we_vote_id,
'date_first_shared': date_first_shared,
'destination_path_backup': '/ready',
'destination_full_url': destination_full_url,
'destination_full_url_override': '',
'email_secret_key': email_secret_key,
'google_civic_election_id': google_civic_election_id,
'include_friends_only_positions': include_friends_only_positions,
'is_ballot_share': is_ballot_share,
'is_candidate_share': is_candidate_share,
'is_challenge_share': is_challenge_share,
'is_measure_share': is_measure_share,
'is_office_share': is_office_share,
'is_organization_share': is_organization_share,
'is_ready_share': is_ready_share,
'is_remind_contact_share': is_remind_contact_share,
'measure_we_vote_id': measure_we_vote_id,
'office_we_vote_id': office_we_vote_id,
'other_voter_email_address_text': other_voter_email_address_text,
'other_voter_display_name': other_voter_display_name,
'other_voter_first_name': other_voter_first_name,
'other_voter_last_name': other_voter_last_name,
'other_voter_we_vote_id': other_voter_we_vote_id,
'shared_by_display_name': shared_by_display_name,
'shared_by_first_name': shared_by_first_name,
'shared_by_last_name': shared_by_last_name,
'shared_by_voter_we_vote_id': shared_by_voter_we_vote_id,
'shared_by_organization_type': shared_by_organization_type,
'shared_by_organization_we_vote_id': shared_by_organization_we_vote_id,
'shared_by_we_vote_hosted_profile_image_url_large': shared_by_we_vote_hosted_profile_image_url_large,
'shared_by_we_vote_hosted_profile_image_url_medium': shared_by_we_vote_hosted_profile_image_url_medium,
'shared_by_we_vote_hosted_profile_image_url_tiny': shared_by_we_vote_hosted_profile_image_url_tiny,
'shared_item_code': shared_item_code,
'shared_item_code_no_opinions': shared_item_code_no_opinions,
'shared_item_code_all_opinions': shared_item_code_all_opinions,
'shared_message': shared_message,
'site_owner_organization_we_vote_id': site_owner_organization_we_vote_id,
'sms_secret_key': sms_secret_key,
'url_with_shared_item_code_no_opinions': url_with_shared_item_code_no_opinions,
'url_with_shared_item_code_all_opinions': url_with_shared_item_code_all_opinions,
}
share_manager = ShareManager()
voter_manager = VoterManager()
voter_results = voter_manager.retrieve_voter_from_voter_device_id(voter_device_id, read_only=True)
if voter_results['voter_found']:
voter = voter_results['voter']
voter_id = voter.id
viewed_by_voter_we_vote_id = voter.we_vote_id
viewed_by_organization_we_vote_id = voter.linked_organization_we_vote_id
is_signed_in = voter.is_signed_in()
results = share_manager.retrieve_shared_item(
destination_full_url=destination_full_url,
shared_by_voter_we_vote_id=viewed_by_voter_we_vote_id,
shared_item_code=shared_item_code,
read_only=True)
status += results['status']
if not results['shared_item_found']:
status += "SHARED_ITEM_NOT_FOUND_REDIRECT_TO_READY "
error_results['status'] = status
error_results['success'] = True
return error_results
shared_item = results['shared_item']
shared_item_id = shared_item.id
url_with_shared_item_code_no_opinions = ''
url_with_shared_item_code_all_opinions = ''
if positive_value_exists(shared_item.destination_full_url):
try:
hostname = shared_item.destination_full_url.strip().lower()
hostname = hostname.replace('http://', '')
hostname = hostname.replace('https://', '')
if '/' in hostname:
hostname_array = hostname.split('/')
hostname = hostname_array[0]
if positive_value_exists(hostname):
if shared_item.shared_item_code_no_opinions:
url_with_shared_item_code_no_opinions = \
"https://" + hostname + "/-" + shared_item.shared_item_code_no_opinions
if shared_item.shared_item_code_all_opinions:
url_with_shared_item_code_all_opinions = \
"https://" + hostname + "/-" + shared_item.shared_item_code_all_opinions
except Exception as e:
status += "COULD_NOT_MODIFY_HOSTNAME: " + str(e) + " "
destination_full_url_override = ''
if positive_value_exists(shared_item_code) and positive_value_exists(hostname):
if positive_value_exists(shared_item.shared_item_code_ready):
if shared_item_code == shared_item.shared_item_code_ready:
destination_full_url_override = "https://" + hostname + "/ready"
if positive_value_exists(shared_item.shared_item_code_remind_contacts):
if shared_item_code == shared_item.shared_item_code_remind_contacts:
destination_full_url_override = "https://" + hostname + "/friends/remind"
if viewed_by_voter_we_vote_id == shared_item.shared_by_voter_we_vote_id:
api_call_coming_from_voter_who_shared = True
# Store that the link was clicked
# TODO We need to adjust this since each shared item can contain the primary destination_full_url
# and secondary links
if positive_value_exists(shared_item_clicked) and not positive_value_exists(api_call_coming_from_voter_who_shared):
# At some point we may allow a distinction between sharing only your public opinions
# (as opposed to public AND friends only opinion). shared_item_code_public_opinions is not implemented yet.
include_public_positions = shared_item.shared_item_code_all_opinions == shared_item_code
include_friends_only_positions = shared_item.shared_item_code_all_opinions == shared_item_code
clicked_results = share_manager.create_shared_link_clicked(
destination_full_url=shared_item.destination_full_url,
shared_item_code=shared_item_code,
shared_item_id=shared_item_id,
shared_by_voter_we_vote_id=shared_item.shared_by_voter_we_vote_id,
shared_by_organization_type=shared_item.shared_by_organization_type,
shared_by_organization_we_vote_id=shared_item.shared_by_organization_we_vote_id,
site_owner_organization_we_vote_id=shared_item.site_owner_organization_we_vote_id,
viewed_by_voter_we_vote_id=viewed_by_voter_we_vote_id,
viewed_by_organization_we_vote_id=viewed_by_organization_we_vote_id,
include_public_positions=include_public_positions,
include_friends_only_positions=include_friends_only_positions,
)
status += clicked_results['status']
delete_secret_keys = False
# If an email or sms secret_key was stored in the SharedItem, we can use it to sign in the person clicking the
# link on the first click. After the first click, we delete both secret keys so subsequent clicks don't sign
# the person in.
if positive_value_exists(shared_item.email_secret_key):
email_secret_key = shared_item.email_secret_key
delete_secret_keys = True
if positive_value_exists(shared_item.sms_secret_key):
sms_secret_key = shared_item.sms_secret_key
delete_secret_keys = True
if delete_secret_keys:
# Retrieve again from main db so we can delete
retrieve_results_for_delete = share_manager.retrieve_shared_item(
shared_item_code=shared_item_code,
read_only=False)
status += results['status']
if retrieve_results_for_delete['shared_item_found']:
shared_item = retrieve_results_for_delete['shared_item']
try:
shared_item.email_secret_key = None
shared_item.sms_secret_key = None
shared_item.save()
except Exception as e:
status += "COULD_NOT_CLEAR_SECRET_KEYS: " + str(e) + " "
# Store the new permissions granted if the public or friends-only positions were shared
if positive_value_exists(include_public_positions) or positive_value_exists(include_friends_only_positions):
permission_results = share_manager.update_or_create_shared_permissions_granted(
shared_by_voter_we_vote_id=shared_item.shared_by_voter_we_vote_id,
shared_by_organization_type=shared_item.shared_by_organization_type,
shared_by_organization_we_vote_id=shared_item.shared_by_organization_we_vote_id,
shared_to_voter_we_vote_id=viewed_by_voter_we_vote_id,
shared_to_organization_we_vote_id=viewed_by_organization_we_vote_id,
google_civic_election_id=google_civic_election_id,
year_as_integer=shared_item.year_as_integer,
include_friends_only_positions=include_friends_only_positions,
)
status += permission_results['status']
# Auto follow this person/organization
if not api_call_coming_from_voter_who_shared:
follow_organization_manager = FollowOrganizationManager()
following_results = follow_organization_manager.toggle_voter_following_organization(
voter_id,
organization_id=0,
organization_we_vote_id=shared_item.shared_by_organization_we_vote_id,
organization_we_vote_id_that_is_following=viewed_by_organization_we_vote_id,
following_status=FOLLOWING)
status += following_results['status']
# Store analytics information when a Shared Item Code (sic) link was clicked
# Do not store if you are clicking your own link
if not api_call_coming_from_voter_who_shared:
is_bot = user_agent_object.is_bot or robot_detection.is_robot(user_agent_string)
analytics_manager = AnalyticsManager()
action_view_type = ''
# We want to see if we can get the google_civic_election_id from the voter_device_link (no guarantees)
voter_device_link_manager = VoterDeviceLinkManager()
results = voter_device_link_manager.retrieve_voter_device_link_from_voter_device_id(
voter_device_id, read_only=False) # From the live database since it may be the first link clicked
if results['voter_device_link_found']:
voter_device_link = results['voter_device_link']
clicked_google_civic_election_id = voter_device_link.google_civic_election_id
else:
clicked_google_civic_election_id = 0
if shared_item.is_ballot_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_BALLOT_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_BALLOT
elif shared_item.is_candidate_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_CANDIDATE_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_CANDIDATE
elif shared_item.is_challenge_share:
action_view_type = ACTION_VIEW_SHARED_CHALLENGE
elif shared_item.is_measure_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_MEASURE_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_MEASURE
elif shared_item.is_office_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_OFFICE_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_OFFICE
elif shared_item.is_organization_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_ORGANIZATION_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_ORGANIZATION
elif shared_item.is_ready_share:
if positive_value_exists(include_friends_only_positions):
action_view_type = ACTION_VIEW_SHARED_READY_ALL_OPINIONS
# elif positive_value_exists(include_public_positions): # Sharing only your public opinions
else:
action_view_type = ACTION_VIEW_SHARED_READY
if positive_value_exists(action_view_type):
analytics_results = analytics_manager.save_action(
action_constant=action_view_type,
voter_we_vote_id=viewed_by_voter_we_vote_id,
voter_id=voter_id,
is_signed_in=is_signed_in,
organization_we_vote_id=shared_item.shared_by_organization_we_vote_id,
google_civic_election_id=clicked_google_civic_election_id,
user_agent_string=user_agent_string,
is_bot=is_bot,
is_mobile=user_agent_object.is_mobile,
is_desktop=user_agent_object.is_pc,
is_tablet=user_agent_object.is_tablet,
)
status += analytics_results['status']
else:
# Shared item not clicked
pass
# If is_challenge share, update ChallengeInvitee.invite_viewed & ChallengeInvitee.invite_viewed_count
update_invitee_count = 0
if positive_value_exists(shared_item_clicked) and not positive_value_exists(api_call_coming_from_voter_who_shared):
challenge_we_vote_id_from_invitee = ''
inviter_voter_we_vote_id = ''
if shared_item.is_challenge_share and positive_value_exists(shared_item_code):
from challenge.models import ChallengeInvitee
try:
queryset = ChallengeInvitee.objects.all()
queryset = queryset.filter(invitee_url_code=shared_item_code)
update_invitee_count = queryset.update(
invite_viewed=True,
invite_viewed_count=F('invite_viewed_count') + 1,
date_invite_viewed=now())
if update_invitee_count > 0:
try:
refreshed_invitee = ChallengeInvitee.objects.get(invitee_url_code=shared_item_code)
challenge_we_vote_id_from_invitee = refreshed_invitee.challenge_we_vote_id
inviter_voter_we_vote_id = refreshed_invitee.inviter_voter_we_vote_id
except Exception as e:
status += "COULD_NOT_GET_REFRESHED_CHALLENGE_INVITEE: " + str(e) + " "
except Exception as e:
status += "CHALLENGE_INVITEE_UPDATE_FAILED: " + str(e) + " "
if update_invitee_count > 0 and \
positive_value_exists(challenge_we_vote_id_from_invitee) and \
positive_value_exists(inviter_voter_we_vote_id):
from challenge.controllers_participant import update_challenge_participant_with_invitee_stats
update_results = update_challenge_participant_with_invitee_stats(
challenge_we_vote_id=challenge_we_vote_id_from_invitee,
inviter_voter_we_vote_id=inviter_voter_we_vote_id,
)
status += update_results['status']
from challenge.controllers_participant import update_challenge_participant_with_invitees_who_viewed_plus
stats_results = update_challenge_participant_with_invitees_who_viewed_plus(
challenge_we_vote_id=challenge_we_vote_id_from_invitee,
inviter_voter_we_vote_id=inviter_voter_we_vote_id,
)
status += stats_results['status']
from challenge.controllers_scoring import refresh_participant_points_for_challenge
refresh_results = refresh_participant_points_for_challenge(
challenge_we_vote_id=challenge_we_vote_id_from_invitee,
voter_we_vote_id=inviter_voter_we_vote_id,
)
status += refresh_results['status']
ballot_item_list = []
candidate_position_list = []
if positive_value_exists(shared_item.shared_by_voter_we_vote_id) \
and shared_item.shared_item_code_all_opinions == shared_item_code:
position_list_manager = PositionListManager()
results = position_list_manager.retrieve_all_positions_for_voter_simple(
voter_we_vote_id=shared_item.shared_by_voter_we_vote_id,
count_only=True)
status += results['status']
if results['position_count'] < BALLOT_SHARED_ITEM_CUTOFF:
from ballot.controllers_ballot_shared import shared_item_ballot_retrieve_for_api
ballot_results = shared_item_ballot_retrieve_for_api( # sharedItemBallotRetrieve
shared_by_voter_we_vote_id=shared_item.shared_by_voter_we_vote_id)
ballot_item_list = ballot_results['ballot_item_list']
candidate_position_list = ballot_results['candidate_position_list']
else:
# We are going to retrieve in a follow-up API call
pass
other_voter_email_address_text = shared_item.other_voter_email_address_text \
if positive_value_exists(shared_item.other_voter_email_address_text) else ''
other_voter_display_name = shared_item.other_voter_display_name \
if positive_value_exists(shared_item.other_voter_display_name) else ''
other_voter_first_name = shared_item.other_voter_first_name \
if positive_value_exists(shared_item.other_voter_first_name) else ''
other_voter_last_name = shared_item.other_voter_last_name \
if positive_value_exists(shared_item.other_voter_last_name) else ''
other_voter_we_vote_id = shared_item.other_voter_we_vote_id \
if positive_value_exists(shared_item.other_voter_we_vote_id) else ''
shared_by_display_name = shared_item.shared_by_display_name \
if positive_value_exists(shared_item.shared_by_display_name) else ''
shared_by_first_name = shared_item.shared_by_first_name \
if positive_value_exists(shared_item.shared_by_first_name) else ''
shared_by_last_name = shared_item.shared_by_last_name \
if positive_value_exists(shared_item.shared_by_last_name) else ''
shared_by_we_vote_hosted_profile_image_url_large = shared_item.shared_by_we_vote_hosted_profile_image_url_large \
if positive_value_exists(shared_item.shared_by_we_vote_hosted_profile_image_url_large) else ''
shared_by_we_vote_hosted_profile_image_url_medium = shared_item.shared_by_we_vote_hosted_profile_image_url_medium \
if positive_value_exists(shared_item.shared_by_we_vote_hosted_profile_image_url_medium) else ''
shared_by_we_vote_hosted_profile_image_url_tiny = shared_item.shared_by_we_vote_hosted_profile_image_url_tiny \
if positive_value_exists(shared_item.shared_by_we_vote_hosted_profile_image_url_tiny) else ''
if positive_value_exists(shared_item.date_first_shared):
date_first_shared = shared_item.date_first_shared.strftime(DATE_FORMAT_YMD_HMS) # '%Y-%m-%d %H:%M:%S'
results = {
'status': status,
'success': success,
'ballot_item_list': ballot_item_list,
'candidate_position_list': candidate_position_list,
'destination_full_url': shared_item.destination_full_url,
'destination_full_url_override': destination_full_url_override,
'email_secret_key': email_secret_key, # Only returned on first click
'is_ballot_share': shared_item.is_ballot_share,
'is_candidate_share': shared_item.is_candidate_share,
'is_challenge_share': shared_item.is_challenge_share,
'is_measure_share': shared_item.is_measure_share,
'is_office_share': shared_item.is_office_share,
'is_organization_share': shared_item.is_organization_share,
'is_ready_share': shared_item.is_ready_share,
'is_remind_contact_share': shared_item.is_remind_contact_share,
'include_friends_only_positions': include_friends_only_positions,
'google_civic_election_id': shared_item.google_civic_election_id,
'other_voter_email_address_text': other_voter_email_address_text,
'other_voter_display_name': other_voter_display_name,
'other_voter_first_name': other_voter_first_name,
'other_voter_last_name': other_voter_last_name,
'other_voter_we_vote_id': other_voter_we_vote_id,
'shared_by_display_name': shared_by_display_name,
'shared_by_first_name': shared_by_first_name,
'shared_by_last_name': shared_by_last_name,
'shared_by_organization_type': shared_item.shared_by_organization_type,
'shared_by_organization_we_vote_id': shared_item.shared_by_organization_we_vote_id,
'shared_by_voter_we_vote_id': shared_item.shared_by_voter_we_vote_id,
'shared_by_we_vote_hosted_profile_image_url_large': shared_by_we_vote_hosted_profile_image_url_large,
'shared_by_we_vote_hosted_profile_image_url_medium': shared_by_we_vote_hosted_profile_image_url_medium,
'shared_by_we_vote_hosted_profile_image_url_tiny': shared_by_we_vote_hosted_profile_image_url_tiny,
'shared_message': shared_item.shared_message,
'site_owner_organization_we_vote_id': shared_item.site_owner_organization_we_vote_id,
'sms_secret_key': sms_secret_key, # Only returned on first click
'candidate_we_vote_id': shared_item.candidate_we_vote_id,
'measure_we_vote_id': shared_item.measure_we_vote_id,
'office_we_vote_id': shared_item.office_we_vote_id,
'date_first_shared': str(date_first_shared),
}
if api_call_coming_from_voter_who_shared:
results['shared_item_code_no_opinions'] = shared_item.shared_item_code_no_opinions
results['shared_item_code_all_opinions'] = shared_item.shared_item_code_all_opinions
results['shared_item_code_challenge'] = shared_item.shared_item_code_challenge
results['shared_item_code_ready'] = shared_item.shared_item_code_ready
results['shared_item_code_remind_contacts'] = shared_item.shared_item_code_remind_contacts
results['url_with_shared_item_code_no_opinions'] = url_with_shared_item_code_no_opinions
results['url_with_shared_item_code_all_opinions'] = url_with_shared_item_code_all_opinions
else:
# If here we don't want to reveal the other shared_item codes
if shared_item.shared_item_code_no_opinions == shared_item_code:
results['shared_item_code_no_opinions'] = shared_item.shared_item_code_no_opinions
results['url_with_shared_item_code_no_opinions'] = url_with_shared_item_code_no_opinions
else:
results['shared_item_code_no_opinions'] = ''
results['url_with_shared_item_code_no_opinions'] = ''
if shared_item.shared_item_code_all_opinions == shared_item_code:
results['shared_item_code_all_opinions'] = shared_item.shared_item_code_all_opinions
results['url_with_shared_item_code_all_opinions'] = url_with_shared_item_code_all_opinions
else:
results['shared_item_code_all_opinions'] = ''
results['url_with_shared_item_code_all_opinions'] = ''
if shared_item.shared_item_code_challenge == shared_item_code:
results['shared_item_code_challenge'] = shared_item.shared_item_code_challenge
else:
results['shared_item_code_challenge'] = ''
if shared_item.shared_item_code_ready == shared_item_code:
results['shared_item_code_ready'] = shared_item.shared_item_code_ready
else:
results['shared_item_code_ready'] = ''
if shared_item.shared_item_code_remind_contacts == shared_item_code:
results['shared_item_code_remind_contacts'] = shared_item.shared_item_code_remind_contacts
else:
results['shared_item_code_remind_contacts'] = ''
return results
def shared_item_save_for_api( # sharedItemSave
voter=None,
voter_device_id='',
destination_full_url='',
ballot_item_we_vote_id='',
google_civic_election_id=0,
is_ballot_share=False,
is_candidate_share=False,
is_measure_share=False,
is_office_share=False,
is_organization_share=False,
is_ready_share=False,
is_remind_contact_share=False,
organization_we_vote_id='',
other_voter_display_name='',
other_voter_first_name='',
other_voter_last_name='',
other_voter_we_vote_id='',
other_voter_email_address_text=None,
shared_message=None):
status = ''
success = True
candidate_we_vote_id = ''
date_first_shared = None
hostname = ''
measure_we_vote_id = ''
number_of_messages_sent = 0
office_we_vote_id = ''
ready_page_url_using_shared_item_code = ''
remind_contacts_url_using_shared_item_code = ''
shared_by_display_name = None
shared_by_first_name = None
shared_by_last_name = None
shared_by_organization_type = ''
shared_by_organization_we_vote_id = ''
shared_by_voter_we_vote_id = ''
shared_by_we_vote_hosted_profile_image_url_large = None
shared_by_we_vote_hosted_profile_image_url_medium = None
shared_by_we_vote_hosted_profile_image_url_tiny = None
shared_item_code_no_opinions = ''
shared_item_code_all_opinions = ''
site_owner_organization_we_vote_id = ''
url_with_shared_item_code_no_opinions = destination_full_url # Default to this
url_with_shared_item_code_all_opinions = destination_full_url # Default to this
if voter and hasattr(voter, 'linked_organization_we_vote_id'):
shared_by_voter_we_vote_id = voter.we_vote_id
shared_by_organization_we_vote_id = voter.linked_organization_we_vote_id
shared_by_organization_type = INDIVIDUAL
else:
voter_manager = VoterManager()
voter_results = voter_manager.retrieve_voter_from_voter_device_id(voter_device_id, read_only=True)
if voter_results['voter_found']:
voter = voter_results['voter']
shared_by_voter_we_vote_id = voter.we_vote_id
shared_by_organization_we_vote_id = voter.linked_organization_we_vote_id
shared_by_organization_type = INDIVIDUAL
if voter and hasattr(voter, 'first_name'):
if positive_value_exists(voter.first_name):
shared_by_first_name = voter.first_name
if positive_value_exists(voter.last_name):
shared_by_last_name = voter.last_name
organization_manager = OrganizationManager()
try:
hostname = destination_full_url.strip().lower()
hostname = hostname.replace('http://', '')
hostname = hostname.replace('https://', '')
if '/' in hostname:
hostname_array = hostname.split('/')
hostname = hostname_array[0]
results = organization_manager.retrieve_organization_from_incoming_hostname(hostname, read_only=True)
status += results['status']
organization_found = results['organization_found']
if organization_found:
organization = results['organization']
site_owner_organization_we_vote_id = organization.we_vote_id
except Exception as e:
status += "COULD_NOT_MODIFY_HOSTNAME: " + str(e) + " "
success = False
if positive_value_exists(ballot_item_we_vote_id):
if "cand" in ballot_item_we_vote_id:
candidate_we_vote_id = ballot_item_we_vote_id
elif "meas" in ballot_item_we_vote_id:
measure_we_vote_id = ballot_item_we_vote_id
elif "off" in ballot_item_we_vote_id:
office_we_vote_id = ballot_item_we_vote_id
if positive_value_exists(is_remind_contact_share):
# destination_full_url is optional because by default we only use the
# built-in /ready and /friends/remind links
required_variables_for_new_entry = positive_value_exists(destination_full_url) \
and positive_value_exists(shared_by_voter_we_vote_id) \
and positive_value_exists(other_voter_email_address_text)
else:
required_variables_for_new_entry = positive_value_exists(destination_full_url) \
and positive_value_exists(shared_by_voter_we_vote_id)
if not required_variables_for_new_entry or not success:
if positive_value_exists(is_remind_contact_share):
status += "REMIND_CONTACT_SHARED_ITEM_REQUIRED_VARIABLES_MISSING "
else:
status += "SHARED_ITEM_SAVE_REQUIRED_VARIABLES_MISSING "
results = {
'status': status,
'success': False,
'candidate_we_vote_id': candidate_we_vote_id,
'date_first_shared': date_first_shared,
'destination_full_url': destination_full_url,
'google_civic_election_id': google_civic_election_id,
'is_ballot_share': is_ballot_share,
'is_candidate_share': is_candidate_share,
'is_measure_share': is_measure_share,
'is_office_share': is_office_share,
'is_organization_share': is_organization_share,
'is_ready_share': is_ready_share,
'is_remind_contact_share': is_remind_contact_share,
'measure_we_vote_id': measure_we_vote_id,
'number_of_messages_sent': number_of_messages_sent,
'office_we_vote_id': office_we_vote_id,
'other_voter_email_address_text': other_voter_email_address_text,
'other_voter_display_name': other_voter_display_name,
'other_voter_first_name': other_voter_first_name,
'other_voter_last_name': other_voter_last_name,
'other_voter_we_vote_id': other_voter_we_vote_id,
'shared_by_display_name': shared_by_display_name,
'shared_by_first_name': shared_by_first_name,
'shared_by_last_name': shared_by_last_name,
'shared_by_organization_type': shared_by_organization_type,
'shared_by_organization_we_vote_id': shared_by_organization_we_vote_id,
'shared_by_voter_we_vote_id': shared_by_voter_we_vote_id,
'shared_by_we_vote_hosted_profile_image_url_large': shared_by_we_vote_hosted_profile_image_url_large,
'shared_by_we_vote_hosted_profile_image_url_medium': shared_by_we_vote_hosted_profile_image_url_medium,
'shared_by_we_vote_hosted_profile_image_url_tiny': shared_by_we_vote_hosted_profile_image_url_tiny,
'shared_item_code_no_opinions': shared_item_code_no_opinions,
'shared_item_code_all_opinions': shared_item_code_all_opinions,
'shared_message': shared_message,
'site_owner_organization_we_vote_id': site_owner_organization_we_vote_id,
'url_with_shared_item_code_no_opinions': url_with_shared_item_code_no_opinions,
'url_with_shared_item_code_all_opinions': url_with_shared_item_code_all_opinions,
}
return results
share_manager = ShareManager()
if positive_value_exists(shared_by_organization_we_vote_id):
results = organization_manager.retrieve_organization_from_we_vote_id(
organization_we_vote_id=shared_by_organization_we_vote_id,
read_only=True)
if results['success'] and results['organization_found']:
shared_by_display_name = None
if positive_value_exists(results['organization'].organization_name) \
and 'Voter-' not in results['organization'].organization_name:
shared_by_display_name = results['organization'].organization_name
shared_by_we_vote_hosted_profile_image_url_large = \
results['organization'].we_vote_hosted_profile_image_url_large
shared_by_we_vote_hosted_profile_image_url_medium = \