9
9
# Third Party Stuff
10
10
from django .conf import settings
11
11
from markdown2 import markdown
12
+ from celery import shared_task
12
13
13
14
# Junction Stuff
14
15
from junction .base .emailer import send_email
15
16
from junction .base .constants import ProposalStatus
16
17
17
- from .models import ProposalSection , ProposalSectionReviewer
18
+ from .models import Proposal , ProposalComment , ProposalSection , ProposalSectionReviewer
19
+ from junction .conferences .models import Conference
18
20
19
21
logger = logging .getLogger (__name__ )
20
22
21
23
24
+ def _get_proposal_section_reviewers (proposal ):
25
+ proposal_reviewers = set (ProposalSectionReviewer .objects .filter (
26
+ proposal_section = proposal .proposal_section ))
27
+ recipients = {proposal_reviewer .conference_reviewer .reviewer
28
+ for proposal_reviewer in proposal_reviewers }
29
+ return recipients
30
+
31
+
32
+ def _arrange_proposals_by_section (proposal_qs ):
33
+ res = collections .defaultdict (list )
34
+ for proposal in proposal_qs :
35
+ res [proposal .proposal_section .name ].append (proposal )
36
+ return res
37
+
38
+
39
+ def group_proposals_by_reveiew_state (conf , state = 'reviewed' ):
40
+ reviewed_qs = conf .proposal_set .filter (
41
+ status = ProposalStatus .PUBLIC ).select_related (
42
+ 'proposal_type' , 'proposal_section' ,
43
+ 'proposalsection' ).filter (proposalcomment__private = True ,
44
+ proposalcomment__deleted = False )
45
+ if state == 'reviewed' :
46
+ proposal_qs = reviewed_qs .distinct ()
47
+ return _arrange_proposals_by_section (proposal_qs )
48
+ else :
49
+ ids = reviewed_qs .values_list ('id' ).distinct ()
50
+ qs = conf .proposal_set .filter (
51
+ status = ProposalStatus .PUBLIC ).select_related (
52
+ 'proposal_type' , 'proposal_section' ,
53
+ 'proposalsection' ).exclude (pk__in = ids )
54
+ return _arrange_proposals_by_section (qs )
55
+
56
+
22
57
def markdown_to_html (md ):
23
58
"""
24
59
Convert given markdown to html.
@@ -28,7 +63,28 @@ def markdown_to_html(md):
28
63
return markdown (md )
29
64
30
65
31
- def send_mail_for_new_comment (proposal_comment , host ):
66
+ def comment_recipients (proposal_comment ):
67
+ proposal = proposal_comment .proposal
68
+ if proposal_comment .reviewer :
69
+ recipients = _get_proposal_section_reviewers (
70
+ proposal = proposal )
71
+ elif proposal_comment .private :
72
+ recipients = _get_proposal_section_reviewers (
73
+ proposal = proposal )
74
+ recipients .add (proposal .author )
75
+ else :
76
+ recipients = {
77
+ comment .commenter
78
+ for comment in proposal .proposalcomment_set
79
+ .all ().select_related ('commenter' )}
80
+ recipients .add (proposal .author )
81
+
82
+ return recipients
83
+
84
+
85
+ @shared_task (ignore_result = True )
86
+ def send_mail_for_new_comment (proposal_comment_id , host ):
87
+ proposal_comment = ProposalComment .objects .get (id = proposal_comment_id )
32
88
proposal = proposal_comment .proposal
33
89
login_url = '{}?next={}' .format (settings .LOGIN_URL , proposal .get_absolute_url ())
34
90
send_to = comment_recipients (proposal_comment )
@@ -51,26 +107,9 @@ def send_mail_for_new_comment(proposal_comment, host):
51
107
'comment_type' : comment_type })
52
108
53
109
54
- def comment_recipients (proposal_comment ):
55
- proposal = proposal_comment .proposal
56
- if proposal_comment .reviewer :
57
- recipients = _get_proposal_section_reviewers (
58
- proposal = proposal )
59
- elif proposal_comment .private :
60
- recipients = _get_proposal_section_reviewers (
61
- proposal = proposal )
62
- recipients .add (proposal .author )
63
- else :
64
- recipients = {
65
- comment .commenter
66
- for comment in proposal .proposalcomment_set
67
- .all ().select_related ('commenter' )}
68
- recipients .add (proposal .author )
69
-
70
- return recipients
71
-
72
-
73
- def send_mail_for_new_proposal (proposal , host ):
110
+ @shared_task (ignore_result = True )
111
+ def send_mail_for_new_proposal (proposal_id , host ):
112
+ proposal = Proposal .objects .get (id = proposal_id )
74
113
proposal_section = ProposalSection .objects .get (
75
114
pk = proposal .proposal_section_id )
76
115
send_to = [p .conference_reviewer .reviewer for p in
@@ -92,18 +131,13 @@ def send_mail_for_new_proposal(proposal, host):
92
131
'login_url' : login_url })
93
132
94
133
95
- def _get_proposal_section_reviewers (proposal ):
96
- proposal_reviewers = set (ProposalSectionReviewer .objects .filter (
97
- proposal_section = proposal .proposal_section ))
98
- recipients = {proposal_reviewer .conference_reviewer .reviewer
99
- for proposal_reviewer in proposal_reviewers }
100
- return recipients
101
-
102
-
103
- def send_mail_for_proposal_content (conference , proposal , host ):
134
+ @shared_task (ignore_result = True )
135
+ def send_mail_for_proposal_content (conference_id , proposal_id , host ):
104
136
"""
105
137
Send mail to proposal author to upload content for proposal.
106
138
"""
139
+ conference = Conference .objects .get (id = conference_id )
140
+ proposal = Proposal .objects .get (id = proposal_id )
107
141
login_url = '{}?next={}' .format (settings .LOGIN_URL , proposal .get_absolute_url ())
108
142
author = proposal .author
109
143
author_name = author .get_full_name () or author .username
@@ -116,28 +150,3 @@ def send_mail_for_proposal_content(conference, proposal, host):
116
150
}
117
151
return send_email (to = author , template_dir = 'proposals/email/upload_content' ,
118
152
context = context )
119
-
120
-
121
- def group_proposals_by_reveiew_state (conf , state = 'reviewed' ):
122
- reviewed_qs = conf .proposal_set .filter (
123
- status = ProposalStatus .PUBLIC ).select_related (
124
- 'proposal_type' , 'proposal_section' ,
125
- 'proposalsection' ).filter (proposalcomment__private = True ,
126
- proposalcomment__deleted = False )
127
- if state == 'reviewed' :
128
- proposal_qs = reviewed_qs .distinct ()
129
- return _arrange_proposals_by_section (proposal_qs )
130
- else :
131
- ids = reviewed_qs .values_list ('id' ).distinct ()
132
- qs = conf .proposal_set .filter (
133
- status = ProposalStatus .PUBLIC ).select_related (
134
- 'proposal_type' , 'proposal_section' ,
135
- 'proposalsection' ).exclude (pk__in = ids )
136
- return _arrange_proposals_by_section (qs )
137
-
138
-
139
- def _arrange_proposals_by_section (proposal_qs ):
140
- res = collections .defaultdict (list )
141
- for proposal in proposal_qs :
142
- res [proposal .proposal_section .name ].append (proposal )
143
- return res
0 commit comments