Skip to content

Commit a4ff804

Browse files
committed
Added USE_ASYNC_FOR_EMAIL to settings
1 parent 36c3156 commit a4ff804

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

junction/proposals/comments_views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def create_proposal_comment(request, conference_slug, proposal_slug):
4141
)
4242
host = '{}://{}'.format(settings.SITE_PROTOCOL,
4343
request.META.get('HTTP_HOST'))
44-
send_mail_for_new_comment.delay(proposal_comment.id, host)
44+
45+
if settings.USE_ASYNC_FOR_EMAIL:
46+
send_mail_for_new_comment.delay(proposal_comment.id, host)
47+
else:
48+
send_mail_for_new_comment(proposal_comment.id, host)
4549

4650
redirect_url = reverse('proposal-detail',
4751
args=[conference.slug, proposal.slug])

junction/proposals/views.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ def create_proposal(request, conference_slug):
131131
proposal_type_id=form.cleaned_data['proposal_type'],
132132
proposal_section_id=form.cleaned_data['proposal_section'])
133133
host = '{}://{}'.format(settings.SITE_PROTOCOL, request.META.get('HTTP_HOST'))
134-
send_mail_for_new_proposal.delay(proposal.id, host)
134+
135+
if settings.USE_ASYNC_FOR_EMAIL:
136+
send_mail_for_new_proposal.delay(proposal.id, host)
137+
else:
138+
send_mail_for_new_proposal(proposal.id, host)
135139

136140
return HttpResponseRedirect(reverse('proposal-detail',
137141
args=[conference.slug, proposal.slug]))
@@ -387,9 +391,16 @@ def proposal_upload_content(request, conference_slug, slug):
387391
raise PermissionDenied
388392

389393
host = '{}://{}'.format(settings.SITE_PROTOCOL, request.META['HTTP_HOST'])
390-
send_mail_for_proposal_content.delay(conference.id, proposal.id, host)
391394

392-
message = 'Email sent successfully.'
395+
if settings.USE_ASYNC_FOR_EMAIL:
396+
send_mail_for_proposal_content.delay(conference.id, proposal.id, host)
397+
message = 'Email sent successfully.'
398+
else:
399+
response = send_mail_for_proposal_content(conference.id, proposal.id, host)
400+
if response == 1:
401+
message = 'Email sent successfully.'
402+
else:
403+
message = 'There is problem in sending mail. Please contact conference chair.'
393404

394405
return HttpResponse(message)
395406

settings/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,5 @@
247247
EXPLARA_API_TOKEN = "shjbalkfbdskjlbdskljbdskaljfb"
248248

249249
QR_CODES_DIR = ROOT_DIR + '/qr_files'
250+
251+
USE_ASYNC_FOR_EMAIL = False

settings/dev.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
INSTALLED_APPS += ('django_extensions',)
2727

2828
# settings for celery
29-
BROKER_URL = os.environ.get("BROKER_URL", "redis://127.0.0.1:6379/0")
30-
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", 'redis://127.0.0.1:6379/0')
29+
BROKER_URL = os.environ.get("BROKER_URL", "redis://redis:6379/0")
30+
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", 'redis://redis:6379/0')

settings/dev.py.sample

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DATABASES = {
1515
}
1616
}
1717

18-
ACCOUNT_DEFAULT_HTTP_PROTOCOL='http'
18+
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'http'
1919

2020
TEMPLATE_CONTEXT_PROCESSORS += (
2121
"django.core.context_processors.debug",
@@ -25,6 +25,6 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
2525

2626
INSTALLED_APPS += ('django_extensions',)
2727

28-
#settings for celery
29-
BROKER_URL = os.environ.get("BROKER_URL", "redis://redis:6379/0")
30-
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", 'redis://redis:6379/0')
28+
# settings for celery
29+
BROKER_URL = os.environ.get("BROKER_URL", "redis://127.0.0.1:6379/0")
30+
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", 'redis://127.0.0.1:6379/0')

0 commit comments

Comments
 (0)