From e88abbfd0cadd64ac529f0af6a98a80f6481e2f1 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Mon, 12 Sep 2016 01:06:29 +0530 Subject: [PATCH 1/2] moved jobpost reporting POST part to a separate view --- hasjob/models/jobpost.py | 2 + hasjob/templates/inc/reportform.html | 2 +- hasjob/views/listing.py | 60 ++++++++++++++++------------ 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 90cfac799..950ce9caf 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -306,6 +306,8 @@ def url_for(self, action='view', _external=False, **kwargs): return url_for('editjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs) elif action == 'withdraw': return url_for('withdraw', hashid=self.hashid, domain=domain, _external=_external, **kwargs) + elif action == 'report': + return url_for('reportjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs) elif action == 'close': return url_for('close', hashid=self.hashid, domain=domain, _external=_external, **kwargs) elif action == 'reopen': diff --git a/hasjob/templates/inc/reportform.html b/hasjob/templates/inc/reportform.html index 7d2f0066e..4cc1f7653 100644 --- a/hasjob/templates/inc/reportform.html +++ b/hasjob/templates/inc/reportform.html @@ -1,5 +1,5 @@ {% from "baseframe/forms.html" import renderfield, ajaxform %} -
+ {{ reportform.hidden_tag() }} diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 5cf42ff84..09ae7d697 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -45,10 +45,10 @@ from hasjob.views.helper import gif1x1, cache_viewcounts, session_jobpost_ab, bgroup -@app.route('//', methods=('GET', 'POST'), subdomain='') -@app.route('//', methods=('GET', 'POST')) -@app.route('/view/', defaults={'domain': None}, methods=('GET', 'POST'), subdomain='') -@app.route('/view/', defaults={'domain': None}, methods=('GET', 'POST')) +@app.route('//', methods=('GET',), subdomain='') +@app.route('//', methods=('GET',)) +@app.route('/view/', defaults={'domain': None}, methods=('GET',), subdomain='') +@app.route('/view/', defaults={'domain': None}, methods=('GET',)) def jobdetail(domain, hashid): is_siteadmin = lastuser.has_permission('siteadmin') query = JobPost.fetch(hashid).options( @@ -111,6 +111,7 @@ def jobdetail(domain, hashid): reportform = forms.ReportForm(obj=report) reportform.report_code.choices = [(ob.id, ob.title) for ob in ReportCode.query.filter_by(public=True).order_by('seq')] + rejectform = forms.RejectForm() moderateform = forms.ModerateForm() if request.method == 'GET': @@ -120,27 +121,6 @@ def jobdetail(domain, hashid): else: pinnedform = forms.PinnedForm(obj=post) - if reportform.validate_on_submit(): - if g.user: - if report is None: - report = JobPostReport(post=post, user=g.user) - report.reportcode_id = reportform.report_code.data - report.ipaddr = request.environ['REMOTE_ADDR'] - report.useragent = request.user_agent.string - db.session.add(report) - db.session.commit() - if request.is_xhr: - return "

Thanks! This post has been flagged for review

" # FIXME: Ugh! - else: - flash("Thanks! This post has been flagged for review", "interactive") - else: - if request.is_xhr: - return "

You need to be logged in to report a post

" # FIXME: Ugh! - else: - flash("You need to be logged in to report a post", "interactive") - elif request.method == 'POST' and request.is_xhr: - return render_template('inc/reportform.html', reportform=reportform) - if post.company_url and post.status != POSTSTATUS.ANNOUNCEMENT: domain_mismatch = not base_domain_matches(post.company_url.lower(), post.email_domain.lower()) else: @@ -189,6 +169,36 @@ def job_related_posts(domain, hashid): related_posts=related_posts, is_siteadmin=is_siteadmin) +@app.route('///report', methods=('POST',), subdomain='') +@app.route('///report', methods=('POST',)) +@app.route('/report/', defaults={'domain': None}, methods=('POST',), subdomain='') +@app.route('/report/', defaults={'domain': None}, methods=('POST',)) +@lastuser.requires_login +def reportjob(domain, hashid): + is_siteadmin = lastuser.has_permission('siteadmin') + post = JobPost.fetch(hashid).options(db.load_only('id')).first_or_404() + + if g.user: + report = JobPostReport.query.filter_by(post=post, user=g.user).first() + else: + report = None + + reportform = forms.ReportForm(obj=report) + reportform.report_code.choices = [(ob.id, ob.title) for ob in ReportCode.query.filter_by(public=True).order_by('seq')] + + if reportform.validate_on_submit(): + if report is None: + report = JobPostReport(post=post, user=g.user) + report.reportcode_id = reportform.report_code.data + report.ipaddr = request.environ['REMOTE_ADDR'] + report.useragent = request.user_agent.string + db.session.add(report) + db.session.commit() + return "

Thanks! This post has been flagged for review

" # FIXME: Ugh! + else: + return render_template('inc/reportform.html', reportform=reportform) + + @app.route('///star', defaults={'domain': None}, methods=['POST'], subdomain='') @app.route('///star', defaults={'domain': None}, methods=['POST']) @app.route('/star/', defaults={'domain': None}, methods=['POST'], subdomain='') From b8e409217462a7db0ae7fc484808550350ca92ac Mon Sep 17 00:00:00 2001 From: Bibhas Date: Mon, 12 Sep 2016 01:12:08 +0530 Subject: [PATCH 2/2] removed unnecessary admin check --- hasjob/views/listing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 09ae7d697..de151963e 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -175,7 +175,6 @@ def job_related_posts(domain, hashid): @app.route('/report/', defaults={'domain': None}, methods=('POST',)) @lastuser.requires_login def reportjob(domain, hashid): - is_siteadmin = lastuser.has_permission('siteadmin') post = JobPost.fetch(hashid).options(db.load_only('id')).first_or_404() if g.user: