Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - deletion of draft #354

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions hasjob/models/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions hasjob/templates/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "sheet.html" %}
{% from "baseframe/forms.html" import renderfield %}
{% block title %}{{ post.headline|e }}{% endblock %}
{% block content %}
<div class="sheet">
<div class="section first">
<h1>Delete this draft?</h1>
<h2>{{ post.headline }}</h2>
<p>
Deleted drafts will be gone forever, with no undo. Are you sure you want to delete?
</p>
<form method="POST" class="form-horizontal">
{{ form.hidden_tag() }}
<button type="submit" class="btn btn-danger">Delete</button>
<a class="btn btn-default" href="{{ post.url_for() }}">Cancel</a>
</form>
</div>
</div>
{% endblock %}
4 changes: 4 additions & 0 deletions hasjob/templates/detail.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
<a class="list-group-item" href="{{ post.url_for('withdraw') }}">
<i class="fa fa-fw fa-trash-o"></i>&nbsp;&nbsp; Withdraw this
</a>
{%- elif post.is_draft() %}
<a class="list-group-item" href="{{ post.url_for('delete') }}">
<i class="fa fa-fw fa-trash-o"></i>&nbsp;&nbsp; Delete this draft
</a>
{%- endif %}
{%- if post.is_old() %}
<a class="list-group-item" href="{{ url_for('newjob', template=post.hashid) }}">
Expand Down
18 changes: 17 additions & 1 deletion hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,14 +1041,30 @@ def close(domain, hashid, key):
form = Form()
if form.validate_on_submit():
post.close()
post.closed_datetime = datetime.utcnow()
db.session.commit()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed that this datetime can be set inside close() so moved there.

# cache bust
# dogpile.invalidate_region('hasjob_index')
return redirect(post.url_for(), code=303)
return render_template("close.html.jinja2", post=post, form=form)


@app.route('/delete/<hashid>', methods=('GET', 'POST'), defaults={'key': None}, subdomain='<subdomain>')
@app.route('/delete/<hashid>', 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('/<domain>/<hashid>/reopen', methods=('GET', 'POST'), defaults={'key': None}, subdomain='<subdomain>')
@app.route('/<domain>/<hashid>/reopen', methods=('GET', 'POST'), defaults={'key': None})
def reopen(domain, hashid, key):
Expand Down