diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-26 14:16:12 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-26 14:16:12 +0000 |
| commit | 6005baea467109e906d782021254c6c3134fcb18 (patch) | |
| tree | 7a0dfb986fcd997948ba5590331205f9c0dd79fd /app | |
| parent | Delete annotations when the admin deletes a task (diff) | |
| download | AnnotateChange-6005baea467109e906d782021254c6c3134fcb18.tar.gz AnnotateChange-6005baea467109e906d782021254c6c3134fcb18.zip | |
Add message flashing formatting
Diffstat (limited to 'app')
| -rw-r--r-- | app/admin/routes.py | 25 | ||||
| -rw-r--r-- | app/auth/routes.py | 11 | ||||
| -rw-r--r-- | app/main/routes.py | 7 | ||||
| -rw-r--r-- | app/static/base.css | 11 | ||||
| -rw-r--r-- | app/templates/base.html | 13 |
5 files changed, 45 insertions, 22 deletions
diff --git a/app/admin/routes.py b/app/admin/routes.py index fb3c6ad..8657c35 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -27,11 +27,11 @@ def manage(): if form.validate_on_submit(): user = User.query.filter_by(id=form.username.data).first() if user is None: - flash("User does not exist.") + flash("User does not exist.", "error") return redirect(url_for("admin.manage")) dataset = Dataset.query.filter_by(id=form.dataset.data).first() if dataset is None: - flash("Dataset does not exist.") + flash("Dataset does not exist.", "error") return redirect(url_for("admin.manage")) action = None @@ -40,7 +40,10 @@ def manage(): elif form.delete.data: action = "delete" else: - flash("Internal error: no button is true but form was submitted.") + flash( + "Internal error: no button is true but form was submitted.", + "error", + ) return redirect(url_for("admin.manage")) task = Task.query.filter_by( @@ -48,16 +51,16 @@ def manage(): ).first() if task is None: if action == "delete": - flash("Can't delete a task that doesn't exist.") + flash("Can't delete a task that doesn't exist.", "error") return redirect(url_for("admin.manage")) else: task = Task(annotator_id=user.id, dataset_id=dataset.id) db.session.add(task) db.session.commit() - flash("Task registered successfully.") + flash("Task registered successfully.", "success") else: if action == "assign": - flash("Task assignment already exists.") + flash("Task assignment already exists.", "error") return redirect(url_for("admin.manage")) else: # delete annotations too @@ -65,7 +68,7 @@ def manage(): db.session.delete(ann) db.session.delete(task) db.session.commit() - flash("Task deleted successfully.") + flash("Task deleted successfully.", "success") tasks = Task.query.all() return render_template( @@ -88,22 +91,22 @@ def add_dataset(): tmp_dir, secure_filename(form.file_.data.filename) ) if not os.path.exists(temp_filename): - flash("Internal error: temporary dataset disappeared.") + flash("Internal error: temporary dataset disappeared.", "error") return redirect(url_for("admin.add_dataset")) name = get_name_from_dataset(temp_filename) target_filename = os.path.join(dataset_dir, name + ".json") if os.path.exists(target_filename): - flash("Internal error: file already exists!") + flash("Internal error: file already exists!", "error") return redirect(url_for("admin.add_dataset")) os.rename(temp_filename, target_filename) if not os.path.exists(target_filename): - flash("Internal error: file moving failed") + flash("Internal error: file moving failed", "error") return redirect(url_for("admin.add_dataset")) dataset = Dataset(name=name, md5sum=md5sum(target_filename)) db.session.add(dataset) db.session.commit() - flash("Dataset %r added successfully." % name) + flash("Dataset %r added successfully." % name, "success") return redirect(url_for("admin.add_dataset")) return render_template("admin/add.html", title="Add Dataset", form=form) diff --git a/app/auth/routes.py b/app/auth/routes.py index 88ff7a0..7f7229e 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -30,7 +30,7 @@ def login(): if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): - flash("Invalid username or password", category="error") + flash("Invalid username or password", "error") return redirect(url_for("auth.login")) login_user(user, remember=form.remember_me.data) next_page = request.args.get("next") @@ -56,7 +56,7 @@ def register(): user.set_password(form.password.data) db.session.add(user) db.session.commit() - flash("Thank you, you are now a registered user!") + flash("Thank you, you are now a registered user!", "info") return redirect(url_for("auth.login")) return render_template("auth/register.html", title="Register", form=form) @@ -70,7 +70,10 @@ def reset_password_request(): user = User.query.filter_by(email=form.email.data).first() if user: send_password_reset_email(user) - flash("Check your email for the instructions to reset your password.") + flash( + "Please check your email for the instructions to reset your password.", + "info", + ) return redirect(url_for("auth.login")) return render_template( "auth/reset_password_request.html", title="Reset Password", form=form @@ -88,6 +91,6 @@ def reset_password(token): if form.validate_on_submit(): user.set_password(form.password.data) db.session.commit() - flash("Your password has been reset.") + flash("Your password has been reset.", "info") return redirect(url_for("auth.login")) return render_template("auth/reset_password.html", form=form) diff --git a/app/main/routes.py b/app/main/routes.py index f1f7a15..5879b28 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -52,7 +52,7 @@ def task(task_id): # get the json from the client annotation = request.get_json() if annotation["task"] != task_id: - flash("Internal error: task id doesn't match.") + flash("Internal error: task id doesn't match.", "error") return redirect(url_for(task_id=task_id)) task = Task.query.filter_by(id=task_id).first() @@ -80,12 +80,13 @@ def task(task_id): task.annotated_on = now db.session.commit() - flash("Your annotation has been recorded, thank you!") + flash("Your annotation has been recorded, thank you!", "success") return url_for("main.index") task = Task.query.filter_by(id=task_id).first() if task is None: - flash("No task with id %r has been assigned to you." % task_id) + flash("No task with id %r has been assigned to you." % task_id, + "error") return redirect(url_for("main.index")) data = load_data_for_chart(task.dataset.name) return render_template( diff --git a/app/static/base.css b/app/static/base.css new file mode 100644 index 0000000..ab908c8 --- /dev/null +++ b/app/static/base.css @@ -0,0 +1,11 @@ +.flashes .info { + color: blue; +} + +.flashes .success { + color: green; +} + +.flashes .error { + color: red; +} diff --git a/app/templates/base.html b/app/templates/base.html index 98eddf2..9812c5f 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,5 +1,10 @@ {% extends 'bootstrap/base.html' %} +{% block styles %} +{{ super() }} +<link rel="stylesheet" href="{{ url_for('static', filename='base.css') }}"> +{% endblock %} + {% block title %} {% if title %}{{ title }} -- AnnotateChange{% else %}Welcome to AnnotateChange{% endif %} {% endblock %} @@ -38,11 +43,11 @@ {% block content %} <div class="container"> - {% with messages = get_flashed_messages() %} + {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} - <ul> - {% for message in messages %} - <li>{{ message}}</li> + <ul class="flashes"> + {% for category, message in messages %} + <li class="{{ category }}">{{ message}}</li> {% endfor %} </ul> {% endif %} |
