Created
March 12, 2017 02:35
-
-
Save vladimirmyshkovski/c558cbdab8b98af2c2720c66501d56ba to your computer and use it in GitHub Desktop.
Flask flash with categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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'); | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an example of using a dynamic Flask Flash with categories, together with the classmethod for SQLAlchemy