Skip to content

Instantly share code, notes, and snippets.

@vladimirmyshkovski
Created March 12, 2017 02:35
Show Gist options
  • Save vladimirmyshkovski/c558cbdab8b98af2c2720c66501d56ba to your computer and use it in GitHub Desktop.
Save vladimirmyshkovski/c558cbdab8b98af2c2720c66501d56ba to your computer and use it in GitHub Desktop.
Flask flash with categories
.flash-message {
border: 0;
color: #ffffff;
margin-bottom: 0;
position: fixed;
width: 100%;
top: 0;
left: 0;
z-index: 100000;
border-radius: 0;
text-align: center;
display: none;
padding: 0;
height: 50px;
line-height: 50px;
}
.error {
background-color: #e51c23;
}
.success {
background-color: #4caf50;
}
.warning {
background-color: #ff9800;
}
.info {
background-color: #9c27b0;
}
(function () {
"use strict";
// Flash message
setTimeout(showFlash, 200);
setTimeout(hideFlash, 2000);
/**
* Show flash message.
*/
function showFlash() {
$('.flash-message').slideDown('fast');
}
/**
* Hide flash message.
*/
function hideFlash() {
$('.flash-message').slideUp('fast');
}
})();
@classmethod
def create(cls,**kwargs):
c = cls(**kwargs)
db.session.add(c)
try:
db.session.commit()
flash(u'Враг народа успешно создан!', 'success')
except IntegrityError:
db.session.rollback()
flash(u'Не удалось создать врага народа!' + u' IntegrityError', 'error')
except InterfaceError:
db.session.rollback()
flash(u'Не удалось создать врага народа!' + u' InterfaceError', 'error')
return c
@vladimirmyshkovski
Copy link
Author

This is an example of using a dynamic Flask Flash with categories, together with the classmethod for SQLAlchemy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment