99# Third Party Stuff
1010from django .conf import settings
1111from markdown2 import markdown
12+ from celery import shared_task
1213
1314# Junction Stuff
1415from junction .base .emailer import send_email
1516from junction .base .constants import ProposalStatus
1617
17- from .models import ProposalSection , ProposalSectionReviewer
18+ from .models import Proposal , ProposalComment , ProposalSection , ProposalSectionReviewer
19+ from junction .conferences .models import Conference
1820
1921logger = logging .getLogger (__name__ )
2022
2123
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+
2257def markdown_to_html (md ):
2358 """
2459 Convert given markdown to html.
@@ -28,7 +63,28 @@ def markdown_to_html(md):
2863 return markdown (md )
2964
3065
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 )
3288 proposal = proposal_comment .proposal
3389 login_url = '{}?next={}' .format (settings .LOGIN_URL , proposal .get_absolute_url ())
3490 send_to = comment_recipients (proposal_comment )
@@ -51,26 +107,9 @@ def send_mail_for_new_comment(proposal_comment, host):
51107 'comment_type' : comment_type })
52108
53109
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 )
74113 proposal_section = ProposalSection .objects .get (
75114 pk = proposal .proposal_section_id )
76115 send_to = [p .conference_reviewer .reviewer for p in
@@ -92,18 +131,13 @@ def send_mail_for_new_proposal(proposal, host):
92131 'login_url' : login_url })
93132
94133
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 ):
104136 """
105137 Send mail to proposal author to upload content for proposal.
106138 """
139+ conference = Conference .objects .get (id = conference_id )
140+ proposal = Proposal .objects .get (id = proposal_id )
107141 login_url = '{}?next={}' .format (settings .LOGIN_URL , proposal .get_absolute_url ())
108142 author = proposal .author
109143 author_name = author .get_full_name () or author .username
@@ -116,28 +150,3 @@ def send_mail_for_proposal_content(conference, proposal, host):
116150 }
117151 return send_email (to = author , template_dir = 'proposals/email/upload_content' ,
118152 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