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
3 changes: 2 additions & 1 deletion hasjob/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 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 = datetime.utcnow()

def delete(self):
self.status = POSTSTATUS.DELETED
self.closed_datetime = datetime.utcnow()
Copy link
Member

Choose a reason for hiding this comment

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

Use db.func.utcnow() in both cases.


def confirm(self):
self.status = POSTSTATUS.CONFIRMED
Expand Down Expand Up @@ -308,6 +313,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':
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
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ <h2>What’s wrong with it?</h2>
<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
19 changes: 18 additions & 1 deletion hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,29 @@ 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.

return redirect(post.url_for(), code=303)
return render_template("close.html", 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:
abort(404)
Copy link
Member

Choose a reason for hiding this comment

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

This is unnecessary because first_or_404() will do it for you.

if not post.admin_is(g.user):
abort(403)
if not post.is_draft():
return redirect(post.url_for(), code=303)
Copy link
Member

Choose a reason for hiding this comment

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

Flash a message that this post must be withdrawn or closed.

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