From 5435bcc5eec33c352513af2c94ca22335b143bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C5=BE=C3=ADlek?= Date: Wed, 18 Mar 2020 03:03:43 +0100 Subject: [PATCH] Stylizing messages --- yadc/bp/auth.py | 4 ++-- yadc/bp/manage.py | 6 +++--- yadc/bp/post.py | 4 ++-- yadc/bp/user.py | 2 +- yadc/forms.py | 6 +++--- yadc/utils.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/yadc/bp/auth.py b/yadc/bp/auth.py index c1f202d..3376eab 100644 --- a/yadc/bp/auth.py +++ b/yadc/bp/auth.py @@ -17,13 +17,13 @@ def login(): if request.method == 'POST' and form.validate(): 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.') + flash('Invalid username or password.', category='error') return redirect(url_for('.login')) user.login(remember=form.remember_me.data) db.session.commit() - flash('Logged in as {}'.format(user.username)) + flash(f'Logged in as {user.username}.') return redirect(nextpage()) diff --git a/yadc/bp/manage.py b/yadc/bp/manage.py index 6e9a7d9..05e2380 100644 --- a/yadc/bp/manage.py +++ b/yadc/bp/manage.py @@ -84,10 +84,10 @@ def modify_user(): if form.delete.data: if el.is_current: - flash("You can't just delete yourself.") + flash("Your account can be deleted from profile settings page.", category='error') return redirect(url_for('.manage_users')) elif el.is_admin: - flash("You can't just delete admins.") + flash("You can't delete admins.", category='error') return redirect(url_for('.manage_users')) db.session.delete(el) @@ -149,7 +149,7 @@ def modify_post(): el.approver = current_user db.session.commit() - flash('Approved post {}'.format(str(el))) + flash('Approved post {}.'.format(str(el))) # redirect(url_for('post.post_show', id=el.id)) flasherrors(form) diff --git a/yadc/bp/post.py b/yadc/bp/post.py index 9ce8994..6e0ddd9 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -103,7 +103,7 @@ def comment(): db.session.add(el) db.session.commit() - flash('Successfully submitted {}'.format(str(el))) + flash('Successfully submitted {}.'.format(str(el))) return redirect(url_for('post.post_show', id=form.post_id.data)) else: el = Comment.query.filter_by(id=form.id.data).first() @@ -142,7 +142,7 @@ def upload(): db.session.add(post) db.session.commit() - flash('Successfully submitted {}'.format(str(post))) + flash('Successfully submitted {}.'.format(str(post))) return redirect(url_for('.posts')) diff --git a/yadc/bp/user.py b/yadc/bp/user.py index f137223..a1f8cd7 100644 --- a/yadc/bp/user.py +++ b/yadc/bp/user.py @@ -46,7 +46,7 @@ def change_pass(): form = ChangePassForm(request.form) if form.validate(): if not current_user.check_password(form.password_current.data): - flash('Incorrect password') + flash('Incorrect password.', category='error') return redirect(url_for('.settings')) current_user.create_password(form.password.data) diff --git a/yadc/forms.py b/yadc/forms.py index 2b43c07..3327f55 100644 --- a/yadc/forms.py +++ b/yadc/forms.py @@ -56,7 +56,7 @@ from PIL import Image def validate_file(form, field): file = request.files.get(field.name) if not file or file.filename == '': - raise ValidationError('Please select a file') + raise ValidationError('Please select a file.') class UploadForm(CSRFForm): post_img = FileField('Image', validators=[validate_file], render_kw={'required':''}) @@ -79,7 +79,7 @@ class UploadForm(CSRFForm): # flash(real_mimetype) # if client_mimetype != real_mimetype or client_mimetype not in ['image/png','image/jpeg']: if real_mimetype not in ['image/png','image/jpeg']: - raise ValidationError('Please select an image file of PNG or JPEG format') + raise ValidationError('Please select an image file of PNG or JPEG format.') try: Image.open(file).verify() @@ -94,7 +94,7 @@ class UploadForm(CSRFForm): width, height = fileinfo['resolution'] if width*height<1280*720 or width<720 or height<720: - raise ValidationError('Image has too low resolution, according to rules.') + raise ValidationError('Image has too low resolution.') # Change user section class ChangeUserInfoForm(CSRFForm): diff --git a/yadc/utils.py b/yadc/utils.py index 2bed73a..682209c 100644 --- a/yadc/utils.py +++ b/yadc/utils.py @@ -56,4 +56,4 @@ def flasherrors(form): for key,errs in form.errors.items(): label = form.__getattribute__(key).label.text for err in errs: - flash('{}: {}'.format(label,err), category='error') \ No newline at end of file + flash(f'{label}: {err}', category='error') \ No newline at end of file