diff --git a/app/auth/views.py b/app/auth/views.py index 69d3570f..3e453ecd 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -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/', 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')) diff --git a/app/models.py b/app/models.py index 59f2bcd3..a59a6a95 100644 --- a/app/models.py +++ b/app/models.py @@ -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): """ diff --git a/app/templates/main/jobs/job.html.j2 b/app/templates/main/jobs/job.html.j2 index 2c582a75..63110075 100644 --- a/app/templates/main/jobs/job.html.j2 +++ b/app/templates/main/jobs/job.html.j2 @@ -99,11 +99,27 @@
+

Status:

+

Actions:

+ + deleteDelete Job + +
+