Add first stopping and deletion functions etc.

This commit is contained in:
Stephan Porada 2019-09-11 14:51:59 +02:00
parent 230d057fee
commit c7337a5277
3 changed files with 46 additions and 5 deletions

View File

@ -4,7 +4,7 @@ from . import auth
from .. import db
from .forms import ChangePasswordForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm, EditProfileForm
from ..email import send_email
from ..models import User
from ..models import User, Job
@auth.route('/login', methods=['GET', 'POST'])
@ -162,11 +162,11 @@ def edit_profile():
)
@auth.route('/edit_profile/delete_self/<int:user_id>', methods=['GET', 'POST'])
@auth.route('/edit_profile/delete_self', methods=['GET', 'POST'])
@login_required
def delete_self(user_id):
selected_user = User.query.filter_by(id=user_id).first()
db.session.delete(selected_user)
def delete_self():
user = current_user
db.session.delete(user)
db.session.commit()
flash('Your account has been deleted!')
return redirect(url_for('main.index'))

View File

@ -216,6 +216,15 @@ class User(UserMixin, db.Model):
jobs[str(job.id)] = job.to_dict()
return jobs
def delete_user(self, user_id):
"""
Delete user from database. Also delete all associated jobs and corpora
files.
"""
user = User.query.filter_by(user_id=user_id)
db.session.delete(user)
db.session.commit()
class AnonymousUser(AnonymousUserMixin):
"""
@ -276,6 +285,22 @@ class Job(db.Model):
'title': self.title,
'user_id': self.user_id}
def flag_for_stop(self):
"""
Flag running or failed job (anything that is not completed) with
stopping. Opaque daemon will end services flaged with 'stopping'.
"""
self.status = 'stopping'
db.session.commit()
def delete_job(self, job_id):
"""
Delete job with given job id from database. Also delete associated job
files
"""
# TODO
pass
class Corpus(db.Model):
"""

View File

@ -99,10 +99,26 @@
</script>
<div class="col s12 m4">
<h2>Status:</h2>
<h3 id="title"></h3>
<p id="description"></p>
<a class="waves-effect waves-light btn" id="status"></a>
<h2>Actions:</h2>
<!-- Confirm deletion of selected user with modal dialogue
Modal Trigger-->
<a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Job</a>
<!-- Modal Strucutre -->
<div id="modal-confirm-delete" class="modal">
<div class="modal-content">
<h4>Confirm deletion</h4>
<p>Do you really want to delete the job {{job.title}}?</p>
</div>
<div class="modal-footer">
<a href="{{ url_for('main.delete_job', job_id=job.id) }}" class="modal-close waves-effect waves-green btn red"><i class="material-icons left">delete</i>Delete Job</a></a>
</div>
</div>
</div>
<div class="col s12 m8">
<div class="card">