Skip to content

Commit

Permalink
DL code review
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki committed Jan 14, 2020
1 parent ded9e88 commit abd3563
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
18 changes: 11 additions & 7 deletions app/townsquare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit abd3563

Please sign in to comment.