From 586dba0081c2004a4b790a478a9cd4f86019d6d8 Mon Sep 17 00:00:00 2001 From: khitab-incubyte <81683192+khitab-incubyte@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:42:26 +0530 Subject: [PATCH 1/2] Fix for return in elig/else. --- hasjob/views/listing.py | 118 ++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 3f247eb4..12ce4199 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1025,55 +1025,55 @@ def confirm_email(domain, hashid, key): '403.html.jinja2', description="This link has expired or is malformed. Check if you have received a newer email from us.", ) - else: - if app.config.get('THROTTLE_LIMIT', 0) > 0: - post_count = ( - JobPost.query.filter(JobPost.email_domain == post.email_domain) - .filter(~(JobPost.state.UNPUBLISHED)) - .filter(JobPost.datetime > utcnow() - timedelta(days=1)) - .count() - ) - if post_count > app.config['THROTTLE_LIMIT']: - flash( - "We have received too many posts with %s addresses in the last 24 hours. " - "Posts are rate-limited per domain, so yours was not confirmed for now. " - "Please try confirming again in a few hours." - % post.email_domain, - category='info', - ) - return redirect(url_for('index')) - post.confirm() - db.session.commit() - if app.config['TWITTER_ENABLED']: - if post.headlineb: - tweet.queue( - post.headline, - post.url_for(b=0, _external=True), - post.location, - dict(post.parsed_location or {}), - username=post.twitter, - ) - tweet.queue( - post.headlineb, - post.url_for(b=1, _external=True), - post.location, - dict(post.parsed_location or {}), - username=post.twitter, - ) - else: - tweet.queue( - post.headline, - post.url_for(_external=True), - post.location, - dict(post.parsed_location or {}), - username=post.twitter, - ) - add_to_boards.queue(post.id) - flash( - "Congratulations! Your job post has been published. As a bonus for being an employer on Hasjob, " - "you can now see how your post is performing relative to others. Look in the footer of any post.", - "interactive", + + if app.config.get('THROTTLE_LIMIT', 0) > 0: + post_count = ( + JobPost.query.filter(JobPost.email_domain == post.email_domain) + .filter(~(JobPost.state.UNPUBLISHED)) + .filter(JobPost.datetime > utcnow() - timedelta(days=1)) + .count() ) + if post_count > app.config['THROTTLE_LIMIT']: + flash( + "We have received too many posts with %s addresses in the last 24 hours. " + "Posts are rate-limited per domain, so yours was not confirmed for now. " + "Please try confirming again in a few hours." + % post.email_domain, + category='info', + ) + return redirect(url_for('index')) + post.confirm() + db.session.commit() + if app.config['TWITTER_ENABLED']: + if post.headlineb: + tweet.queue( + post.headline, + post.url_for(b=0, _external=True), + post.location, + dict(post.parsed_location or {}), + username=post.twitter, + ) + tweet.queue( + post.headlineb, + post.url_for(b=1, _external=True), + post.location, + dict(post.parsed_location or {}), + username=post.twitter, + ) + else: + tweet.queue( + post.headline, + post.url_for(_external=True), + post.location, + dict(post.parsed_location or {}), + username=post.twitter, + ) + add_to_boards.queue(post.id) + flash( + "Congratulations! Your job post has been published. As a bonus for being an employer on Hasjob, " + "you can now see how your post is performing relative to others. Look in the footer of any post.", + "interactive", + ) # cache bust # dogpile.invalidate_region('hasjob_index') return redirect(post.url_for(), code=302) @@ -1196,10 +1196,10 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None): return redirect( post.url_for('edit', subdomain=blink.board.name, _external=True) ) - else: - return redirect( - post.url_for('edit', subdomain=None, _external=True) - ) + + return redirect( + post.url_for('edit', subdomain=None, _external=True) + ) # Don't allow email address to be changed once it's confirmed if not post.state.UNPUBLISHED: @@ -1373,10 +1373,10 @@ def newjob(): " We'll add details about your company later", ) ) - else: - if g.user.blocked: - flash("Your account has been blocked from posting jobs", category='info') - return redirect(url_for('index'), code=303) + + if g.user.blocked: + flash("Your account has been blocked from posting jobs", category='info') + return redirect(url_for('index'), code=303) if g.board: if 'new-job' not in g.board.permissions(g.user): @@ -1430,9 +1430,9 @@ def newjob(): return editjob( hashid=None, key=None, form=form, validated=True, newpost=newpost ) - elif form.errors: - # POST request from new job page, with errors - flash("Please review the indicated issues", category='interactive') + + # POST request from new job page, with errors + flash("Please review the indicated issues", category='interactive') # Render page. Execution reaches here under three conditions: # 1. GET request, page loaded for the first time From b41eec8319d10769000953683d8918fa2d8b90c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Oct 2021 16:16:57 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hasjob/views/listing.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 12ce4199..e9566957 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1037,8 +1037,7 @@ def confirm_email(domain, hashid, key): flash( "We have received too many posts with %s addresses in the last 24 hours. " "Posts are rate-limited per domain, so yours was not confirmed for now. " - "Please try confirming again in a few hours." - % post.email_domain, + "Please try confirming again in a few hours." % post.email_domain, category='info', ) return redirect(url_for('index')) @@ -1197,9 +1196,7 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None): post.url_for('edit', subdomain=blink.board.name, _external=True) ) - return redirect( - post.url_for('edit', subdomain=None, _external=True) - ) + return redirect(post.url_for('edit', subdomain=None, _external=True)) # Don't allow email address to be changed once it's confirmed if not post.state.UNPUBLISHED: