1
1
Fork 0

Stylizing messages

dev
Jan Kužílek 5 years ago
parent ff09a96fed
commit 5435bcc5ee

@ -17,13 +17,13 @@ def login():
if request.method == 'POST' and form.validate(): if request.method == 'POST' and form.validate():
user = User.query.filter_by(username=form.username.data).first() user = User.query.filter_by(username=form.username.data).first()
if user is None or not user.check_password(form.password.data): 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')) return redirect(url_for('.login'))
user.login(remember=form.remember_me.data) user.login(remember=form.remember_me.data)
db.session.commit() db.session.commit()
flash('Logged in as {}'.format(user.username)) flash(f'Logged in as {user.username}.')
return redirect(nextpage()) return redirect(nextpage())

@ -84,10 +84,10 @@ def modify_user():
if form.delete.data: if form.delete.data:
if el.is_current: 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')) return redirect(url_for('.manage_users'))
elif el.is_admin: 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')) return redirect(url_for('.manage_users'))
db.session.delete(el) db.session.delete(el)
@ -149,7 +149,7 @@ def modify_post():
el.approver = current_user el.approver = current_user
db.session.commit() db.session.commit()
flash('Approved post {}'.format(str(el))) flash('Approved post {}.'.format(str(el)))
# redirect(url_for('post.post_show', id=el.id)) # redirect(url_for('post.post_show', id=el.id))
flasherrors(form) flasherrors(form)

@ -103,7 +103,7 @@ def comment():
db.session.add(el) db.session.add(el)
db.session.commit() 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)) return redirect(url_for('post.post_show', id=form.post_id.data))
else: else:
el = Comment.query.filter_by(id=form.id.data).first() el = Comment.query.filter_by(id=form.id.data).first()
@ -142,7 +142,7 @@ def upload():
db.session.add(post) db.session.add(post)
db.session.commit() db.session.commit()
flash('Successfully submitted {}'.format(str(post))) flash('Successfully submitted {}.'.format(str(post)))
return redirect(url_for('.posts')) return redirect(url_for('.posts'))

@ -46,7 +46,7 @@ def change_pass():
form = ChangePassForm(request.form) form = ChangePassForm(request.form)
if form.validate(): if form.validate():
if not current_user.check_password(form.password_current.data): if not current_user.check_password(form.password_current.data):
flash('Incorrect password') flash('Incorrect password.', category='error')
return redirect(url_for('.settings')) return redirect(url_for('.settings'))
current_user.create_password(form.password.data) current_user.create_password(form.password.data)

@ -56,7 +56,7 @@ from PIL import Image
def validate_file(form, field): def validate_file(form, field):
file = request.files.get(field.name) file = request.files.get(field.name)
if not file or file.filename == '': if not file or file.filename == '':
raise ValidationError('Please select a file') raise ValidationError('Please select a file.')
class UploadForm(CSRFForm): class UploadForm(CSRFForm):
post_img = FileField('Image', validators=[validate_file], render_kw={'required':''}) post_img = FileField('Image', validators=[validate_file], render_kw={'required':''})
@ -79,7 +79,7 @@ class UploadForm(CSRFForm):
# flash(real_mimetype) # flash(real_mimetype)
# if client_mimetype != real_mimetype or client_mimetype not in ['image/png','image/jpeg']: # if client_mimetype != real_mimetype or client_mimetype not in ['image/png','image/jpeg']:
if real_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: try:
Image.open(file).verify() Image.open(file).verify()
@ -94,7 +94,7 @@ class UploadForm(CSRFForm):
width, height = fileinfo['resolution'] width, height = fileinfo['resolution']
if width*height<1280*720 or width<720 or height<720: 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 # Change user section
class ChangeUserInfoForm(CSRFForm): class ChangeUserInfoForm(CSRFForm):

@ -56,4 +56,4 @@ def flasherrors(form):
for key,errs in form.errors.items(): for key,errs in form.errors.items():
label = form.__getattribute__(key).label.text label = form.__getattribute__(key).label.text
for err in errs: for err in errs:
flash('{}: {}'.format(label,err), category='error') flash(f'{label}: {err}', category='error')
Loading…
Cancel
Save