diff --git a/hasjob/models/jobpost.py b/hasjob/models/jobpost.py index 93c26457f..6421e6261 100644 --- a/hasjob/models/jobpost.py +++ b/hasjob/models/jobpost.py @@ -279,6 +279,11 @@ def withdraw(self): def close(self): self.status = POSTSTATUS.CLOSED + self.closed_datetime = db.func.utcnow() + + def delete(self): + self.status = POSTSTATUS.DELETED + self.closed_datetime = db.func.utcnow() def confirm(self): self.status = POSTSTATUS.CONFIRMED diff --git a/hasjob/templates/delete.html b/hasjob/templates/delete.html new file mode 100644 index 000000000..dcecc103b --- /dev/null +++ b/hasjob/templates/delete.html @@ -0,0 +1,19 @@ +{% extends "sheet.html" %} +{% from "baseframe/forms.html" import renderfield %} +{% block title %}{{ post.headline|e }}{% endblock %} +{% block content %} +
+
+

Delete this draft?

+

{{ post.headline }}

+

+ Deleted drafts will be gone forever, with no undo. Are you sure you want to delete? +

+
+ {{ form.hidden_tag() }} + + Cancel +
+
+
+{% endblock %} diff --git a/hasjob/templates/detail.html.jinja2 b/hasjob/templates/detail.html.jinja2 index 3866cfcda..4067b01d7 100644 --- a/hasjob/templates/detail.html.jinja2 +++ b/hasjob/templates/detail.html.jinja2 @@ -161,6 +161,10 @@    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 7688b4030..b97bebc61 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -1041,7 +1041,6 @@ def close(domain, hashid, key): form = Form() if form.validate_on_submit(): post.close() - post.closed_datetime = datetime.utcnow() db.session.commit() # cache bust # dogpile.invalidate_region('hasjob_index') @@ -1049,6 +1048,23 @@ def close(domain, hashid, key): return render_template("close.html.jinja2", 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(hashid, key): + post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id', 'status')).first_or_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(): + post.delete() + db.session.commit() + return redirect(url_for('my_posts'), 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):