From 997c933e22184846036fc9875bf6931386256864 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Wed, 10 Aug 2016 19:17:22 +0530 Subject: [PATCH 1/8] added DELETED status --- hasjob/models/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hasjob/models/__init__.py b/hasjob/models/__init__.py index f86f0d4e6..f3260b7dc 100644 --- a/hasjob/models/__init__.py +++ b/hasjob/models/__init__.py @@ -24,9 +24,10 @@ class POSTSTATUS: MODERATED = 8 # Moderated, needs edit ANNOUNCEMENT = 9 # Special announcement CLOSED = 10 # Not accepting applications, but publicly viewable + DELETED = 11 # For posts that are actually deleted, like in case of drafts UNPUBLISHED = (DRAFT, PENDING) - GONE = (REJECTED, WITHDRAWN, SPAM) + GONE = (REJECTED, WITHDRAWN, SPAM, DELETED) LISTED = (CONFIRMED, REVIEWED, ANNOUNCEMENT) POSTPENDING = (CONFIRMED, REVIEWED, REJECTED, WITHDRAWN, FLAGGED, SPAM, MODERATED, ANNOUNCEMENT) MY = (DRAFT, PENDING, CONFIRMED, REVIEWED, MODERATED, ANNOUNCEMENT, CLOSED) From a24705625c01240f58e3e6e08b5be31652caa9c4 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Fri, 12 Aug 2016 00:10:01 +0530 Subject: [PATCH 2/8] added delete endpoint and template to confirm --- hasjob/models/jobpost.py | 5 +++++ hasjob/templates/detail.html | 4 ++++ hasjob/views/listing.py | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 565128574..282b9b87e 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -264,6 +264,9 @@ def withdraw(self): def close(self): self.status = POSTSTATUS.CLOSED + def delete(self): + self.status = POSTSTATUS.DELETED + def confirm(self): self.status = POSTSTATUS.CONFIRMED @@ -292,6 +295,8 @@ def url_for(self, action='view', _external=False, **kwargs): return url_for('withdraw', 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 == 'delete': + return url_for('delete', hashid=self.hashid, domain=domain, _external=_external, **kwargs) elif action == 'reopen': return url_for('reopen', hashid=self.hashid, domain=domain, _external=_external, **kwargs) elif action == 'moderate': diff --git a/hasjob/templates/detail.html b/hasjob/templates/detail.html index cc0f79bd7..69a3b3478 100644 --- a/hasjob/templates/detail.html +++ b/hasjob/templates/detail.html @@ -152,6 +152,10 @@

What’s wrong with it?

   Withdraw this + {%- elif post.is_draft() %} + +    Delete this draft + {%- endif %} {%- if post.is_old() %} diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index aed4e9fc6..60299e51d 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1017,6 +1017,28 @@ def close(domain, hashid, key): return render_template("close.html", post=post, form=form) +@app.route('///delete', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') +@app.route('///delete', methods=('GET', 'POST'), defaults={'key': None}) +def delete(domain, hashid, key): + post = JobPost.get(hashid) + if not post: + abort(404) + if not post.admin_is(g.user): + abort(403) + if request.method == 'GET' and not post.is_draft(): + return redirect(post.url_for('jobdetail'), code=303) + if not post.is_draft(): + flash("Your job is not a draft. Please close or withdraw it.", "info") + return redirect(post.url_for(), code=303) + form = Form() + if form.validate_on_submit(): + post.delete() + post.closed_datetime = datetime.utcnow() + db.session.commit() + return redirect(post.url_for(), code=303) + return render_template("delete.html", post=post, form=form) + + @app.route('///reopen', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') @app.route('///reopen', methods=('GET', 'POST'), defaults={'key': None}) def reopen(domain, hashid, key): From fac0c605d5e38e1e82186d7a3dfdea8526911290 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Fri, 12 Aug 2016 00:10:32 +0530 Subject: [PATCH 3/8] added delete confirmation template --- hasjob/templates/delete.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 hasjob/templates/delete.html diff --git a/hasjob/templates/delete.html b/hasjob/templates/delete.html new file mode 100644 index 000000000..fcd84568e --- /dev/null +++ b/hasjob/templates/delete.html @@ -0,0 +1,20 @@ +{% extends "sheet.html" %} +{% from "baseframe/forms.html" import renderfield %} +{% block title %}{{ post.headline|e }}{% endblock %} +{% block content %} + +{% endblock %} From 030733de17f0adcae8600ad106317f6554e1b70e Mon Sep 17 00:00:00 2001 From: Bibhas Date: Wed, 24 Aug 2016 00:59:08 +0530 Subject: [PATCH 4/8] confirmation text change, redirecting to /my, setting closing datetime inside model method --- hasjob/models/jobpost.py | 2 ++ hasjob/templates/delete.html | 5 ++--- hasjob/views/listing.py | 13 ++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 282b9b87e..1fa491570 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -263,9 +263,11 @@ def withdraw(self): def close(self): self.status = POSTSTATUS.CLOSED + self.closed_datetime = datetime.utcnow() def delete(self): self.status = POSTSTATUS.DELETED + self.closed_datetime = datetime.utcnow() def confirm(self): self.status = POSTSTATUS.CONFIRMED diff --git a/hasjob/templates/delete.html b/hasjob/templates/delete.html index fcd84568e..dcecc103b 100644 --- a/hasjob/templates/delete.html +++ b/hasjob/templates/delete.html @@ -4,11 +4,10 @@ {% block content %}
-

Delete this draft job post?

+

Delete this draft?

{{ post.headline }}

- This draft will be deleted forever with no way to recover it. - You have to create a new job from scratch. + Deleted drafts will be gone forever, with no undo. Are you sure you want to delete?

{{ form.hidden_tag() }} diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 60299e51d..10533460f 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1011,31 +1011,26 @@ def close(domain, hashid, key): form = Form() if form.validate_on_submit(): post.close() - post.closed_datetime = datetime.utcnow() db.session.commit() return redirect(post.url_for(), code=303) return render_template("close.html", post=post, form=form) -@app.route('///delete', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') -@app.route('///delete', methods=('GET', 'POST'), defaults={'key': None}) -def delete(domain, hashid, key): +@app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') +@app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}) +def delete(hashid, key): post = JobPost.get(hashid) if not post: abort(404) if not post.admin_is(g.user): abort(403) - if request.method == 'GET' and not post.is_draft(): - return redirect(post.url_for('jobdetail'), code=303) if not post.is_draft(): - flash("Your job is not a draft. Please close or withdraw it.", "info") return redirect(post.url_for(), code=303) form = Form() if form.validate_on_submit(): post.delete() - post.closed_datetime = datetime.utcnow() db.session.commit() - return redirect(post.url_for(), code=303) + return redirect(url_for('my_posts'), code=303) return render_template("delete.html", post=post, form=form) From 4c7a661c3d804ad76f1a056091923719fc8b1a94 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Thu, 1 Sep 2016 01:57:43 +0530 Subject: [PATCH 5/8] only loading required fields for post --- hasjob/models/jobpost.py | 2 +- hasjob/views/listing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 619fd6e98..7352ce114 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -75,7 +75,7 @@ def has_starred_post(user, post): User.has_starred_post = has_starred_post -class JobPost(BaseMixin, db.Model): +class JobPost(BaseMixin, db.Model): __tablename__ = 'jobpost' # Metadata diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index e8dbac486..abafaa877 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1019,7 +1019,7 @@ def close(domain, hashid, key): @app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') @app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}) def delete(hashid, key): - post = JobPost.get(hashid) + post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id')).first_or_404() if not post: abort(404) if not post.admin_is(g.user): From e76b0c59919ea93611de336f53b27ffad669ed33 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Thu, 1 Sep 2016 02:07:17 +0530 Subject: [PATCH 6/8] also selecting status --- hasjob/views/listing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index abafaa877..7e33e12f0 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1019,7 +1019,7 @@ def close(domain, hashid, key): @app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}, subdomain='') @app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}) def delete(hashid, key): - post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id')).first_or_404() + post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id', 'status')).first_or_404() if not post: abort(404) if not post.admin_is(g.user): From 84221f43a628e7d1e09d52a37735f748fe7cf9e3 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Fri, 2 Sep 2016 17:40:05 +0530 Subject: [PATCH 7/8] removed extra space --- hasjob/models/jobpost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 7352ce114..619fd6e98 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -75,7 +75,7 @@ def has_starred_post(user, post): User.has_starred_post = has_starred_post -class JobPost(BaseMixin, db.Model): +class JobPost(BaseMixin, db.Model): __tablename__ = 'jobpost' # Metadata From 1cf4360d6707000df2cedbf5e1272ff4bdea2073 Mon Sep 17 00:00:00 2001 From: Bibhas Date: Wed, 1 Mar 2017 12:00:19 +0530 Subject: [PATCH 8/8] using db.func.utcnow() instead --- hasjob/models/jobpost.py | 4 ++-- hasjob/views/listing.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 35e85c7b7..e423ae1f7 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -279,11 +279,11 @@ def withdraw(self): def close(self): self.status = POSTSTATUS.CLOSED - self.closed_datetime = datetime.utcnow() + self.closed_datetime = db.func.utcnow() def delete(self): self.status = POSTSTATUS.DELETED - self.closed_datetime = datetime.utcnow() + self.closed_datetime = db.func.utcnow() def confirm(self): self.status = POSTSTATUS.CONFIRMED diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index 9f38ec84e..fd9acd9a8 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1053,11 +1053,10 @@ def close(domain, hashid, key): @app.route('/delete/', methods=('GET', 'POST'), defaults={'key': None}) def delete(hashid, key): post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id', 'status')).first_or_404() - if not post: - abort(404) if not post.admin_is(g.user): abort(403) if not post.is_draft(): + flash("Your job post must be withdrawn or closed.", "info") return redirect(post.url_for(), code=303) form = Form() if form.validate_on_submit():