From abd356326cff0bde51f9b069a3c4ba9de9c13e95 Mon Sep 17 00:00:00 2001 From: Owocki Date: Tue, 14 Jan 2020 10:17:06 -0700 Subject: [PATCH] DL code review --- app/marketing/mails.py | 5 +++-- app/townsquare/views.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/marketing/mails.py b/app/marketing/mails.py index b59c2c4b2f1..87766194b4d 100644 --- a/app/marketing/mails.py +++ b/app/marketing/mails.py @@ -393,8 +393,8 @@ def comment_email(comment, to_emails): subject = gettext("💬 New Comment") + cur_language = translation.get_language() for to_email in to_emails: - cur_language = translation.get_language() try: setup_lang(to_email) from_email = settings.CONTACT_EMAIL @@ -403,7 +403,8 @@ def comment_email(comment, to_emails): if not should_suppress_notification_email(to_email, 'comment'): send_mail(from_email, to_email, subject, text, html, categories=['transactional', func_name()]) finally: - translation.activate(cur_language) + pass + translation.activate(cur_language) def new_faucet_request(fr): diff --git a/app/townsquare/views.py b/app/townsquare/views.py index 1be4524787a..5c5b0a9dcec 100644 --- a/app/townsquare/views.py +++ b/app/townsquare/views.py @@ -190,15 +190,21 @@ def api(request, activity_id): is_debugging_offers = settings.DEBUG + +def get_offer_and_create_offer_action(profile, offer_id, what, do_not_allow_more_than_one_offeraction=False): + offer = Offer.objects.current().get(pk=offer_id) + if do_not_allow_more_than_one_offeraction and profile.offeractions.filter(what=what, offer=offer) and not is_debugging_offers: + raise Exception('already visited this offer') + OfferAction.objects.create(profile=profile, offer=offer, what=what) + return offer + + def offer_go(request, offer_id, offer_slug): try: - offer = Offer.objects.current().get(pk=offer_id) if not request.user.is_authenticated: return redirect('/login/github?next=' + request.get_full_path()) - if request.user.profile.offeractions.filter(what='go', offer=offer) and not is_debugging_offers: - raise Exception('already visited this offer') - OfferAction.objects.create(profile=request.user.profile, offer=offer, what='go') + offer = get_offer_and_create_offer_action(request.user.profile, offer_id, 'go', True) return redirect(offer.url) except: raise Http404 @@ -210,9 +216,7 @@ def offer_decline(request, offer_id, offer_slug): offer = Offer.objects.current().get(pk=offer_id) if not request.user.is_authenticated: return redirect('/login/github?next=' + request.get_full_path()) - if request.user.profile.offeractions.filter(what='decline', offer=offer) and not is_debugging_offers: - raise Exception('already visited this offer') - OfferAction.objects.create(profile=request.user.profile, offer=offer, what='decline') + offer = get_offer_and_create_offer_action(request.user.profile, offer_id, 'decline', True) return redirect('/') except: raise Http404